Пример #1
0
def test_hamiltonian_init():
    with pytest.raises(TypeError):
        H = hamiltonians.Hamiltonian(2, "test")
    H1 = hamiltonians.Hamiltonian(2, np.eye(4))
    H1 = hamiltonians.Hamiltonian(2, np.eye(4))
    H1 = hamiltonians.Hamiltonian(2, K.eye(4))
    H1 = hamiltonians.Hamiltonian(2, K.eye(4))
    with pytest.raises(ValueError):
        H1 = hamiltonians.Hamiltonian(-2, np.eye(4))
    with pytest.raises(RuntimeError):
        H2 = hamiltonians.Hamiltonian(np.eye(2), np.eye(4))
    with pytest.raises(ValueError):
        H3 = hamiltonians.Hamiltonian(4, np.eye(10))
Пример #2
0
 def control_unitary(unitary):
     shape = tuple(unitary.shape)
     if shape != (2, 2):
         raise_error(ValueError, "Cannot use ``control_unitary`` method for "
                                 "input matrix of shape {}.".format(shape))
     zeros = K.zeros((2, 2), dtype='DTYPECPX')
     part1 = K.concatenate([K.eye(2, dtype='DTYPECPX'), zeros], axis=0)
     part2 = K.concatenate([zeros, unitary], axis=0)
     return K.concatenate([part1, part2], axis=1)
Пример #3
0
 def _construct_unitary(self):
     return K.eye(2**len(self.target_qubits))