Issue #145 Implement BackendEstimatorV2 runtime support(with IBM Quantum Hardware test)#160
Conversation
|
I have added one missing function in |
Thank you very much for adding I also checked the remaining Windows CI failure. It looks unrelated to the estimator payload logic: the primitive job header included |
|
Thank you very much for the review. I pushed a follow-up fix 7693f92 for the Windows The fix is limited to Windows header macro hygiene and should not affect the estimator implementation or the |
doichanj
left a comment
There was a problem hiding this comment.
I think this PR looks good for me and well implemented.
Thank you for your contribution
Thank you for the review and kind words! I appreciate it. I’m glad the implementation looks good and address anything else if needed. |
Summary
This fix adds a native Backend Estimator V2 path to Qiskit C++ for issue #145. The core change is a typed estimator primitive implementation that can submit IBM Runtime V2 estimator jobs through QRMI using
program_id = "estimator", instead of modeling estimator behavior as a sampler-like result or a raw vector wrapper.The implementation introduces
primitives::BackendEstimatorV2as the user-facing entry point, along withBackendEstimatorJob,EstimatorPub,EstimatorPubResult, andEstimatorPrimitiveResult. It also extendsBackendV2with an estimator submission overload:run(std::vector<EstimatorPub>&, double). QRMI implements that overload by building a Runtime V2 estimator payload withversion = 2,support_qiskit = false, anoptionsobject, and apubsarray whose entries carry the OpenQASM 3 circuit, observables, parameter values, and resolved target precision.Details and comments
Job Handling
Users can construct estimator PUBs from Pauli labels, Pauli maps, Pauli term vectors, Runtime-compatible observable JSON,
SparseObservable, or a vector ofSparseObservablevalues.The implementation rejects measured circuits before backend submission, both through
BackendEstimatorV2::run()and the QRMI payload helper used by direct QRMI backend calls.The estimator currently requires QRMI or another backend that implements
BackendV2::run(std::vector<EstimatorPub>&, double).BackendEstimatorJob::cancel()returnsfalsebecause estimator cancellation is not wired that it needs a provider-level contract, not just an estimator change.BackendEstimatorJob::result()waits until the provider job reaches a final state, but onlyDONEcan produce estimator results.FAILED,CANCELLED, andERRORfinal states throw instead of returning partial or empty successful results. Provider result-count mismatches and provider read failures also throw.QRMI result handling now caches the parsed result envelope, validates that the provider response contains a
resultsarray before indexing into it, and stops the QRMI task after reading results. This keeps the estimator path robust while preserving sampler QRMI cleanup behavior.Files In Scope
The estimator-specific files are:
src/primitives/backend_estimator_v2.hppsrc/primitives/backend_estimator_job.hppsrc/primitives/containers/estimator_pub.hppsrc/primitives/containers/estimator_pub_result.hppsrc/primitives/containers/estimator_primitive_result.hppsrc/providers/qrmi_estimator_payload.hpptest/test_estimator.cppsamples/estimator_test.cppreleasenotes/notes/backend-estimator-v2-145.yamlThe shared-file changes are in scope because estimator support needs them:
BackendV2needs an estimatorrun()overload.Jobneeds an estimator result overload.parsing.
QuantumCircuitneeds measurement detection because estimator circuits mustbe rejected before submission.
SparseObservableneeds safe copy/access helpers so estimator PUBs canserialize sparse observables into Runtime-compatible Pauli maps.
the current backend requirement.
Test Coverage
The estimator test suite covers:
program_id = "estimator".SparseObservableserialization.evs.stdslength mismatch.ERROR,FAILED, andCANCELLEDprovider states.Verification Status
Local Test Operation
Commands:
Run Successfully:
git diff --checkexits with code0.test/buildafter findingqiskit_cext.test_driver test_estimatorpasses all estimator-focused tests.ctestpasses the full local test suite.IBM Quantum Hardware Test
Run the hardware validation from the
qiskit-cpp/samples/directory after the local unit tests pass. This operation submits the estimator sample through QRMI to IBM Quantum Runtime.Commands:
Run Successfully:
estimator_testexecutable.ibm_kingstonwith Runtime jobstatus
DONE.12quantum seconds.version = 2.Submitted workload:
The current sample is submits an unmeasured circuit to Estimator and applies the transpiler layout to the observable terms before building the
SparseObservable. That proves the hardware path is using a real Estimator V2 workload: an ISA-compatible circuit, layout-mapped observables, a native QRMI Runtimeestimatorsubmission, and a Runtime job that reachedDONEon IBM hardware.The sample submitted
ZZ + 0.5 * XXas aSparseObservableafter applying the transpiler layout to the observable terms. The hardware run usedsamples/estimator_test.cpp, backendibm_kingston, target precision0.02Checklist
releasenotes/notes/backend-estimator-v2-145.yamltest/