-
Notifications
You must be signed in to change notification settings - Fork 34
Add support for generating subexperiments with LO's translated to a native gate set #517
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
4b819c7
b89583c
679fb73
43ed255
7a5fe8a
aab23a2
c654f6a
73bccc4
0472093
fa0578c
819cc90
367e19c
f286131
c881fbc
8d1745d
ba8b744
4b796a9
b8351d1
6395205
9cf2372
f7e8cb1
4448506
4aac71f
41b5881
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,132 @@ | ||
# This code is a Qiskit project. | ||
|
||
# (C) Copyright IBM 2024. | ||
|
||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
""" | ||
Equivalence utilities. | ||
|
||
.. currentmodule:: circuit_knitting.utils.equivalence | ||
|
||
.. autosummary:: | ||
:toctree: ../stubs/ | ||
|
||
""" | ||
from collections import defaultdict | ||
|
||
import numpy as np | ||
from qiskit.circuit import ( | ||
EquivalenceLibrary, | ||
caleb-johnson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
QuantumCircuit, | ||
QuantumRegister, | ||
Parameter, | ||
) | ||
from qiskit.circuit.library.standard_gates import ( | ||
RZGate, | ||
XGate, | ||
YGate, | ||
ZGate, | ||
HGate, | ||
SGate, | ||
SdgGate, | ||
SXGate, | ||
SXdgGate, | ||
TGate, | ||
TdgGate, | ||
RXGate, | ||
RYGate, | ||
PhaseGate, | ||
) | ||
|
||
_eagle_sel = HeronEquivalenceLibrary = EagleEquivalenceLibrary = EquivalenceLibrary() | ||
equivalence_libraries = defaultdict( | ||
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. Right now, if a user passes an unsupported basis, everything will run fine and their subexperiments will be in the standard gate set. Maybe we'd prefer to error if they pass in a QPU architecture we don't support or doesn't exist? 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.
By that, do you mean that they have a
What do you mean by "everything will run fine"? What will happen to the unsupported gates? 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. If a user passes 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.
I mean they pass in a string that doesn't describe a supported QPU architecture. A string not in {"heron", "eagle"} |
||
lambda: None, {"heron": HeronEquivalenceLibrary, "eagle": EagleEquivalenceLibrary} | ||
) | ||
|
||
###################################################################### | ||
|
||
# YGate | ||
q = QuantumRegister(1, "q") | ||
def_y = QuantumCircuit(q) | ||
for inst in [RZGate(np.pi), XGate()]: | ||
def_y.append(inst, [0], []) | ||
_eagle_sel.add_equivalence(YGate(), def_y) | ||
|
||
# ZGate | ||
q = QuantumRegister(1, "q") | ||
def_z = QuantumCircuit(q) | ||
def_z.append(RZGate(np.pi), [0], []) | ||
_eagle_sel.add_equivalence(ZGate(), def_z) | ||
|
||
# HGate | ||
q = QuantumRegister(1, "q") | ||
def_h = QuantumCircuit(q) | ||
for inst in [RZGate(np.pi / 2), SXGate(), RZGate(np.pi / 2)]: | ||
def_h.append(inst, [0], []) | ||
_eagle_sel.add_equivalence(HGate(), def_h) | ||
|
||
# SGate | ||
q = QuantumRegister(1, "q") | ||
def_s = QuantumCircuit(q) | ||
def_s.append(RZGate(np.pi / 2), [0], []) | ||
_eagle_sel.add_equivalence(SGate(), def_s) | ||
|
||
# SdgGate | ||
q = QuantumRegister(1, "q") | ||
def_sdg = QuantumCircuit(q) | ||
def_sdg.append(RZGate(-np.pi / 2), [0], []) | ||
_eagle_sel.add_equivalence(SdgGate(), def_sdg) | ||
|
||
# SXdgGate | ||
q = QuantumRegister(1, "q") | ||
def_sxdg = QuantumCircuit(q) | ||
for inst in [ | ||
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. Another suspicious one. Should be able to do a single pi rotation on either side of |
||
RZGate(np.pi / 2), | ||
RZGate(np.pi / 2), | ||
SXGate(), | ||
RZGate(np.pi / 2), | ||
RZGate(np.pi / 2), | ||
]: | ||
def_sxdg.append(inst, [0], []) | ||
_eagle_sel.add_equivalence(SXdgGate(), def_sxdg) | ||
|
||
# TGate | ||
q = QuantumRegister(1, "q") | ||
def_t = QuantumCircuit(q) | ||
def_t.append(RZGate(np.pi / 4), [0], []) | ||
_eagle_sel.add_equivalence(TGate(), def_t) | ||
|
||
# TdgGate | ||
q = QuantumRegister(1, "q") | ||
def_tdg = QuantumCircuit(q) | ||
def_tdg.append(RZGate(-np.pi / 4), [0], []) | ||
_eagle_sel.add_equivalence(TdgGate(), def_tdg) | ||
|
||
# RXGate | ||
q = QuantumRegister(1, "q") | ||
def_rx = QuantumCircuit(q) | ||
theta = Parameter("theta") | ||
for inst in [RZGate(np.pi / 2), SXGate(), RZGate(theta + np.pi), SXGate(), RZGate(5 * np.pi / 2)]: | ||
def_rx.append(inst, [0], []) | ||
_eagle_sel.add_equivalence(RXGate(theta), def_rx) | ||
|
||
# RYGate | ||
q = QuantumRegister(1, "q") | ||
def_ry = QuantumCircuit(q) | ||
theta = Parameter("theta") | ||
for inst in [SXGate(), RZGate(theta + np.pi), SXGate(), RZGate(3 * np.pi)]: | ||
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. Should be able to rotate by 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. I suspect that the reason there are factors of greater than 2pi in the equivalence library is because a rotation of 2pi doesn't actually bring the wavefunction to its original state; instead, e.g., for RZGate, it leads to the wavefunction picking up a global phase of -1. The rotation must be by an angle of 4pi to bring its state completely to where it began (see also: the mathematics of spinors). Even though a rotation by 2pi leads to a global phase of -1, this will not result in any difference in the state that is actually physically observable, but nonetheless Qiskit carefully keeps track of global phases, and I believe this is one instance of where that leads to some rotation angles that seem a bit atypical. Here's a quick sanity check (in julia) given the RZGate definition of a rotation by 2pi: In [1]: RZ(λ) = [exp(-im * λ / 2) 0; 0 exp(im * λ / 2)]
Out[1]: RZ (generic function with 1 method)
In [2]: RZ(2π)
Out[2]: 2×2 Matrix{ComplexF64}:
-1.0-1.22465e-16im 0.0+0.0im
0.0+0.0im -1.0+1.22465e-16im |
||
def_ry.append(inst, [0], []) | ||
_eagle_sel.add_equivalence(RYGate(theta), def_ry) | ||
|
||
# PhaseGate | ||
q = QuantumRegister(1, "q") | ||
def_p = QuantumCircuit(q) | ||
theta = Parameter("theta") | ||
def_p.append(RZGate(theta), [0], []) | ||
_eagle_sel.add_equivalence(PhaseGate(theta), def_p) |
Uh oh!
There was an error while loading. Please reload this page.