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

Simulation fails when circuit contains metadata #1435

Closed
kevinsung opened this issue Jan 24, 2022 · 1 comment
Closed

Simulation fails when circuit contains metadata #1435

kevinsung opened this issue Jan 24, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@kevinsung
Copy link

Informations

  • Qiskit Aer version: 0.10.2
  • Python version: 3.8
  • Operating system: Arch Linux

What is the current behavior?

Simulation fails when circuit contains metadata.

Steps to reproduce the problem

Input:

from qiskit import Aer, QuantumCircuit

backend = Aer.get_backend("statevector_simulator")
circuit = QuantumCircuit(1, metadata = {1: object})
backend.run(circuit)

Output:

Simulation failed and returned the following error message:
ERROR: Failed to load qobj: to_json not implemented for this type of object: <class 'type'>

Input:

from qiskit import Aer, QuantumCircuit

backend = Aer.get_backend("statevector_simulator")
circuit = QuantumCircuit(1, metadata = {object: 1})
backend.run(circuit)

Output:

Simulation failed and returned the following error message:
ERROR: Failed to load qobj: Unable to cast Python instance to C++ type (compile in debug mode for details)

What is the expected behavior?

Simulation should succeed. The metadata should be handled according to https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.html#qiskit.circuit.QuantumCircuit, which says

metadata (dict) – Arbitrary key value metadata to associate with the circuit. This gets stored as free-form data in a dict in the metadata attribute. It will not be directly used in the circuit.

Suggested solutions

None (yet).

@kevinsung kevinsung added the bug Something isn't working label Jan 24, 2022
@chriseclectic
Copy link
Member

@hhorii For this one it might be better to not attempt to serialize the header information at all, and instead store it on the python side and add it back to the results after execution.

hhorii added a commit to hhorii/qiskit-aer that referenced this issue Mar 30, 2022
The to_json() method  is called for each circuit header.
A header may include metadata and metadata can be a python object.
This PR changes serialization of circuit headers to use py::handle without serializing to a json.

Fixes Qiskit#1435


* use python parser for circuit.header

* support metadata copy with parameterization

* avoid serialization of circuit metadata

* use circuit_index to specify metadata

* remove metadata from qobj for Aer to simulate circuits

* add release note

* clear circuite metadata correctly.

* take unnecessary tests for circuit metadata backup/recovery

* work around metadata serialization issue within _run method

* Update releasenotes/notes/remove_circuit_metadata_from_qobj-324e7ea9b369ee67.yaml
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