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

Proper handling of serialized numpy metadata #1218

Closed
coruscating opened this issue Jul 7, 2023 · 0 comments
Closed

Proper handling of serialized numpy metadata #1218

coruscating opened this issue Jul 7, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@coruscating
Copy link
Collaborator

FineAmplitude fails when a numpy array is passed in as an experiment option:

qc = QuantumCircuit(2)
qc.rzx(np.pi/2,0,1)

with pulse.build(backend=backend, name="szx") as rzx:
    pulse.call(qc)

inst_map = InstructionScheduleMap()
inst_map.add("szx", (0,1), rzx)

fine_amp = FineZXAmplitude((0,1), backend)
fine_amp.set_transpile_options(inst_map=inst_map)
fine_amp.set_experiment_options(repetitions=np.arange(0,10,1))

expdata = fine_amp.run(backend).block_for_results()

This code doesn't run at all with qiskit-ibm-provider < 0.6.1, which is the version that fixes numpy serialization (we should probably add this as a requirement). With 0.6.1, the error occurs in the analysis:

Traceback (most recent call last):
  File "qiskit_experiments/framework/experiment_data.py", line 897, in _run_analysis_callback
    callback(self, **kwargs)
  File "qiskit_experiments/framework/base_analysis.py", line 169, in run_analysis
    results, figures = analysis._run_analysis(expdata)
  File "qiskit_experiments/curve_analysis/curve_analysis.py", line 384, in _run_analysis
    processed_data = self._run_data_processing(
  File "qiskit_experiments/curve_analysis/curve_analysis.py", line 172, in _run_data_processing
    xdata = np.asarray([datum["metadata"][x_key] for datum in analyzed_data], dtype=float)
TypeError: float() argument must be a string or a number, not 'dict'

This happens because these numpy ints are serialized to {"__type__": "int", "__value__": int(obj)} dicts in the provider. @nkanazawa1989 Perhaps just adding handling for these types in CurveAnalysis will fix this?

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