From 44d49ea4c4622d56b440b61e51d81a00ff006e60 Mon Sep 17 00:00:00 2001 From: Vincent Gierisch Date: Tue, 21 May 2024 02:47:58 +0200 Subject: [PATCH] fix pre-commit test --- bqskit/ir/gates/constant/ecr.py | 20 ++++++++++++++------ tests/ir/gates/constant/test_ecr.py | 6 ++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/bqskit/ir/gates/constant/ecr.py b/bqskit/ir/gates/constant/ecr.py index 03f9efd68..9ad42b56d 100644 --- a/bqskit/ir/gates/constant/ecr.py +++ b/bqskit/ir/gates/constant/ecr.py @@ -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). @@ -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 diff --git a/tests/ir/gates/constant/test_ecr.py b/tests/ir/gates/constant/test_ecr.py index b26003433..5e0fa0d28 100644 --- a/tests/ir/gates/constant/test_ecr.py +++ b/tests/ir/gates/constant/test_ecr.py @@ -10,11 +10,12 @@ 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) @@ -22,12 +23,13 @@ def test_ecr() -> None: 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))