Skip to content

Commit

Permalink
fix pre-commit test
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentgierisch committed May 21, 2024
1 parent 7ce1a1f commit 44d49ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 14 additions & 6 deletions bqskit/ir/gates/constant/ecr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from bqskit.ir.gates.qubitgate import QubitGate
from bqskit.qis.unitary.unitarymatrix import UnitaryMatrix


class ECRGate(ConstantGate, QubitGate):
"""
The echoed cross-resonance gate (ECR).
Expand All @@ -27,16 +28,23 @@ class ECRGate(ConstantGate, QubitGate):
_num_qudits = 2
_qasm_name = 'ecr'
_utry = UnitaryMatrix([
[0, 0, 1*1/math.sqrt(2), 1j*1/math.sqrt(2)],
[0, 0, 1j*1/math.sqrt(2), 1*1/math.sqrt(2)],
[1*1/math.sqrt(2), -1j*1/math.sqrt(2), 0, 0],
[-1j*1/math.sqrt(2), 1*1/math.sqrt(2), 0, 0],
[0, 0, 1 * 1 / math.sqrt(2), 1j * 1 / math.sqrt(2)],
[0, 0, 1j * 1 / math.sqrt(2), 1 * 1 / math.sqrt(2)],
[1 * 1 / math.sqrt(2), -1j * 1 / math.sqrt(2), 0, 0],
[-1j * 1 / math.sqrt(2), 1 * 1 / math.sqrt(2), 0, 0],
])

def __init__(self) -> None:
pass

def get_qasm_gate_def(self) -> str:
qasm_rzx = 'gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }'
qasm_rzx = (
'gate rzx(param0) q0,q1 {'
'h q1;'
'cx q0,q1;'
'rz(param0) q1;'
'cx q0,q1;'
'h q1; }'
)
qasm_ecr = 'gate ecr q0,q1 { rzx(pi/4) q0,q1; x q0; rzx(-pi/4) q0,q1; }'
return qasm_rzx +'\n' + qasm_ecr
return qasm_rzx + '\n' + qasm_ecr
6 changes: 4 additions & 2 deletions tests/ir/gates/constant/test_ecr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@
from bqskit.ir.gates import XGate
from bqskit.ir.lang.qasm2 import OPENQASM2Language


def test_ecr() -> None:
c = Circuit(2)
c.append_gate(HGate(), 1)
c.append_gate(CXGate(), (0, 1))
c.append_gate(RZGate(), 1, [np.pi/4.0])
c.append_gate(RZGate(), 1, [np.pi / 4.0])
c.append_gate(CXGate(), (0, 1))
c.append_gate(HGate(), 1)

c.append_gate(XGate(), 0)

c.append_gate(HGate(), 1)
c.append_gate(CXGate(), (0, 1))
c.append_gate(RZGate(), 1, [-np.pi/4.0])
c.append_gate(RZGate(), 1, [-np.pi / 4.0])
c.append_gate(CXGate(), (0, 1))
c.append_gate(HGate(), 1)

assert c.get_unitary().get_distance_from(ECRGate().get_unitary()) < 3e-8


def test_ecr_encode_decode() -> None:
c = Circuit(2)
c.append_gate(ECRGate(), (0, 1))
Expand Down

0 comments on commit 44d49ea

Please sign in to comment.