-
Notifications
You must be signed in to change notification settings - Fork 29
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
Allow users to specify cut decompositions in terms of a native gate set #495
Changes from 4 commits
f83dcd7
bd32f39
65fcdb4
512060f
73d8ab9
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,155 @@ | ||
# 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/ | ||
|
||
""" | ||
|
||
import numpy as np | ||
from qiskit.circuit import ( | ||
EquivalenceLibrary, | ||
QuantumCircuit, | ||
QuantumRegister, | ||
Parameter, | ||
) | ||
from qiskit.circuit.library.standard_gates import ( | ||
RZGate, | ||
XGate, | ||
YGate, | ||
ZGate, | ||
HGate, | ||
SGate, | ||
IGate, | ||
SdgGate, | ||
SXGate, | ||
SXdgGate, | ||
TGate, | ||
TdgGate, | ||
RXGate, | ||
RYGate, | ||
PhaseGate, | ||
) | ||
|
||
_eagle_sel = HeronEquivalenceLibrary = EagleEquivalenceLibrary = EquivalenceLibrary() | ||
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 document that these libraries are for single-qubit operations only. Should also document that it is assumed that each input will produce, at most, one equivalence. 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. Maybe the names of the classes should include |
||
|
||
########## Single-qubit Eagle native gate set: x, sx, rz, i ########## | ||
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 think it's better to delete the native gates from the equivalence library. Qiskit equivalence libraries don't return the gate itself, only alternate equivalences. |
||
# XGate | ||
q = QuantumRegister(1, "q") | ||
def_x = QuantumCircuit(q) | ||
def_x.append(XGate(), [0], []) | ||
_eagle_sel.add_equivalence(XGate(), def_x) | ||
|
||
# SXGate | ||
q = QuantumRegister(1, "q") | ||
def_sx = QuantumCircuit(q) | ||
def_sx.append(SXGate(), [0], []) | ||
_eagle_sel.add_equivalence(SXGate(), def_sx) | ||
|
||
# RZGate | ||
q = QuantumRegister(1, "q") | ||
def_rz = QuantumCircuit(q) | ||
theta = Parameter("theta") | ||
def_rz.append(RZGate(theta), [0], []) | ||
_eagle_sel.add_equivalence(RZGate(theta), def_rz) | ||
|
||
# IGate | ||
q = QuantumRegister(1, "q") | ||
def_i = QuantumCircuit(q) | ||
def_i.append(IGate(), [0], []) | ||
_eagle_sel.add_equivalence(IGate(), def_i) | ||
|
||
###################################################################### | ||
|
||
# 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 [ | ||
RZGate(np.pi / 2), | ||
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. The |
||
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), 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. Another strange one from |
||
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) |
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.
Should assert equiv is length-1 here