Add Python-first Model IR and Rust codegen prototype with docs and tests#33
Add Python-first Model IR and Rust codegen prototype with docs and tests#33blackopsrepl wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 739bb7c807
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| lines.extend(_emit_entities(model.entities)) | ||
| lines.extend(_emit_solution(model)) | ||
|
|
||
| lines.append(f"use {model.solution.name}ConstraintStreams;") |
There was a problem hiding this comment.
Move ConstraintStreams import out of module scope
generate_rust_module emits use <Solution>ConstraintStreams; at the top level, but #[planning_solution] generates that trait in the same module. In Rust this becomes a re-import of an already-defined item (E0255), so generated crates fail to compile before constraint code runs. Put this use inside define_constraints() (as done in existing examples) or remove it entirely.
Useful? React with 👍 / 👎.
|
|
||
| def _emit_constraint_builder(model: ModelDef, constraint: ConstraintDef, c_name: str, score_ty: str) -> list[str]: | ||
| solution_name = model.solution.name | ||
| source_entity_name = model.solution.entity_collections[constraint.source.collection_field] |
There was a problem hiding this comment.
Accept fact collections as constraint sources in codegen
_emit_constraint_builder assumes every constraint.source.collection_field is an entity collection by indexing model.solution.entity_collections[...]. However, validate_model explicitly allows source collections from both entity and fact collections, so valid models with fact-based sources crash with KeyError during generation. Resolve the source type from both collection maps (like the join right-side lookup) before emitting stream types.
Useful? React with 👍 / 👎.
|
|
||
| def _impact_method(impact: ImpactSpec) -> str: | ||
| prefix = "penalize" if impact.impact == "penalize" else "reward" | ||
| return f"{prefix}_{impact.level}" |
There was a problem hiding this comment.
Guard medium impacts from unsupported builder methods
_impact_method blindly concatenates impact.level, which can emit penalize_medium/reward_medium for ImpactSpec(level="medium"). The stream API in this repo does not define medium-level builder methods, so these generated calls do not compile when users choose that IR value. Add validation/mapping so only supported method names are emitted for the selected score API.
Useful? React with 👍 / 👎.
739bb7c to
4386f63
Compare
|
Closing this PR because the Python implementation has moved to a standalone repository and is no longer intended for inclusion in the SolverForge Rust workspace. |
Motivation
solverforge-pyexperiment and set guardrails for Path 2 (IR -> codegen -> compile).Description
python/solverforge_irpackage implementing a typed IR (model.py), lambda lowering (lambda_to_expr), validation (validate_model), and a Rust code generator (codegen.py) that emitslib.rsandCargo.tomland returnsGeneratedRustProjectmetadata.contains,len,overlaps), and map Python type hints likeOption[...]/Vec[...]to Rust types via_map_type.python/testsexercising IR lowering, model validation, and Rust code generation (test_model_ir.py,test_codegen.py).docs/python-model-ir.mdanddocs/python-path2-postmortem.md, and register the new doc pages inREADME.md.Testing
python/tests/test_model_ir.pywhich exerciselambda_to_exprandvalidate_model, and they passed.python/tests/test_codegen.pywhich validate generated Rust module snippets and project writing, and they passed.write_rust_projectwrites files and tests assert their existence.Codex Task