Beispiel #1
0
 def test_valid(self, size: int, radixes: Sequence[int]) -> None:
     ub = UnitaryBuilder(size, radixes)
     assert ub.get_size() == size
     assert isinstance(ub.get_radixes(), tuple)
     assert len(ub.get_radixes()) == size
     if len(radixes) > 0:
         for radix1, radix2 in zip(radixes, ub.get_radixes()):
             assert radix1 == radix2
     assert ub.get_dim() == int(np.prod(ub.get_radixes()))
     assert np.allclose(
         ub.get_unitary().get_numpy(),
         np.identity(ub.get_dim()),
     )
Beispiel #2
0
    def test_valid_2(self) -> None:
        u1 = UnitaryMatrix.random(3)
        u2 = UnitaryMatrix.random(2)
        ub = UnitaryBuilder(3)

        ub.apply_right(u1, [0, 1, 2])
        assert ub.get_unitary() == u1
        ub.apply_right(u2, [0, 1])
        prod = np.kron(u2.get_numpy(), np.identity(2)) @ u1.get_numpy()
        assert ub.get_unitary() == prod
Beispiel #3
0
    def test_valid_3(self) -> None:
        u1 = UnitaryMatrix.random(3)
        u2 = UnitaryMatrix.random(2)
        ub = UnitaryBuilder(3)

        ub.apply_left(u1, [0, 1, 2])
        assert ub.get_unitary() == u1
        ub.apply_left(u2, [1, 2])
        prod = u1 @ np.kron(np.identity(2), u2.get_numpy())
        assert ub.get_unitary() == prod
Beispiel #4
0
    def test_valid_1(self) -> None:
        u1 = UnitaryMatrix.random(3)
        ub = UnitaryBuilder(3)

        ub.apply_right(u1, [0, 1, 2])
        assert ub.get_unitary() == u1
Beispiel #5
0
 def test_invalid_value_radixes(self, radixes: Sequence[int]) -> None:
     with pytest.raises(TypeError):
         UnitaryBuilder(2, radixes)
Beispiel #6
0
 def test_invalid_value_size(self, size: int) -> None:
     with pytest.raises(ValueError):
         UnitaryBuilder(size)
Beispiel #7
0
 def test_invalid_type_radixes(self, not_a_seq_int: Any) -> None:
     if not_a_seq_int == '':
         return
     with pytest.raises(TypeError):
         UnitaryBuilder(5, not_a_seq_int)
Beispiel #8
0
 def test_invalid_type_size(self, not_an_int: Any) -> None:
     with pytest.raises(TypeError):
         UnitaryBuilder(not_an_int)
Beispiel #9
0
    def test_valid_1(self) -> None:
        u1 = UnitaryMatrix.random(3)
        ub = UnitaryBuilder(3)

        ub.apply_right(u1, [0, 1, 2])
        assert u1 == ub.calc_env_matrix([0, 1, 2])