You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix#1059: add pred extract for lifting external target-space solutions (#1060)
* Add `pred extract` for lifting external target-space solutions to source
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>
* Address codex review on #1060: bundle validation, empty-config, schema 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>
* Factor bundle replay into BundleReplay helper; unify solve/extract/MCP
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>
* Address codex xhigh review: target.data coherence, tighter tests, pub(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>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments