Пример #1
0
def _inverse_angle(gate: qgates.QuantumGate) -> qgates.QuantumGate:
    return qgates.QuantumGate(gate.name,
                              gate.matrix.T.conj(),
                              _inverse_angle,
                              parameters=-gate.parameters)
Пример #2
0
    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)
Пример #3
0
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)
Пример #4
0
 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)
Пример #5
0
 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")
Пример #6
0
 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)
Пример #7
0
 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)
Пример #8
0
 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)