-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add identity removal pass to presets #13363
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
features_transpiler: | ||
- | | ||
The :class:`.RemoveIdentityEquivalent` transpiler pass is now run as part | ||
of the preset pass managers at optimization levels 2 and 3. The pass is | ||
run in the ``init`` stage and the ``optimization`` stage, because the | ||
optimizations it applies are valid in both stages and the pass is | ||
fast to execute. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1796,21 +1796,29 @@ def test_no_infinite_loop(self, optimization_level): | |
seed_transpiler=42, | ||
) | ||
|
||
# Expect a -pi/2 global phase for the U3 to RZ/SX conversion, and | ||
# a -0.5 * theta phase for RZ to P twice, once at theta, and once at 3 pi | ||
# for the second and third RZ gates in the U3 decomposition. | ||
expected = QuantumCircuit( | ||
1, global_phase=-np.pi / 2 - 0.5 * (-0.2 + np.pi) - 0.5 * 3 * np.pi | ||
) | ||
expected.p(-np.pi, 0) | ||
expected.sx(0) | ||
expected.p(np.pi - 0.2, 0) | ||
expected.sx(0) | ||
if optimization_level == 1: | ||
# Expect a -pi/2 global phase for the U3 to RZ/SX conversion, and | ||
# a -0.5 * theta phase for RZ to P twice, once at theta, and once at 3 pi | ||
# for the second and third RZ gates in the U3 decomposition. | ||
expected = QuantumCircuit( | ||
1, global_phase=-np.pi / 2 - 0.5 * (-0.2 + np.pi) - 0.5 * 3 * np.pi | ||
) | ||
expected.p(-np.pi, 0) | ||
expected.sx(0) | ||
expected.p(np.pi - 0.2, 0) | ||
expected.sx(0) | ||
else: | ||
expected = QuantumCircuit(1, global_phase=(15 * np.pi - 1) / 10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is slightly unexpected, I guess at some point a gate is now removed and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my assumption, I don't remember the exact details though. Let me run it with a callback and see what's going on exactly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking through each pass it looks like
to:
This changes the output of
which is the output on calling the pass on the circuit with to:
which is the pass's output with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh that makes sense -- thanks for checking, better to be sure! 🙂 |
||
expected.sx(0) | ||
expected.p(1.0 / 5.0 + np.pi, 0) | ||
expected.sx(0) | ||
expected.p(3 * np.pi, 0) | ||
|
||
error_message = ( | ||
f"\nOutput circuit:\n{out!s}\n{Operator(out).data}\n" | ||
f"Expected circuit:\n{expected!s}\n{Operator(expected).data}" | ||
) | ||
self.assertEqual(Operator(qc), Operator(out)) | ||
self.assertEqual(out, expected, error_message) | ||
|
||
@data(0, 1, 2, 3) | ||
|
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 I would expect the transpiler to remove
Ry(0)
& co even as a very basic optimization, should we also include this target-free run in optimization level 1?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.
My concern with doing it for level 1 was more about small angles like
Ry(1e-8)
will be removed and I was worried that might be surprising to people especially at level 1. But I don't feel super strongly about it, it's easy enough to add it to level 1 if you think that's better.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.
Hm you're right, I didn't think that these angles are already removed already... as rule we should maybe not increase the level of approximation that is already happening (e.g. cutoffs that unitary re-synthesis does). On level 1 we don't do re-synthesis, right? So then I agree we shouldn't add it one 1 yet 🙂
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.
Level 1 will run 1q re-synthesis, but via
Optikize1qGatesDecomposition
notUnitarySynthesis
. I can't remember how that pass handles tolerances, I'll have to check.