Exemple #1
0
 def test_example(self) -> None:
     circuit = Circuit(2)
     circuit.append_gate(HGate(), [0])
     assert circuit.find_available_cycle([1]) == 0
     circuit.append_gate(XGate(), [0])
     circuit.append_gate(ZGate(), [1])
     assert circuit.find_available_cycle([1]) == 1
Exemple #2
0
 def test_type_invalid_2(self, not_an_location: Sequence[int]) -> None:
     circuit = Circuit(4, [2, 2, 3, 3])
     try:
         circuit.find_available_cycle(not_an_location)
     except TypeError:
         return
     except BaseException:
         assert False, 'Unexpected Exception.'
Exemple #3
0
 def test_type_valid_1(self, location: Sequence[int]) -> None:
     circuit = Circuit(1)
     try:
         circuit.find_available_cycle(location)
     except TypeError:
         assert False, 'Unexpected TypeError.'
     except BaseException:
         return
Exemple #4
0
 def test(self) -> None:
     circuit = Circuit(4, [2, 2, 3, 3])
     circuit.append_gate(CNOTGate(), [0, 1])
     assert circuit.find_available_cycle([2, 3]) == 0
     circuit.append_gate(
         ConstantUnitaryGate(np.identity(36), [2, 2, 3, 3]),
         [0, 1, 2, 3],
     )
     circuit.append_gate(CNOTGate(), [0, 1])
     assert circuit.find_available_cycle([2, 3]) == 2
     circuit.append_gate(
         ConstantUnitaryGate(np.identity(36), [2, 2, 3, 3]),
         [0, 1, 2, 3],
     )
     circuit.append_gate(CPIGate(), [2, 3])
     assert circuit.find_available_cycle([0, 1]) == 4
Exemple #5
0
 def test_return_type(self, location: Sequence[int]) -> None:
     circuit = Circuit(4, [2, 2, 3, 3])
     circuit.append_gate(ConstantUnitaryGate(np.identity(2), [2]), [1])
     circuit.append_gate(
         ConstantUnitaryGate(np.identity(36), [2, 2, 3, 3]),
         [0, 1, 2, 3],
     )
     circuit.append_gate(ConstantUnitaryGate(np.identity(3), [3]), [3])
     assert isinstance(circuit.find_available_cycle(location), int)