Fix #1059: add pred extract for lifting external target-space solutions#1060
Open
Fix #1059: add pred extract for lifting external target-space solutions#1060
pred extract for lifting external target-space solutions#1060Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
…(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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 throughpred solveand re-solving from scratch.This is direction (2) from #1059. Named
extractrather thanliftper @GiggleLiu's suggestion on the issue.Fixes #1059.
Usage
Output JSON includes source
problem/solution/evaluationplus anintermediateblock with the input target config and its evaluation. Also supports-for stdin.Changes
problemreductions-cli/src/commands/extract.rs— new commandproblemreductions-cli/src/commands/mod.rs,cli.rs,main.rs— wiring + help text + subcommand hintproblemreductions-cli/tests/cli_tests.rs— 3 integration tests (round-trip, rejects plain problem file, rejects wrong config length)Test plan
cargo build -p problemreductions-clicargo test -p problemreductions-cli --test cli_tests test_extract(3/3 pass)cargo clippy -p problemreductions-cli --all-targetscleanFollow-ups (not in this PR)
liftfield in the bundle JSON so pure-external consumers can invert the map without anypredbinary. Per the issue, leave as a longer-term enhancement.