Qiskit-Extensions / circuit-knitting-toolbox

Tools for knitting quantum circuits with Qiskit
https://qiskit-extensions.github.io/circuit-knitting-toolbox/
Apache License 2.0
74 stars 25 forks source link

Support SamplerV2 #488

Closed caleb-johnson closed 5 months ago

caleb-johnson commented 6 months ago

The circuit cutting post-processing uses the SamplerResult objects output from SamplerV1 directly; however, SamplerV2 will return PrimitiveResult objects, so our post-processing should support both types of outputs from the two different sampler interfaces

https://github.com/Qiskit/qiskit/blob/61181ce0681129f9a1d5af43122484f8b6da1bbc/qiskit/primitives/base/base_sampler.py#L231

garrison commented 6 months ago

nb: The relevant function is reconstruct_expectation_values in https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/blob/main/circuit_knitting/cutting/cutting_reconstruction.py.

For more info on the migration, see https://docs.quantum.ibm.com/api/migration-guides/qiskit-1.0-features#qiskitprimitives and https://github.com/Qiskit/qiskit-ibm-runtime?tab=readme-ov-file#primitive-versions.

garrison commented 6 months ago

Tracking issue from Qiskit Aer to support primitives V2: https://github.com/Qiskit/qiskit-aer/issues/2078

EDIT: Actually, there's no reason to wait on Aer to add support for primitives V2, but we might want to wait on Aer before we adopt the new primitives entirely. I've opened #503 as a follow up to this issue for that reason.

garrison commented 5 months ago

Actually (reversing course a second time), it seems like we do indeed need to wait for Aer to support SamplerV2 if we are to provide automated tests of this feature, because Qiskit's implemention throws an error: "StatevectorSampler cannot handle mid-circuit measurements". Unless, of course, we want to provide our own BaseSamplerV2 implementation based on our simulation.py -- but I think we are better off waiting on Aer.

garrison commented 5 months ago

it seems like we do indeed need to wait for Aer to support SamplerV2 if we are to provide automated tests of this feature

Then again, we can provide a smoke test by only executing the circuits that do not contain any mid-circuit measurements. This might be worth doing, as long as we also manually test the code using Qiskit Runtime.

garrison commented 5 months ago

An alternative would be to use BackendSamplerV2 together with AerSimulator, as suggested at https://github.com/Qiskit/qiskit-aer/issues/2078. But this would mean waiting for Qiskit 1.1 (which is when BackendSamplerV2 will first appear in a release) and will also require a fix to https://github.com/Qiskit/qiskit/issues/12043.