Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calibrations or Experiments not working with Sampler usage with Qiskit DynamicsBackend #1487

Open
arthurostrauss opened this issue Nov 15, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@arthurostrauss
Copy link

Informations

  • Qiskit Experiments version: 0.8.0
  • Python version: 3.10
  • Operating system: Mac OS Sequoia

What is the current behavior?

Trying to set up calibration experiments or characterization experiments yield an error in the creation of the analysis result, making the whole workflow broken when used with Qiskit Dynamics.

The following is displayed when printing analysis_results():

Options {'execution': {'meas_type': 'kerneled'}} have no effect in local testing mode.

[]
Job data not added for errored job [Job ID: 9ac2115c-19ec-4b76-9b56-e7bd5876a9b6]
Error message: n/a

Steps to reproduce the problem

`
from qiskit.quantum_info import Operator
from qiskit_dynamics import DynamicsBackend, Solver
import numpy as np
from qiskit_experiments.library.calibration import RoughXSXAmplitudeCal
from qiskit_experiments.calibration_management import Calibrations, FixedFrequencyTransmon

Define the backend for the dynamics simulation

nu_z = 10.
nu_x = 1.
nu_d = 9.98 # Almost on resonance with the Hamiltonian's energy levels difference, nu_z

X = Operator.from_label('X')
Y = Operator.from_label('Y')
Z = Operator.from_label('Z')
s_p = 0.5 * (X + 1j * Y)

solver = Solver(
static_hamiltonian=.5 * 2 * np.pi * nu_z * Z,
hamiltonian_operators=[2 * np.pi * nu_x * X],
hamiltonian_channels=["d0"],
channel_carrier_freqs={"d0": nu_x},
dt=0.01,
)

dynamics_backend = DynamicsBackend(solver=solver, subsystem_dims=[2])

Calibrate a X gate

cals = Calibrations(libraries=[FixedFrequencyTransmon(["x", "sx"])])
exp = RoughXSXAmplitudeCal([0], cals, amplitudes=np.linspace(-0.2, 0.2, 21))
exp_data = exp.run(backend=dynamics_backend).block_for_results()

print(exp_data.analysis_results())`

What is the expected behavior?

The analysis result should at the very least not be empty and no error should be generated.

Suggested solutions

Check back how Experiments handles the PUB results from the primitive call and see if something does not break. For now when using backend_run=True, everything works normally.

Also, a change in Qiskit Runtime could be relevant for dealing with options efficiently, as it seems that an execution option for the experiment is dropped down by the call tp the local service

@arthurostrauss arthurostrauss added the bug Something isn't working label Nov 15, 2024
@wshanks
Copy link
Collaborator

wshanks commented Nov 15, 2024

There are a few issues at play here related to getting the measurement level communicated through the stack.

  1. First, for experiments falling back to SamplerV2 from qiskit-ibm-runtime and going through BackendSamplerV2, support for passing options through to backend.run and for processing level 1 data is needed. I added that support to BackendSamplerV2 in Add run_options option and support for processing level 1 data to BackendSamplerV2 Qiskit/qiskit#13357, which will be in Qiskit 1.3 (you can use pip install qiskit==1.3rc1 now).
  2. There is a point in the BackendSamplerV2 data processing here where it checks if the result data memory is truthy. Dynamics returns a numpy array for this which raises an exception on being cast to a boolean. The Qiskit base class specifies list for the type of the memory, so I think Dynamics should switch to returning a list. We had to add tolist() to data returned by PulseBackend in Add support executing circuits with a SamplerV2 instance #1470 as well.
  3. When trying to update Qiskit to 1.3 to take advantage of the updates described in point 1 above, an incompatibility between Dynamics and Qiskit is encountered. I reported that in DynamicsBackend sets Target.num_qubits which is not settable in Qiskit 1.3 qiskit-dynamics#366.
  4. With Qiskit 1.3 and the two fixes to Dynamics, things almost work, but there is still a problem getting options from qiskit_ibm_runtime.SamplerV2 to BackendSamplerV2. I started working on that in Add support for noise model and level 1 data to local sampler Qiskit/qiskit-ibm-runtime#1990, but I still need to finish it. It was written for my original version of Add run_options option and support for processing level 1 data to BackendSamplerV2 Qiskit/qiskit#13357 that passed individual options through and hasn't been updated yet to work with the final version that puts all the backend.run options into a run_options option.

@wshanks
Copy link
Collaborator

wshanks commented Nov 15, 2024

By the way, didn't you make your own SamplerV2 that works with Dynamics? Have you tried passing that to BaseExperiment.run as the sampler argument instead of letting it default to qiskit_ibm_runtime.SamplerV2?

wshanks added a commit to wshanks/qiskit-dynamics that referenced this issue Nov 15, 2024
In Qiskit, it is specified that memory should be a list
(https://github.com/Qiskit/qiskit/blob/b9d5c9c6aeb4568b6e9fba8943517ebed300886d/qiskit/result/models.py#L38).
While most code can work with either lists or numpy arrays, some can
not, including BackendSamplerV2 in Qiskit (see
qiskit-community/qiskit-experiments#1487).
Here the numpy array data is converted to a nested list using
`tolist()`.
@arthurostrauss
Copy link
Author

Thanks for this detailed reply @wshanks. I have also tried to pass directly a pre-defined BackendSamplerV2 instance and got the same result, probably because I have not tested with Qiskit 1.3 yet. For your point 2, should I raise this as an issue on Qiskit Dynamics repo? I do not know if @DanPuzzuoli is aware of this issue already.

@wshanks
Copy link
Collaborator

wshanks commented Nov 18, 2024

For point 2, I opened qiskit-community/qiskit-dynamics#367. The CI failed but the failures seemed unrelated to the change. It seems like the Dynamics repo needs some maintenance to run with the latest version of qiskit-ibm-runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants