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

Circuits with Reset can not be transpiled with AerSimulator with a noise model #1975

Closed
wshanks opened this issue Oct 27, 2023 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@wshanks
Copy link
Contributor

wshanks commented Oct 27, 2023

Informations

  • Qiskit Aer version: 0.13.0
  • Python version: 3.11
  • Operating system: Fedora Linux 38

What is the current behavior?

When trying to transpile a circuit with a Reset instruction with an AerSimulator backend with a noise model, the transpiler raises an exception about "reset" not being in the equivalence library.

Steps to reproduce the problem

import numpy as np
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_aer.noise import NoiseModel



noise_model = NoiseModel()
# Uncomment this line for a successful transpilation
# noise_model = NoiseModel(basis_gates=["id", "rz", "sx", "cx", "reset"])
noise_model.add_readout_error(np.array([[0.9, 0.1], [0.1, 0.9]]), [0])

backend = AerSimulator(noise_model=noise_model)

qc = QuantumCircuit(1, 1)
qc.reset(0)
qc.measure(0, 0)
transpile(qc, backend)

What is the expected behavior?

Successful transpilation

Suggested solutions

This is a consequence of the conversion to BackendV2. Before the conversion, AerSimulator had no target object so this code would execute and insert reset into the list of allowed instructions. Now when the noise model is set as an option, this code sets the basis gates:

if key in ["method", "noise_model", "basis_gates"]:
self._cached_basis_gates = self._basis_gates()

which takes the intersection of the default set with the basis gates of the noise model:

if noise_model:
noise_gates = noise_model.basis_gates
basis_gates = basis_gates.intersection(noise_gates)

which defaults to just a small set of gates:

if basis_gates is None:
# Default basis gates is id, rz, sx, cx so that all standard
# non-identity instructions can be unrolled to rz, sx, cx,
# and identities won't be unrolled
self._basis_gates = set(["id", "rz", "sx", "cx"])

These cached basis gates get used to set the backend configuration basis gates:

config.basis_gates = self._cached_basis_gates + config.custom_instructions

The convert_to_target() function which AerSimulator uses to generate the target object uses the configuration basis gates to set the instructions in the target and so "reset" is not included.

I am not sure if it makes sense to add reset to the default set for NoiseModel or if some other solution is preferred. My workaround for now is to use NoiseModel(basis_gates=["id", "rz", "sx", "cx", "reset"]).

@wshanks wshanks added the bug Something isn't working label Oct 27, 2023
github-merge-queue bot pushed a commit to qiskit-community/qiskit-experiments that referenced this issue Oct 31, 2023
This sets the basis gates explicitly on the `NoiseModel` used for some
tomography tests. Without this, some of the test circuits fail to
transpile because `reset` is not in the equivalence library when using
qiskit-aer 0.13.0 (see
Qiskit/qiskit-aer#1975).
github-merge-queue bot pushed a commit to qiskit-community/qiskit-experiments that referenced this issue Oct 31, 2023
This sets the basis gates explicitly on the `NoiseModel` used for some
tomography tests. Without this, some of the test circuits fail to
transpile because `reset` is not in the equivalence library when using
qiskit-aer 0.13.0 (see
Qiskit/qiskit-aer#1975).
@wshanks
Copy link
Contributor Author

wshanks commented Oct 31, 2023

Closed by #1976

@wshanks wshanks closed this as completed Oct 31, 2023
mergify bot pushed a commit to qiskit-community/qiskit-experiments that referenced this issue Oct 31, 2023
This sets the basis gates explicitly on the `NoiseModel` used for some
tomography tests. Without this, some of the test circuits fail to
transpile because `reset` is not in the equivalence library when using
qiskit-aer 0.13.0 (see
Qiskit/qiskit-aer#1975).

(cherry picked from commit c2c6097)
wshanks added a commit to wshanks/qiskit-experiments that referenced this issue Nov 28, 2023
+ Unpin qiskit-aer extra requirement now that 0.13.1 has been released
  and we do not have to worry about
Qiskit/qiskit-aer#1985
+ Remove workaround in test for
  Qiskit/qiskit-aer#1975

Note that the tests will not pass with 0.13.0 because the workaround was
removed, but the workaround was for an Aer bug so we don't reflect it as
an incomapitibility with qiskit-experiments.
wshanks added a commit to wshanks/qiskit-experiments that referenced this issue Nov 28, 2023
+ Unpin qiskit-aer extra requirement now that 0.13.1 has been released
  and we do not have to worry about
Qiskit/qiskit-aer#1985
+ Remove workaround in test for
  Qiskit/qiskit-aer#1975

Note that the tests will not pass with 0.13.0 because the workaround was
removed, but the workaround was for an Aer bug so we don't reflect it as
an incomapitibility with qiskit-experiments.
github-merge-queue bot pushed a commit to qiskit-community/qiskit-experiments that referenced this issue Nov 29, 2023
+ Unpin qiskit-aer extra requirement now that 0.13.1 has been released
and we do not have to worry about
Qiskit/qiskit-aer#1985
+ Remove workaround in test for
Qiskit/qiskit-aer#1975

Note that the tests will not pass with 0.13.0 because the workaround was
removed, but the workaround was for an Aer bug so we don't reflect it as
an incomapitibility with qiskit-experiments.
github-merge-queue bot pushed a commit to qiskit-community/qiskit-experiments that referenced this issue Nov 29, 2023
+ Unpin qiskit-aer extra requirement now that 0.13.1 has been released
and we do not have to worry about
Qiskit/qiskit-aer#1985
+ Remove workaround in test for
Qiskit/qiskit-aer#1975

Note that the tests will not pass with 0.13.0 because the workaround was
removed, but the workaround was for an Aer bug so we don't reflect it as
an incomapitibility with qiskit-experiments.
github-merge-queue bot pushed a commit to qiskit-community/qiskit-experiments that referenced this issue Nov 29, 2023
+ Unpin qiskit-aer extra requirement now that 0.13.1 has been released
and we do not have to worry about
Qiskit/qiskit-aer#1985
+ Remove workaround in test for
Qiskit/qiskit-aer#1975

Note that the tests will not pass with 0.13.0 because the workaround was
removed, but the workaround was for an Aer bug so we don't reflect it as
an incomapitibility with qiskit-experiments.
itoko pushed a commit to itoko/qiskit-experiments that referenced this issue Dec 12, 2023
+ Unpin qiskit-aer extra requirement now that 0.13.1 has been released
and we do not have to worry about
Qiskit/qiskit-aer#1985
+ Remove workaround in test for
Qiskit/qiskit-aer#1975

Note that the tests will not pass with 0.13.0 because the workaround was
removed, but the workaround was for an Aer bug so we don't reflect it as
an incomapitibility with qiskit-experiments.
nkanazawa1989 pushed a commit to nkanazawa1989/qiskit-experiments that referenced this issue Jan 17, 2024
This sets the basis gates explicitly on the `NoiseModel` used for some
tomography tests. Without this, some of the test circuits fail to
transpile because `reset` is not in the equivalence library when using
qiskit-aer 0.13.0 (see
Qiskit/qiskit-aer#1975).
nkanazawa1989 pushed a commit to nkanazawa1989/qiskit-experiments that referenced this issue Jan 17, 2024
+ Unpin qiskit-aer extra requirement now that 0.13.1 has been released
and we do not have to worry about
Qiskit/qiskit-aer#1985
+ Remove workaround in test for
Qiskit/qiskit-aer#1975

Note that the tests will not pass with 0.13.0 because the workaround was
removed, but the workaround was for an Aer bug so we don't reflect it as
an incomapitibility with qiskit-experiments.
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

1 participant