Skip to content

Add Recursive Self Aggregation (RSA) algorithm - #190

Closed
shashankk42 wants to merge 24 commits into
FLASK-LLNL:mainfrom
shashankk42:feature/parallel-rsa
Closed

Add Recursive Self Aggregation (RSA) algorithm#190
shashankk42 wants to merge 24 commits into
FLASK-LLNL:mainfrom
shashankk42:feature/parallel-rsa

Conversation

@shashankk42

@shashankk42 shashankk42 commented Apr 3, 2026

Copy link
Copy Markdown

Summary

Implement parallel Recursive Self-Aggregation (RSA) algorithm for retrosynthesis with AI-based/template-based routing and UI controls

File-by-file changes:

  1. charge_backend/backend_helper_funcs.py - Added documentation comment for use_ai_based field inheritance from RunSettings
  2. charge_backend/backend_manager.py - Updated retrosynthesis routing to check use_ai_based flag instead of overloading use_rsa for AI vs template selection
  3. charge_backend/charge_server.py - Added dynamic WebSocket URL detection with HTTPS support
  4. charge_backend/retrosynthesis/ai.py - Implemented RSA orchestration logic with parallel proposal generation and aggregation stages
  5. charge_backend/retrosynthesis/retrosynthesis_task.py - Added RSAAggregationTask dataclass for RSA retrosynthesis workflow configuration
  6. charge_backend/retrosynthesis/template.py - Made template-based retrosynthesis optional when AiZynthFinder config file is missing
  7. charge_backend/rsa_algorithm.py - Extracted generic RSA algorithm loop into task-agnostic reusable helper function
  8. flask-app/src/App.tsx - Added UI checkboxes and state management for RSA mode selection and AI-based approach toggle
  9. flask-app/src/types.ts - Added useAiBased, useRsa, rsaMode, rsaN, rsaK, rsaT fields to FlaskRunSettings interface
  10. Added prompt .txt files

Related PRs

This PR depends on:

All three PRs must be merged together for RSA functionality to work.

Shashank Kushwaha added 24 commits April 1, 2026 21:59
- Add RSA parameters (useRsa, rsaMode, rsaN, rsaK, rsaT) to sendMessageToServer
- Add RSA parameters to handleComputeFlaskAI for compute-reaction-from action
- Include RSA settings in dependency arrays for React hooks
- Ensures RSA mode is sent when clicking 'How do I make this?' on nodes
- Route to AI-based retrosynthesis when RSA enabled or config file missing
- Create root node for AI-based path (matching template-based behavior)
- Support both standard one-shot and RSA modes from initial compute action
- Maintain backward compatibility with template-based when config exists
- Fix import for smiles_to_html from correct module (molecule_naming)
- Add os import at module level in both ai.py and template.py
- Check if config file exists before attempting template expansion
- Gracefully skip template search with info message when config unavailable
- Prevent FileNotFoundError when /data/config.yml doesn't exist
- Allow AI-based retrosynthesis to complete without template dependency
- Production-ready: works with or without AiZynthFinder config
- Auto-detect WebSocket URL from request host header and protocol
- Use wss:// for HTTPS requests, ws:// for HTTP requests
- Support VS Code port forwarding (e.g., localhost:8003 -> ws://localhost:8003/ws)
- Remove hardcoded localhost:8001 default
- Maintain backward compatibility with WS_SERVER environment variable
- Production-ready: works for local dev, port forwarding, and HTTPS hosting
…osals, inject into all prompts - Update system prompt to prevent redundant database queries
Bug: Proposals were using user_prompt instead of user_prompt_with_rag
Result: Database queried N times instead of 1 (once per proposal)
Fix: Use user_prompt_with_rag for proposal tasks (safe for standalone/RAG/non-RSA)
RAG mode: Query once, inject results, then remove tool (1 query total)
Standalone mode: Remove tool entirely (0 queries)
Non-RSA: Unaffected (tool remains available)

Changes only within RSA block (lines 144-404)
Show summary of retrieved reactions in reasoning panel:
- First 5 reactions with names and components
- Reactants and products for each
- Confirmation that results are injected into prompts
Created rsa_algorithm.py with run_rsa_loop() and refactored retrosynthesis to use it.
- Implement parallel execution for Stage 1 proposals using asyncio.gather()
- Add runner_factory parameter to create independent runner instances
- Add validation to filter proposals/aggregations with empty reactants
- Default to parallel mode (parallel=True) with fallback to sequential
- Retrosynthesis now creates independent runners for parallel execution
Aggregations within each stage run in parallel. Barriers enforce sequential stage progression.
@shashankk42

Copy link
Copy Markdown
Author

Closing to create fresh PR with generic RSA implementation in ChARGe repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant