feat: Add optimization execution and live results overlay to canvas
Phase 2 - Execution Bridge: - Update /start endpoint to fallback to generic runner when no study script exists - Auto-detect model files (.prt, .sim) from 1_setup/model/ directory - Pass atomizer_spec.json path to generic runner Phase 3 - Live Monitoring & Results Overlay: - Add ResultBadge component for displaying values on canvas nodes - Extend schema with resultValue and isFeasible fields - Update DesignVarNode, ObjectiveNode, ConstraintNode, ExtractorNode to show results - Add Run/Stop buttons and Results toggle to SpecRenderer - Poll /status endpoint every 3s and map best_trial values to nodes - Show green/red badges for constraint feasibility
This commit is contained in:
@@ -2114,17 +2114,51 @@ async def start_optimization(study_id: str, request: StartOptimizationRequest =
|
||||
run_script = study_dir / "run_sat_optimization.py"
|
||||
if not run_script.exists():
|
||||
run_script = study_dir / "run_optimization.py"
|
||||
|
||||
# Fallback to generic runner if no study script found but spec exists
|
||||
is_generic_runner = False
|
||||
if not run_script.exists() and (study_dir / "atomizer_spec.json").exists():
|
||||
generic_runner = (
|
||||
Path(__file__).parent.parent.parent.parent.parent
|
||||
/ "optimization_engine"
|
||||
/ "run_optimization.py"
|
||||
)
|
||||
if generic_runner.exists():
|
||||
run_script = generic_runner
|
||||
is_generic_runner = True
|
||||
|
||||
if not run_script.exists():
|
||||
raise HTTPException(
|
||||
status_code=404, detail=f"No optimization script found for study {study_id}"
|
||||
)
|
||||
|
||||
# Detect script type and build appropriate command
|
||||
script_type = _detect_script_type(run_script)
|
||||
script_type = (
|
||||
_detect_script_type(run_script) if not is_generic_runner else "generic_universal"
|
||||
)
|
||||
python_exe = sys.executable
|
||||
cmd = [python_exe, str(run_script)]
|
||||
|
||||
if request:
|
||||
if is_generic_runner:
|
||||
# Configure generic runner arguments
|
||||
cmd.extend(["--config", str(study_dir / "atomizer_spec.json")])
|
||||
|
||||
# Auto-detect PRT and SIM files
|
||||
model_dir = study_dir / "1_setup" / "model"
|
||||
if not model_dir.exists():
|
||||
model_dir = study_dir / "model"
|
||||
|
||||
prt_files = list(model_dir.glob("*.prt"))
|
||||
sim_files = list(model_dir.glob("*.sim"))
|
||||
|
||||
if prt_files:
|
||||
cmd.extend(["--prt", str(prt_files[0])])
|
||||
if sim_files:
|
||||
cmd.extend(["--sim", str(sim_files[0])])
|
||||
|
||||
if request and request.trials:
|
||||
cmd.extend(["--trials", str(request.trials)])
|
||||
elif request:
|
||||
if script_type == "sat":
|
||||
# SAT scripts use --trials
|
||||
cmd.extend(["--trials", str(request.trials)])
|
||||
|
||||
Reference in New Issue
Block a user