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

Something weird happening in transpile after 1.1 release #12425

Closed
nkanazawa1989 opened this issue May 17, 2024 · 8 comments · Fixed by Qiskit/qiskit-aer#2142
Closed

Something weird happening in transpile after 1.1 release #12425

nkanazawa1989 opened this issue May 17, 2024 · 8 comments · Fixed by Qiskit/qiskit-aer#2142
Labels
bug Something isn't working

Comments

@nkanazawa1989
Copy link
Contributor

nkanazawa1989 commented May 17, 2024

Environment

  • Qiskit version: 1.1.0
  • Python version: 3.11.5
  • Operating system: MacOS

What is happening?

I noticed Qiskit Experiments tests relying on Qiskit Aer are now all failing, for example 1414. According to the error log the aer simulator backend reports basis gates which is a subset of what it can actually support. This is not a bug in Qiskit Aer.

How can we reproduce the issue?

For example

from qiskit_aer import AerSimulator
from qiskit_experiments.library import StateTomography
import qiskit.quantum_info as qi

seed = 1234
shots = 5000
f_threshold = 0.99

num_qubits = 1

# Generate tomography data without analysis
backend = AerSimulator(seed_simulator=seed, shots=shots)
target = qi.random_statevector(2**num_qubits, seed=seed)

exp = StateTomography(target)
expdata = exp.run(backend, analysis=None)

This code works okey with qiskit==1.0.2. However with 1.1.0 I get this error

TranspilerError: "Unable to translate the operations in the circuit: ['measure', 'h', 'initialize', 'barrier'] to the backend's (or manually specified) target basis: ['store', 'initialize', 'measure', 'barrier', 'snapshot']. This likely means the target basis is not universal or there are additional equivalence rules needed in the EquivalenceLibrary being used. For more details on this error see: https://docs.quantum.ibm.com/api/qiskit/transpiler_passes.BasisTranslator#translation-errors"

What should happen?

Transpile should work as before.

Any suggestions?

I don't know. I'll investigate.

@nkanazawa1989 nkanazawa1989 added the bug Something isn't working label May 17, 2024
@nkanazawa1989
Copy link
Contributor Author

nkanazawa1989 commented May 17, 2024

Maybe due to this change #12410? After this PR, outside parallel environment we bypass PM serialization but this means every run share the same state. I confirmed

transpile(exp.circuits()[0], backend=backend, initial_layout=[0])

works okey

transpile(exp.circuits(), backend=backend, initial_layout=[0])

errors.

This makes me think some compiler pass unexpectedly mutate Target information or some stateful pass is not reset after run.

@nkanazawa1989
Copy link
Contributor Author

Also confirmed the backend target is not mutated. So this is likely due to pass state issue.

@t-imamichi
Copy link
Member

t-imamichi commented May 17, 2024

It's interesting. It works with BasicSimulator but fails with AerSimulator. I made a simple case to reproduce it.

macOS 14.5 arm
qiskit 1.1.0
qiskit-aer 0.14.1

from qiskit import QuantumCircuit, transpile
from qiskit.providers.basic_provider import BasicSimulator
from qiskit_aer import AerSimulator

qc = [QuantumCircuit(1) for _ in range(2)]
qc[0].rx(0, 0)
qc[1].p(0, 0)

# OK
backend = BasicSimulator()
_ = transpile(qc, backend=backend)

# NG
backend = AerSimulator()
_ = transpile(qc, backend=backend)

# qiskit.transpiler.exceptions.TranspilerError: "Unable to translate the operations in the circuit: ['p'] to the backend's (or manually specified) target basis: ['measure', 'barrier', 'store', 'snapshot', 'rx']. This likely means the target basis is not universal or there are additional equivalence rules needed in the EquivalenceLibrary being used. For more details on this error see: https://docs.quantum.ibm.com/api/qiskit/transpiler_passes.BasisTranslator#translation-errors"

@nkanazawa1989
Copy link
Contributor Author

I also confirmed. Then this should NOT be the pass state issue. I found another behavior.

# OK
backend = AerSimulator()
_ = transpile(qc, target=backend.target)

So this is due to weird interaction between Qiskit and QiskitAer. Perhaps this is why our unit test doesn't catch this serious problem.

@mtreinish
Copy link
Member

mtreinish commented May 17, 2024

I expect this is an aer bug stemming from their custom translation stage pass: https://github.com/Qiskit/qiskit-aer/blob/main/qiskit_aer/backends/plugin/aer_backend_plugin.py . That pass mutates it's own Target using explicit internal private attributes, which was always unsound, but likely was never caught because of the serialization that was changed in #12410 because the target was essentially always deepcopied between runs before.

You can probably confirm by either setting ignore_backend_supplied_default_methods=True or running translation_method=translator on the transpile call which will disable aer's custom pass.

@nkanazawa1989
Copy link
Contributor Author

Ah I see this is why #12425 (comment) runs without error. Indeed there is no Aer backend that injects that custom pass.

@t-imamichi
Copy link
Member

Thank you for investigating this issue, Matthew. We then need to transfer this issue to Aer.

mtreinish added a commit to mtreinish/qiskit-aer that referenced this issue May 17, 2024
This commit removes the qiskit aer translation plugin. This was added as
a workaround for a Qiskit/qiskit#11351. This has been fixed in Qiskit
since 0.45.2 and is no longer necessary. The mechanism by which the
workaround worked was unsound in practice as it was mutating the target
and also explicitly using private attributes of the Target. This is
causing real issues now as it only worked by assuming the target wasn't
shared between passmanagers which is never guaranteed. Similarly the
reliance on internal private attributes of the Target class will cause
issues in the future when the target internals change (see
Qiskit/qiskit#12292). This commit opts to remove the plugin in its
entirity as it's no longer necessary and actively causing issues with
Qiskit 1.1 and transpiling targeting aer backends with >1 circuit. As
it's private internal detail there isn't a release note.

Fixes Qiskit/qiskit#12425
Fixes Qiskit#2141
mtreinish added a commit to mtreinish/qiskit-aer that referenced this issue May 17, 2024
This commit removes the qiskit aer translation plugin. This was added as
a workaround for a Qiskit/qiskit#11351. This has been fixed in Qiskit
since 0.45.2 and is no longer necessary. The mechanism by which the
workaround worked was unsound in practice as it was mutating the target
and also explicitly using private attributes of the Target. This is
causing real issues now as it only worked by assuming the target wasn't
shared between passmanagers which is never guaranteed. Similarly the
reliance on internal private attributes of the Target class will cause
issues in the future when the target internals change (see
Qiskit/qiskit#12292). This commit opts to remove the plugin in its
entirity as it's no longer necessary and actively causing issues with
Qiskit 1.1 and transpiling targeting aer backends with >1 circuit. As
it's private internal detail there isn't a release note.

Fixes Qiskit/qiskit#12425
Fixes Qiskit#2141
doichanj pushed a commit to Qiskit/qiskit-aer that referenced this issue May 20, 2024
This commit removes the qiskit aer translation plugin. This was added as
a workaround for a Qiskit/qiskit#11351. This has been fixed in Qiskit
since 0.45.2 and is no longer necessary. The mechanism by which the
workaround worked was unsound in practice as it was mutating the target
and also explicitly using private attributes of the Target. This is
causing real issues now as it only worked by assuming the target wasn't
shared between passmanagers which is never guaranteed. Similarly the
reliance on internal private attributes of the Target class will cause
issues in the future when the target internals change (see
Qiskit/qiskit#12292). This commit opts to remove the plugin in its
entirity as it's no longer necessary and actively causing issues with
Qiskit 1.1 and transpiling targeting aer backends with >1 circuit. As
it's private internal detail there isn't a release note.

Fixes Qiskit/qiskit#12425
Fixes #2141
@mtreinish
Copy link
Member

I'm going to close this because the underlying issue in aer was marked as closed and fixed by Qiskit/qiskit-aer#2142. It is still waiting on a new aer release though.

doichanj pushed a commit to doichanj/qiskit-aer that referenced this issue May 23, 2024
This commit removes the qiskit aer translation plugin. This was added as
a workaround for a Qiskit/qiskit#11351. This has been fixed in Qiskit
since 0.45.2 and is no longer necessary. The mechanism by which the
workaround worked was unsound in practice as it was mutating the target
and also explicitly using private attributes of the Target. This is
causing real issues now as it only worked by assuming the target wasn't
shared between passmanagers which is never guaranteed. Similarly the
reliance on internal private attributes of the Target class will cause
issues in the future when the target internals change (see
Qiskit/qiskit#12292). This commit opts to remove the plugin in its
entirity as it's no longer necessary and actively causing issues with
Qiskit 1.1 and transpiling targeting aer backends with >1 circuit. As
it's private internal detail there isn't a release note.

Fixes Qiskit/qiskit#12425
Fixes Qiskit#2141
doichanj added a commit to Qiskit/qiskit-aer that referenced this issue May 31, 2024
* release 0.14.2

* Disable test shot_branching on MacOS (#2143)

* remove test_shot_branching

* disable sho_branching tests on MacOS

* fix test

* fix test

* format

* fix test_shot_branching

* fix test_runtime_parameterization

* fix tests for the latest Qiskit (#2138)

* Remove qiskit aer translation stage (#2142)

This commit removes the qiskit aer translation plugin. This was added as
a workaround for a Qiskit/qiskit#11351. This has been fixed in Qiskit
since 0.45.2 and is no longer necessary. The mechanism by which the
workaround worked was unsound in practice as it was mutating the target
and also explicitly using private attributes of the Target. This is
causing real issues now as it only worked by assuming the target wasn't
shared between passmanagers which is never guaranteed. Similarly the
reliance on internal private attributes of the Target class will cause
issues in the future when the target internals change (see
Qiskit/qiskit#12292). This commit opts to remove the plugin in its
entirity as it's no longer necessary and actively causing issues with
Qiskit 1.1 and transpiling targeting aer backends with >1 circuit. As
it's private internal detail there isn't a release note.

Fixes Qiskit/qiskit#12425
Fixes #2141

* Fix issue 2084 again (#2119)

* Fix issue 2084 again

* format

* fix test

* fix test

* Always hook omp functions in Mac (#2128)

* always hook omp functions in Mac

* fix recent test failures with the latest qiskit

---------

Co-authored-by: Jun Doi <doichan@jp.ibm.com>

* Add simulator_metadata in metadata of SamplerV2 (#2109)

Co-authored-by: Hiroshi Horii <hhorii@users.noreply.github.com>

* Fix cuStateVec_enable option (#2146)

* Fix cuStateVec_enable option

* fix function name

* Add support for rotation gates (#2147)

* add rotation gates

* add cr* gates to operations.hpp

* fix test for stabilkize/extended-stabilizer

* fix test again

* Fix deterministic measure of stabilizer (#2132)

* Fix deterministic measure of stabilizer

* fix accumulation in loop

* format

---------

Co-authored-by: Hiroshi Horii <hhorii@users.noreply.github.com>

* Fix init of EstimatorV2 and SamplerV2 (#2120)

* fix init of EstimatorV2 and SamplerV2 to handle method

* add release note

* fix from_backend and example in README

* remove setting density_matrix

* Fix deploy.yml (#2110)

Co-authored-by: Hiroshi Horii <hhorii@users.noreply.github.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Add support for ECR gate to MPS (#2137)

* Add support for ECR gate

* replace is not to !=

* fix release note

* Fix ecr implementation for stabilizer/extended-stabilizer

* Handle gates with ctrl_stete=0 (#2148)

* handle cx gate with ctrl_stete=0

* add handling *_o0, add test for cx_o0

* format

* fix test

* fix test

* fix test cx

* fix to handle multiple control states

* fix ctrl_state

* format

* resolve conflict again

* fix aer_compiler

* fix random seed (#2151)

Co-authored-by: Hiroshi Horii <hhorii@users.noreply.github.com>

* Move delay gate to custom instructions (#2153)

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Hiroshi Horii <hhorii@users.noreply.github.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
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

Successfully merging a pull request may close this issue.

3 participants