Skip to content

Fix #1059: add pred extract for lifting external target-space solutions#1060

Open
isPANN wants to merge 4 commits intomainfrom
issue-1059-pred-extract
Open

Fix #1059: add pred extract for lifting external target-space solutions#1060
isPANN wants to merge 4 commits intomainfrom
issue-1059-pred-extract

Conversation

@isPANN
Copy link
Copy Markdown
Collaborator

@isPANN isPANN commented Apr 21, 2026

Summary

Adds pred extract <bundle> --config <target-config> so external solvers (QUBO samplers, neutral-atom platforms, QAOA runtimes, etc.) can map a target-space configuration back to the source problem space without shelling back through pred solve and re-solving from scratch.

This is direction (2) from #1059. Named extract rather than lift per @GiggleLiu's suggestion on the issue.

Fixes #1059.

Usage

pred create MIS --graph 0-1,1-2,2-3 -o mis.json
pred reduce mis.json --to QUBO -o bundle.json
# external solver reads bundle.target, produces a QUBO config [0,1,0,1]
pred extract bundle.json --config 0,1,0,1
# -> MIS solution [0,1,0,1], evaluation Max(2)

Output JSON includes source problem / solution / evaluation plus an intermediate block with the input target config and its evaluation. Also supports - for stdin.

Changes

  • problemreductions-cli/src/commands/extract.rs — new command
  • problemreductions-cli/src/commands/mod.rs, cli.rs, main.rs — wiring + help text + subcommand hint
  • problemreductions-cli/tests/cli_tests.rs — 3 integration tests (round-trip, rejects plain problem file, rejects wrong config length)

Test plan

  • cargo build -p problemreductions-cli
  • cargo test -p problemreductions-cli --test cli_tests test_extract (3/3 pass)
  • cargo clippy -p problemreductions-cli --all-targets clean
  • Manual end-to-end: MIS → QUBO → extract with optimal and suboptimal target configs, stdin input, error paths (plain problem file, wrong config length, out-of-range value)

Follow-ups (not in this PR)

  • Direction (1): a self-contained lift field in the bundle JSON so pure-external consumers can invert the map without any pred binary. Per the issue, leave as a longer-term enhancement.

isPANN and others added 3 commits April 22, 2026 02:35
Fixes #1059. External solvers (QUBO samplers, neutral-atom platforms, QAOA
runtimes, etc.) can now map a target-space configuration back to the source
problem space via `pred extract <bundle> --config <target-config>`, without
having to shell back through `pred solve` and re-solve from scratch.

Per issue #1059 discussion, this is direction (2) (subcommand) with the name
`extract` rather than `lift` (GiggleLiu's suggestion).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…a alignment

- Validate bundle self-consistency (path.len >= 2, endpoints match
  source/target) before calling reduce_along_path — turns previously
  panicking malformed bundles into normal CLI errors.
- Allow empty --config to represent a zero-variable target configuration.
- Align extract's JSON output schema with `pred solve` on a bundle:
  add `reduced_to`, add `solver: "external"`, rename intermediate.config
  to intermediate.solution — so downstream consumers don't need separate
  parsers for two nearly identical workflows.
- Add 3 new integration tests: out-of-range config value, malformed
  bundle path/source mismatch, stdin bundle input.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codex review item 4. Before: `solve_bundle` (CLI), `solve_bundle_inner`
(MCP), and `extract` each had their own copy of the "load bundle, validate,
reconstruct ReductionPath, call reduce_along_path" flow — three places to
drift out of sync, and only `extract` had the endpoint-vs-source/target
validation added in the previous commit.

Now `BundleReplay::prepare` is the single entry point: validates
bundle.path length and endpoint consistency with source/target, loads both
problems, rebuilds the path, and replays to a `ReductionChain`. Callers
just pick their own way to produce a target config (solver vs external
input) and call `replay.extract(target_config)`.

Benefit: the malformed-bundle check now protects `pred solve` and the MCP
bundle-solve tool too, not just `pred extract`.

Also: tests derive the target config from `pred solve --solver brute-force`
instead of hardcoding it, so they pass under both default and `--features
mcp` builds (which pick different reduction paths, MIS->...->ILP->QUBO vs
MIS->...->MaxSetPacking->QUBO).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.92%. Comparing base (b3b18f1) to head (223d23a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1060   +/-   ##
=======================================
  Coverage   97.92%   97.92%           
=======================================
  Files         966      966           
  Lines      100043   100043           
=======================================
+ Hits        97967    97968    +1     
+ Misses       2076     2075    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…(crate)

Addresses remaining items from codex xhigh review on #1060 that this PR
introduced (or whose scope this PR widened):

Must-fix (correctness hole introduced by claiming BundleReplay "validates"
bundles without fully doing so):
- `BundleReplay::prepare` now serializes the chain's replayed target and
  checks it byte-equals `bundle.target.data`. Previously a tampered bundle
  where `target.data` disagreed with what `reduce_along_path` actually
  produced would silently pass prepare(): callers solved/validated against
  the bundle's stated target but extracted through a different chain target.
  Now rejected with a "`target.data` does not match" error, consistently
  across `pred solve`, `pred extract`, and the MCP solve tool.

Tests:
- Tighten `test_extract_roundtrip_mis_to_qubo` to assert
  `intermediate.solution` echoes the input target config exactly, and
  that the source solution is a binary vector of the right length whose
  ones-count matches the declared source evaluation.
- New `test_extract_rejects_tampered_target_data` regression test covering
  the coherence check, asserting it fires on both `pred extract` and
  `pred solve` (verifying the shared gate).

Nit:
- Narrow `BundleReplay` field visibility from `pub` to `pub(crate)` —
  this helper is an internal CLI abstraction, not an external API.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

Reduction bundles don't expose lift metadata — external solvers can't recover source solution

1 participant