def _inverse_angle(gate: qgates.QuantumGate) -> qgates.QuantumGate: return qgates.QuantumGate(gate.name, gate.matrix.T.conj(), _inverse_angle, parameters=-gate.parameters)
return gate def _generic_inverse(gate: qgates.QuantumGate) -> qgates.QuantumGate: name = (gate.name + "+").replace("++", "") return qgates.QuantumGate(name, gate.matrix.T.conj(), _generic_inverse, parameters=gate.parameters) def _inverse_angle(gate: qgates.QuantumGate) -> qgates.QuantumGate: return qgates.QuantumGate(gate.name, gate.matrix.T.conj(), _inverse_angle, parameters=-gate.parameters) X = qgates.QuantumGate("X", mconsts.X, _self_inverse) Y = qgates.QuantumGate("Y", mconsts.Y, _self_inverse) Z = qgates.QuantumGate("Z", mconsts.Z, _self_inverse) H = qgates.QuantumGate("H", mconsts.H, _self_inverse) S = qgates.QuantumGate("S", mconsts.S, _generic_inverse) T = qgates.QuantumGate("T", mconsts.T, _generic_inverse) ID = qgates.QuantumGate("Id", mconsts.ID2, _self_inverse) CX = qgates.QuantumGate("CX", mconsts.CX, _self_inverse) Rx = qgates.ParametrisedQuantumGate("Rx", mconsts.Rx, _inverse_angle) Ry = qgates.ParametrisedQuantumGate("Ry", mconsts.Ry, _inverse_angle) Rz = qgates.ParametrisedQuantumGate("Rz", mconsts.Rz, _inverse_angle)
def _generic_inverse(gate: qgates.QuantumGate) -> qgates.QuantumGate: name = (gate.name + "+").replace("++", "") return qgates.QuantumGate(name, gate.matrix.T.conj(), _generic_inverse, parameters=gate.parameters)
def test_gate_dim(self) -> None: """Test if QuantumGate's dim attribute is right.""" qgate = qgates.QuantumGate("qgate", mconsts.X, lambda X: X) self.assertEqual(qgate.dim, 2)
def test_gate_name(self) -> None: """Test if QuantumGate's name attribute is right.""" qgate = qgates.QuantumGate("qgate", mconsts.X, lambda X: X) self.assertEqual(qgate.name, "qgate")
def test_gate_parameter_empty(self) -> None: """Test if QuantumGate's parameters attribute is right.""" qgate = qgates.QuantumGate("qgate", mconsts.X, lambda X: X) self.assertFalse(qgate.parameters)
def test_gate_matrix(self) -> None: """Test if QuantumGate's matrix attribute is right.""" qgate = qgates.QuantumGate("qgate", mconsts.X, lambda X: X) self.assertAllClose(qgate.matrix, mconsts.X)
def test_creation_gate_no_parameters(self) -> None: """Test if construction of QuantumGate without parameter works.""" qgate = qgates.QuantumGate("qgate", mconsts.X, lambda X: X)