Skip to content

[ISSUE-06] Implement planner, classifier, and combinatorial expansion#73

Merged
Gonza10V merged 3 commits into
full_buildfrom
codex/implement-full-build-planner-and-classifier
May 6, 2026
Merged

[ISSUE-06] Implement planner, classifier, and combinatorial expansion#73
Gonza10V merged 3 commits into
full_buildfrom
codex/implement-full-build-planner-and-classifier

Conversation

@Gonza10V
Copy link
Copy Markdown
Contributor

@Gonza10V Gonza10V commented May 6, 2026

Motivation

  • Provide a pure, deterministic full-build planner that classifies SBOL inputs into lvl-2 assembly, lvl-1 assembly, domestication, combinatorial expansions, and structured unsupported records without mutating inventory or executing stages.
  • Ensure level-1 designs are validated and ordered deterministically for v1 (exactly promoter, RBS, CDS, terminator) and surface non-fatal issues as structured BuildWarnings.
  • Support deterministic combinatorial expansion with configurable caps and opt-in large-expansion behavior so planners remain offline-testable and safe by default.
  • Keep planner logic focused on classification/expansion only and avoid route optimization, execution, or protocol generation in this PR.

Description

  • Added lightweight planning contracts and exports in src/buildcompiler/planning/models.py and updated src/buildcompiler/planning/__init__.py to expose BuildPlan, UnsupportedPlanningRecord, and FullBuildPlanner.
  • Implemented deterministic non-combinatorial classifier and stable request-id helper in src/buildcompiler/planning/classifier.py that maps ModuleDefinition -> ASSEMBLY_LVL2, multi-component ComponentDefinition -> ASSEMBLY_LVL1, single supported-role ComponentDefinition -> DOMESTICATION, and unsupported shapes to UnsupportedPlanningRecord.
  • Implemented level-1 validation and ordering helpers in src/buildcompiler/planning/validation.py to classify part roles, enforce exact cardinality (4 parts), respect SBOL order when unambiguous, and otherwise fall back to canonical order while emitting BuildWarnings.
  • Implemented deterministic combinatorial expansion in src/buildcompiler/planning/combinatorial.py that enumerates variant cartesian products (for the supported variable/variant shape used in tests), enforces BuildOptions().planning.combinatorial.max_variants with opt-in allow_large_expansion, skips invalid variants with warnings, and returns structured unsupported records if expansion is blocked or all variants are invalid.
  • Implemented the pure orchestrator FullBuildPlanner in src/buildcompiler/planning/full_build_planner.py which aggregates lvl2/lvl1/domestication requests, warnings, and unsupported records without touching inventory or executing stages.
  • Added unit tests covering classifier, validation/order rules, combinatorial expansion behaviors, and planner integration in tests/unit/planning/*.

Testing

  • Ran import smoke checks with python -c "from buildcompiler.planning import FullBuildPlanner", python -c "from buildcompiler.planning import BuildPlan", and python -c "from buildcompiler.api.options import BuildOptions; BuildOptions()", and they succeeded.
  • Ran targeted planning unit tests with pytest tests/unit/planning -q and they passed (6 passed).
  • Ran the broader unit suite with pytest tests/unit/planning tests/unit/domain tests/unit/api tests/unit/sbol tests/unit/inventory -q and it passed (28 passed).
  • Attempting the uv-backed test command uv run pytest tests/unit/planning failed due to an external optional dependency fetch error cloning SBOLInventory over the network (git fetch/proxy 403), but direct pytest runs succeeded locally; ruff check src/buildcompiler/planning tests/unit/planning and ruff format --check src/buildcompiler/planning tests/unit/planning completed successfully after formatting.

Implemented files/classes/functions added or updated: planning/models.py (BuildPlan, UnsupportedPlanningRecord), planning/classifier.py (request_id_for, classify_non_combinatorial), planning/validation.py (classify_part_role, validate_lvl1_cardinality, ordered_lvl1_parts), planning/combinatorial.py (expand_combinatorial_derivation), planning/full_build_planner.py (FullBuildPlanner), and planning/__init__.py exports.

Tests added/updated: tests/unit/planning/test_classifier.py (classification + IDs), tests/unit/planning/test_validation.py (lvl1 cardinality and ordering behavior), tests/unit/planning/test_combinatorial.py (expansion, blocking, invalid-variant handling), and tests/unit/planning/test_full_build_planner.py (mixed-input aggregation).

Assumptions and notes: combinatorial support in this PR implements a minimal deterministic expansion path for variableComponents[].variants shapes used by tests rather than the full pySBOL2 combinatorial API breadth, blocked large expansions are represented as a structured UnsupportedPlanningRecord plus a planning.combinatorial.expansion_blocked BuildWarning, and ambiguous SBOL order is detected when getInSequentialOrder() cannot produce a full unambiguous 4-role sequence so the planner falls back to canonical promoter/RBS/CDS/terminator order with a warning.

Blockers and follow-ups: route optimization/selector logic and the execution/full-build loop are intentionally out of scope and should be implemented in subsequent issues, and running the uv runner in CI may require allowing network access or pinning optional dependencies to avoid the SBOLInventory git fetch failure observed during one uv invocation.


Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3196051a9a

ℹ️ 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".

Comment on lines +46 to +47
if count > 1:
return BuildRequest(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Validate lvl1 designs before enqueueing them

Any ComponentDefinition with more than one subcomponent is immediately emitted as an ASSEMBLY_LVL1 request here, so invalid level-1 designs (e.g. 2 parts, missing CDS, duplicate promoter) are treated as buildable with no warnings. This bypasses the new validate_lvl1_cardinality/ordering logic entirely, which means malformed inputs can flow downstream and fail later in execution instead of being flagged during planning.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex good catch, lets check in planning that the design has 4 parts and those are promoter, RBS, CDS, terminator. If it does not contain those four then return a warning, we suggest to use those four for synthetic bacterial genes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Added a level-1 planning guard in the classifier so multi-component designs are only classified as ASSEMBLY_LVL1 when they match the expected 4-part structure (promoter, rbs, cds, terminator) when role evidence is available; otherwise they are returned as UnsupportedPlanningRecord with a warning-style message and structured metadata (component_count, observed_role_counts, suggested_parts). src/buildcompiler/planning/classifier.pyL47-L88
  • Added/updated classifier tests to:
  • Updated planner integration test fixtures so the lvl1 design input is a valid promoter/RBS/CDS/terminator 4-part construct, keeping expectations aligned with the new classifier behavior. tests/unit/planning/test_full_build_planner.pyL6-L31

Testing

  • pytest tests/unit/planning/test_classifier.py tests/unit/planning/test_full_build_planner.py -q

Also completed:

  • Committed changes: dc833e8
  • Created follow-up PR message via make_pr tool.

View task →



def _collect_variant_sets(derivation):
variables = sorted(list(derivation.variableComponents), key=lambda v: v.identity)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Derive combinatorial part order from template, not IDs

The expansion currently sorts variableComponents by their identity and then reuses that sequence as part_order. Because variable-component IDs are arbitrary in SBOL, this can reorder promoter/RBS/CDS/terminator positions and produce incorrect assembly constraints even when the role multiset check passes. Variant ordering should follow the template’s sequence order (or variable references), not lexical URI order.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex good catch, fix this issue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Fixed combinatorial expansion ordering so variable components are no longer ordered by arbitrary variable-component IDs; they’re now ordered by each variable component’s referenced variable (vc.variable), with identity as a deterministic tiebreaker. This ensures emitted constraints["part_order"] follows template-variable positions instead of lexical URI ordering artifacts. src/buildcompiler/planning/combinatorial.pyL11-L16
  • Added a regression test that constructs a combinatorial derivation with intentionally scrambled variable-component IDs and verifies the resulting part_order matches template-variable sequence, preventing the reported ordering bug from regressing. tests/unit/planning/test_combinatorial.pyL51-L84

Testing

  • pytest tests/unit/planning/test_combinatorial.py tests/unit/planning/test_full_build_planner.py -q
  • git commit -m "Fix combinatorial part ordering by variable reference"

View task →

@Gonza10V Gonza10V merged commit 7b87035 into full_build May 6, 2026
0 of 4 checks passed
@Gonza10V Gonza10V deleted the codex/implement-full-build-planner-and-classifier branch May 6, 2026 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant