def test_get_tensor_raises_error(backend): backend = backend_factory.get_backend(backend) tensor1 = np.ones((2, 3, 2), dtype=np.float64) tensor2 = 2 * np.ones((2, 3, 2), dtype=np.float64) tensors = [tensor1, tensor2] mps = BaseMPS(tensors, backend=backend) with pytest.raises(ValueError): mps.get_tensor(site=-1) with pytest.raises(IndexError): mps.get_tensor(site=3)
def test_get_tensor(backend): backend = backend_factory.get_backend(backend) tensor1 = np.ones((2, 3, 2), dtype=np.float64) tensor2 = 2 * np.ones((2, 3, 2), dtype=np.float64) tensors = [tensor1, tensor2] mps = BaseMPS(tensors, backend=backend) np.testing.assert_allclose(mps.get_tensor(0), tensor1) np.testing.assert_allclose(mps.get_tensor(1), tensor2)
def test_get_tensor_connector_matrix(backend): backend = backend_factory.get_backend(backend) tensor1 = np.ones((2, 3, 2), dtype=np.float64) tensor2 = 2 * np.ones((2, 3, 2), dtype=np.float64) connector = backend.convert_to_tensor(np.ones((2, 2), dtype=np.float64)) tensors = [tensor1, tensor2] mps = BaseMPS(tensors, backend=backend, connector_matrix=connector) np.testing.assert_allclose(mps.get_tensor(0), tensor1) np.testing.assert_allclose(mps.get_tensor(1), 2 * tensor2)