def test_apply_transfer_operator_invalid_direction_raises_error(backend): backend = backend_factory.get_backend(backend) tensor = np.array([[[1., 2., 1.], [1., -2., 1.]], [[-1., 1., -1.], [-1., 1., -1.]], [[1., 2, 3], [3, 2, 1]]], dtype=np.float64) tensors = 6 * [backend.convert_to_tensor(tensor)] mat = backend.convert_to_tensor( np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.float64)) mps = BaseMPS(tensors, backend=backend) with pytest.raises(ValueError): mps.apply_transfer_operator(site=3, direction=0, matrix=mat) with pytest.raises(ValueError): mps.apply_transfer_operator(site=3, direction="keft", matrix=mat)
def test_apply_transfer_operator_right(backend): backend = backend_factory.get_backend(backend) tensor = np.array([[[1., 2., 1.], [1., -2., 1.]], [[-1., 1., -1.], [-1., 1., -1.]], [[1., 2, 3], [3, 2, 1]]], dtype=np.float64) tensors = 6 * [backend.convert_to_tensor(tensor)] mat = backend.convert_to_tensor( np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.float64)) mps = BaseMPS(tensors, backend=backend) expected = np.array([[80., -20., 128.], [-20., 10., -60.], [144., -60., 360.]]) actual = mps.apply_transfer_operator(site=3, direction=-1, matrix=mat) np.testing.assert_allclose(actual, expected) actual = mps.apply_transfer_operator(site=3, direction="r", matrix=mat) np.testing.assert_allclose(actual, expected) actual = mps.apply_transfer_operator(site=3, direction="right", matrix=mat) np.testing.assert_allclose(actual, expected)
def test_apply_transfer_operator_left(backend): backend = backend_factory.get_backend(backend) tensor = np.array([[[1., 2., 1.], [1., -2., 1.]], [[-1., 1., -1.], [-1., 1., -1.]], [[1., 2, 3], [3, 2, 1]]], dtype=np.float64) tensors = 6 * [backend.convert_to_tensor(tensor)] mat = backend.convert_to_tensor( np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.float64)) mps = BaseMPS(tensors, backend=backend) expected = np.array([[74., 58., 38.], [78., 146., 102.], [38., 114., 74.]]) actual = mps.apply_transfer_operator(site=3, direction=1, matrix=mat) np.testing.assert_allclose(actual, expected) actual = mps.apply_transfer_operator(site=3, direction="l", matrix=mat) np.testing.assert_allclose(actual, expected) actual = mps.apply_transfer_operator(site=3, direction="left", matrix=mat) np.testing.assert_allclose(actual, expected)