-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add import for classes in qiskit/quantum_info/synthesis #11672
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
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 7738290304
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the right call, just one inline suggestion. Otherwise LGTM
I think there is likely some follow up work on main
to expose the various specialized two qubit decomposer classes as public and include them in the documentation.
from __future__ import annotations | ||
import warnings | ||
|
||
from qiskit.synthesis.two_qubit.two_qubit_decompose import TwoQubitWeylDecomposition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few public decomposer classes in the module. It's probably better to play it safe with:
from qiskit.synthesis.two_qubit.two_qubit_decompose import TwoQubitWeylDecomposition | |
from qiskit.synthesis.two_qubit.two_qubit_decompose import * |
and expose them all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I try to do this change, I get the following pylint errors:
qiskit/quantum_info/synthesis/two_qubit_decompose.py:30:0: W0401: Wildcard import qiskit.synthesis.two_qubit.two_qubit_decompose (wildcard-import)
qiskit/quantum_info/synthesis/two_qubit_decompose.py:30:0: W0614: Unused import(s) cmath, math, io, base64, logging, np, logger, decompose_two_qubit_product_gate, TwoQubitWeylDecomposition, TwoQubitWeylIdEquiv, TwoQubitWeylSWAPEquiv, TwoQubitWeylPartialSWAPEquiv, TwoQubitWeylPartialSWAPFlipEquiv, TwoQubitWeylControlledEquiv, TwoQubitControlledUDecomposer, TwoQubitWeylMirrorControlledEquiv, TwoQubitWeylfSimaabEquiv, TwoQubitWeylfSimabbEquiv, TwoQubitWeylfSimabmbEquiv, TwoQubitWeylGeneral, Ud, trace_to_fid, rz_array, TwoQubitBasisDecomposer, TwoQubitDecomposeUpToDiagonal, two_qubit_cnot_decompose, ClassVar, Optional, Type, QuantumRegister, QuantumCircuit, Gate, CXGate, RXGate, RYGate, RZGate, QiskitError, Operator, weyl_coordinates, transform_to_magic_basis, OneQubitEulerDecomposer, DEFAULT_ATOL and deprecate_arg from wildcard import of qiskit.synthesis.two_qubit.two_qubit_decompose (unused-wildcard-import)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add more classes to the import (and later also to the main branch documentation), but I think it would be better to state them specifically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that except of TwoQubitWeylDecomposition, TwoQubitControlledUDecomposer, TwoQubitDecomposeUpToDiagonal
, all other classes are variants of TwoQubitWeylDecomposition
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A search that I did in various libraries (circuit knitting
, qiskit-ibm-runtime
and qiskit-ibm-provider
) does not indicate the usage of other classes except of TwoQubitWeylDecomposition
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mostly worried about other downstream users that we don't know about, or that don't have public code anywhere that we can access. I think listing all the public classes explicitly is fine, being explicit doesn't hurt anything. It'll fix the pylint errors too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I added all the classes in the file two_qubit_decompose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mostly worried about other downstream users that we don't know about
Though there's loads of other specific imports that are still going to break. Here we're only fixing the two-qubit one, but before (<=0.45) people were able to import e.g. qiskit.quantum_info.synthesis.one_qubit_decompose
, .qsd
, .weyl
, .local_invariance
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point, on the one hand we're documenting this release as "fully compatible with the Qiskit 0.45.x releases" but with extra deprecations. But we've also documented the public interface as those that are documented. This is a weird case because qiskit.quantum_info.synthesis
is a dark corner of the API where there was a ton of undocumented functionality that wasn't exposed anywhere except in the leaf modules, and the definition of the stable api only really changed after 0.45 (in preparation for 1.0.0).
I'm inclined to just err on the side of caution more here just so people don't have an excuse for not upgrading to 0.46 and add module shims back in for everything that redirects to the new location inqiskit.synthesis
with a deprecation warning. (like what's done for __init__.py
here already)
import warnings | ||
|
||
from qiskit.synthesis.two_qubit.two_qubit_decompose import ( | ||
TwoQubitWeylDecomposition, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be missing the TwoQubitBasisDecomposer
, or is there a reason it's not here? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is a reason. This class already appeared in qiskit/quanutm_info init file, and was properly deprecated in #11460.
This PRs handles classes that have never properly appeared in qiskit/quanutm_info init file before.
from __future__ import annotations | ||
import warnings | ||
|
||
from qiskit.synthesis.two_qubit.two_qubit_decompose import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're at it, could we then also add the decompose_two_qubit_product_gate
? It also has a docstring and might have been mistaken as "public"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this function is used internally in some of the classes.
from __future__ import annotations | ||
import warnings | ||
|
||
from qiskit.synthesis.two_qubit.two_qubit_decompose import TwoQubitWeylDecomposition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mostly worried about other downstream users that we don't know about
Though there's loads of other specific imports that are still going to break. Here we're only fixing the two-qubit one, but before (<=0.45) people were able to import e.g. qiskit.quantum_info.synthesis.one_qubit_decompose
, .qsd
, .weyl
, .local_invariance
....
#11672 (comment) - I think that these functions are used internally (in 2q unitary or general unitary synthesis) |
from qiskit.synthesis.two_qubit.two_qubit_decompose import ( | ||
TwoQubitWeylDecomposition, | ||
TwoQubitControlledUDecomposer, | ||
TwoQubitDecomposeUpToDiagonal, | ||
TwoQubitWeylIdEquiv, | ||
TwoQubitWeylSWAPEquiv, | ||
TwoQubitWeylPartialSWAPEquiv, | ||
TwoQubitWeylPartialSWAPFlipEquiv, | ||
TwoQubitWeylControlledEquiv, | ||
TwoQubitWeylMirrorControlledEquiv, | ||
TwoQubitWeylfSimaabEquiv, | ||
TwoQubitWeylfSimabbEquiv, | ||
TwoQubitWeylfSimabmbEquiv, | ||
TwoQubitWeylGeneral, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking it over some more I feel a wildcard import is the proper thing to do here. We can just tell pylint to ignore the rules it was failing before:
from qiskit.synthesis.two_qubit.two_qubit_decompose import ( | |
TwoQubitWeylDecomposition, | |
TwoQubitControlledUDecomposer, | |
TwoQubitDecomposeUpToDiagonal, | |
TwoQubitWeylIdEquiv, | |
TwoQubitWeylSWAPEquiv, | |
TwoQubitWeylPartialSWAPEquiv, | |
TwoQubitWeylPartialSWAPFlipEquiv, | |
TwoQubitWeylControlledEquiv, | |
TwoQubitWeylMirrorControlledEquiv, | |
TwoQubitWeylfSimaabEquiv, | |
TwoQubitWeylfSimabbEquiv, | |
TwoQubitWeylfSimabmbEquiv, | |
TwoQubitWeylGeneral, | |
) | |
# pylint: disable=wildcard-import,unused-wildcard-import | |
from qiskit.synthesis.two_qubit.two_qubit_decompose import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtreinish, @Cryoris: |
I think this PR handles all files that were originally under
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, thanks for doing this @ShellyGarion
Summary
Fix a problem that was mentioned here:
#11635 (comment)
This line:
from qiskit.quantum_info.synthesis.two_qubit_decompose import TwoQubitWeylDecomposition
will work in Qiskit 0.46 and raise a deprecation warning.
Details and comments