-
Notifications
You must be signed in to change notification settings - Fork 35
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 get_inverse features #249
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
.hypothesis/ | ||
.venv/ | ||
.vscode/ | ||
.idea/ | ||
.mypy_cache/ | ||
.DS_Store | ||
docs/source/autogen | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from bqskit.ir.gates.constant.clock import ClockGate | ||
from bqskit.ir.gates.constant.cpi import CPIGate | ||
from bqskit.ir.gates.constant.cs import CSGate | ||
from bqskit.ir.gates.constant.csdg import CSDGGate | ||
from bqskit.ir.gates.constant.csum import CSUMGate | ||
from bqskit.ir.gates.constant.ct import CTGate | ||
from bqskit.ir.gates.constant.cx import CNOTGate | ||
|
@@ -17,6 +18,7 @@ | |
from bqskit.ir.gates.constant.h import HGate | ||
from bqskit.ir.gates.constant.identity import IdentityGate | ||
from bqskit.ir.gates.constant.iswap import ISwapGate | ||
from bqskit.ir.gates.constant.iswapdg import ISwapDGGate | ||
from bqskit.ir.gates.constant.itoffoli import IToffoliGate | ||
from bqskit.ir.gates.constant.pd import PDGate | ||
from bqskit.ir.gates.constant.permutation import PermutationGate | ||
|
@@ -27,21 +29,28 @@ | |
from bqskit.ir.gates.constant.sdg import SdgGate | ||
from bqskit.ir.gates.constant.shift import ShiftGate | ||
from bqskit.ir.gates.constant.sqrtcnot import SqrtCNOTGate | ||
from bqskit.ir.gates.constant.sqrtcnotdg import SqrtCNOTDGGate | ||
from bqskit.ir.gates.constant.sqrtiswap import SqrtISwapGate | ||
from bqskit.ir.gates.constant.sqrtiswapdg import SqrtISwapDGGate | ||
from bqskit.ir.gates.constant.subswap import SubSwapGate | ||
from bqskit.ir.gates.constant.swap import SwapGate | ||
from bqskit.ir.gates.constant.sx import SqrtXGate | ||
from bqskit.ir.gates.constant.sx import SXGate | ||
from bqskit.ir.gates.constant.sxdg import SqrtXDGGate | ||
from bqskit.ir.gates.constant.sxdg import SXDGGate | ||
from bqskit.ir.gates.constant.sycamore import SycamoreGate | ||
from bqskit.ir.gates.constant.t import TGate | ||
from bqskit.ir.gates.constant.tdg import TdgGate | ||
from bqskit.ir.gates.constant.unitary import ConstantUnitaryGate | ||
from bqskit.ir.gates.constant.x import XGate | ||
from bqskit.ir.gates.constant.xx import XXGate | ||
from bqskit.ir.gates.constant.xxdg import XXDGGate | ||
from bqskit.ir.gates.constant.y import YGate | ||
from bqskit.ir.gates.constant.yy import YYGate | ||
from bqskit.ir.gates.constant.yydg import YYDGGate | ||
from bqskit.ir.gates.constant.z import ZGate | ||
from bqskit.ir.gates.constant.zz import ZZGate | ||
from bqskit.ir.gates.constant.zzdg import ZZDGGate | ||
|
||
__all__ = [ | ||
'BGate', | ||
|
@@ -51,6 +60,7 @@ | |
'ClockGate', | ||
'CPIGate', | ||
'CSGate', | ||
'CSDGGate', | ||
'CSUMGate', | ||
'CTGate', | ||
'CNOTGate', | ||
|
@@ -60,6 +70,7 @@ | |
'HGate', | ||
'IdentityGate', | ||
'ISwapGate', | ||
'ISwapDGGate', | ||
'IToffoliGate', | ||
'PDGate', | ||
'PermutationGate', | ||
|
@@ -70,19 +81,26 @@ | |
'SdgGate', | ||
'ShiftGate', | ||
'SqrtCNOTGate', | ||
'SqrtCNOTDGGate', | ||
'SqrtISwapGate', | ||
'SqrtISwapDGGate', | ||
'SubSwapGate', | ||
'SwapGate', | ||
'SqrtXGate', | ||
'SXGate', | ||
'SqrtXDGGate', | ||
'SXDGGate', | ||
'SycamoreGate', | ||
'TGate', | ||
'TdgGate', | ||
'ConstantUnitaryGate', | ||
'XGate', | ||
'XXGate', | ||
'XXDGGate', | ||
'YGate', | ||
'YYGate', | ||
'YYDGGate', | ||
'ZGate', | ||
'ZZGate', | ||
'ZZDGGate', | ||
] | ||
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. We also need to add the new gates to the autodoc in If you can automate that, that would be awesome! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""This module implements the CSDGGate.""" | ||
from __future__ import annotations | ||
|
||
from bqskit.ir.gate import Gate | ||
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 import should be under a |
||
from bqskit.ir.gates.constantgate import ConstantGate | ||
from bqskit.ir.gates.qubitgate import QubitGate | ||
from bqskit.qis.unitary.unitarymatrix import UnitaryMatrix | ||
|
||
|
||
class CSDGGate(ConstantGate, QubitGate): | ||
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. What about the CTGate? |
||
""" | ||
The Controlled-S Dagger gate. | ||
|
||
The CS Dagger gate is given by the following unitary: | ||
|
||
.. math:: | ||
|
||
\\begin{pmatrix} | ||
1 & 0 & 0 & 0 \\\\ | ||
0 & 1 & 0 & 0 \\\\ | ||
0 & 0 & 1 & 0 \\\\ | ||
0 & 0 & 0 & -i \\\\ | ||
\\end{pmatrix} | ||
""" | ||
|
||
_num_qudits = 2 | ||
_qasm_name = 'csdg' | ||
_utry = UnitaryMatrix( | ||
[ | ||
[1, 0, 0, 0], | ||
[0, 1, 0, 0], | ||
[0, 0, 1, 0], | ||
[0, 0, 0, -1j], | ||
], | ||
) | ||
|
||
def get_qasm_gate_def(self) -> str: | ||
"""Returns a qasm gate definition block for this gate.""" | ||
return ( | ||
'gate csdg a,b\n' | ||
'{\n' | ||
'\tp(-pi/4) a;\n' | ||
'\tcx a, b;\n' | ||
'\tp(pi/4) b;\n' | ||
'\tcx a, b;\n' | ||
'\tp(-pi/4) b;\n' | ||
'}\n' | ||
) | ||
|
||
def get_inverse(self) -> Gate: | ||
"""Return the inverse of this gate.""" | ||
from bqskit.ir.gates.constant.cs import CSGate | ||
return CSGate() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""This module implements the ISwapDGGate.""" | ||
from __future__ import annotations | ||
|
||
from bqskit.ir.gate import Gate | ||
from bqskit.ir.gates.constantgate import ConstantGate | ||
from bqskit.ir.gates.qubitgate import QubitGate | ||
from bqskit.qis.unitary.unitarymatrix import UnitaryMatrix | ||
|
||
|
||
class ISwapDGGate(ConstantGate, QubitGate): | ||
""" | ||
The two qubit swap and phase iSWAP Dagger gate. | ||
|
||
The ISwap Dagger gate is given by the following unitary: | ||
|
||
.. math:: | ||
|
||
\\begin{pmatrix} | ||
1 & 0 & 0 & 0 \\\\ | ||
0 & 0 & -i & 0 \\\\ | ||
0 & -i & 0 & 0 \\\\ | ||
0 & 0 & 0 & 1 \\\\ | ||
\\end{pmatrix} | ||
""" | ||
|
||
_num_qudits = 2 | ||
_qasm_name = 'iswap_dg' | ||
_utry = UnitaryMatrix( | ||
[ | ||
[1, 0, 0, 0], | ||
[0, 0, -1j, 0], | ||
[0, -1j, 0, 0], | ||
[0, 0, 0, 1], | ||
], | ||
) | ||
|
||
def get_qasm_gate_def(self) -> str: | ||
"""Returns a qasm gate definition block for this gate.""" | ||
"""iswap_dg q0,q1 { h q1; cx q1,q0; cx q0,q1; h q0; sdg q1; sdg q0; }""" | ||
return ( | ||
'gate iswap_dg a,b\n' | ||
'{\n' | ||
'\th b;\n' | ||
'\tcx b, a;\n' | ||
'\tcx a, b;\n' | ||
'\th a;\n' | ||
'\tsdg b;\n' | ||
'\tsdg a;\n' | ||
'}\n' | ||
) | ||
|
||
def get_inverse(self) -> Gate: | ||
"""Return the inverse of this gate.""" | ||
from bqskit.ir.gates.constant.iswap import ISwapGate | ||
return ISwapGate() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""This module implements the SqrtCNOTDGGate.""" | ||
from __future__ import annotations | ||
|
||
from bqskit.ir.gate import Gate | ||
from bqskit.ir.gates.constantgate import ConstantGate | ||
from bqskit.ir.gates.qubitgate import QubitGate | ||
from bqskit.qis.unitary.unitarymatrix import UnitaryMatrix | ||
|
||
|
||
class SqrtCNOTDGGate(ConstantGate, QubitGate): | ||
""" | ||
The Square root Controlled-X gate. | ||
|
||
The SqrtCNOT Dagger gate is given by the following unitary: | ||
|
||
.. math:: | ||
|
||
\\begin{pmatrix} | ||
1 & 0 & 0 & 0 \\\\ | ||
0 & 1 & 0 & 0 \\\\ | ||
0 & 0 & \\frac{1}{2} - \\frac{1}{2}i & \\frac{1}{2} + \\frac{1}{2}i \\\\ | ||
0 & 0 & \\frac{1}{2} + \\frac{1}{2}i & \\frac{1}{2} - \\frac{1}{2}i \\\\ | ||
\\end{pmatrix} | ||
""" | ||
|
||
_num_qudits = 2 | ||
_qasm_name = 'csxdg' | ||
_utry = UnitaryMatrix( | ||
[ | ||
[1, 0, 0, 0], | ||
[0, 1, 0, 0], | ||
[0, 0, 0.5 - 0.5j, 0.5 + 0.5j], | ||
[0, 0, 0.5 + 0.5j, 0.5 - 0.5j], | ||
], | ||
) | ||
|
||
def get_qasm_gate_def(self) -> str: | ||
"""Returns a qasm gate definition block for this gate.""" | ||
"""Gate csxdg q0,q1 { u(0,0,pi/4) q1; cx q0,q1; u(0,0,-pi/4) q1; cx | ||
q0,q1; cu(pi/2,0,pi,0) q0,q1; u(0,0,pi/4) q1; cx q0,q1; u(0,0,-pi/4) q1; | ||
cx q0,q1; p(pi/4) q0; }""" | ||
return ( | ||
'gate csxdg a,b\n' | ||
'{\n' | ||
'\tu(0,0,pi/4) b;\n' | ||
'\tcx a,b;\n' | ||
'\tu(0,0,-pi/4) b;\n' | ||
'\tcx a,b;\n' | ||
'\tcu(pi/2,0,pi,0) a,b;\n' | ||
'\tu(0,0,pi/4) b;\n' | ||
'\tcx a,b;\n' | ||
'\tu(0,0,-pi/4) b;\n' | ||
'\tcx a,b;\n' | ||
'\tp(pi/4) a;\n' | ||
'}\n' | ||
) | ||
|
||
def get_inverse(self) -> Gate: | ||
"""Return the inverse of this gate.""" | ||
from bqskit.ir.gates.constant.sqrtcnot import SqrtCNOTGate | ||
return SqrtCNOTGate() |
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.
We should keep convention and have the
dg
be lower case. This applies everywhere and to all new gates.