Skip to content

Commit

Permalink
apply comments on py
Browse files Browse the repository at this point in the history
  • Loading branch information
multiphaseCFD committed Sep 17, 2024
1 parent 9d23871 commit a83e5d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pennylane_lightning/lightning_tensor/_tensornet.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def svd_split(Mat, site_shape, max_bond_dim):
"""SVD decomposition of a matrix via numpy linalg. Note that this function is to be moved to the C++ layer."""
# TODO: Check if cutensornet allows us to remove all zero (or < tol) singular values and the respective rows and columns of U and Vd
U, S, Vd = np.linalg.svd(Mat, full_matrices=False)
U = U @ np.diag(S) # Append singular values to U
U = U * S # Append singular values to U

Check warning on line 38 in pennylane_lightning/lightning_tensor/_tensornet.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L37-L38

Added lines #L37 - L38 were not covered by tests
bonds = len(S)

Vd = Vd.reshape(tuple([bonds] + site_shape + [-1]))
U = U.reshape(tuple([-1] + site_shape + [bonds]))
Vd = Vd.reshape([bonds] + site_shape + [-1])
U = U.reshape([-1] + site_shape + [bonds])

Check warning on line 42 in pennylane_lightning/lightning_tensor/_tensornet.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L41-L42

Added lines #L41 - L42 were not covered by tests

# keep only chi bonds
chi = np.min([bonds, max_bond_dim])
chi = min([bonds, max_bond_dim])
U, Vd = U[..., :chi], Vd[:chi]

Check warning on line 46 in pennylane_lightning/lightning_tensor/_tensornet.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L45-L46

Added lines #L45 - L46 were not covered by tests
return U, Vd

Expand All @@ -57,7 +57,7 @@ def decompose_dense(psi, n_wires, site_shape, max_bond_dim):
psi, site_shape, max_bond_dim
) # psi [site_len, -1] -> U [site_len, mu] Vd [mu, (2x2x2x..)]

Ms[0] = U.reshape(tuple(site_shape + [-1]))
Ms[0] = U.reshape(site_shape + [-1])

Check warning on line 60 in pennylane_lightning/lightning_tensor/_tensornet.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L60

Added line #L60 was not covered by tests
bondL = Vd.shape[0]
psi = Vd

Expand All @@ -71,7 +71,7 @@ def decompose_dense(psi, n_wires, site_shape, max_bond_dim):
psi = Vd
bondL = Vd.shape[0]

Ms[-1] = Vd.reshape(tuple([-1] + site_shape))
Ms[-1] = Vd.reshape([-1] + site_shape)

Check warning on line 74 in pennylane_lightning/lightning_tensor/_tensornet.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L74

Added line #L74 was not covered by tests

return Ms

Expand Down
4 changes: 3 additions & 1 deletion tests/lightning_tensor/test_tensornet_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def test_gate_matrix_decompose():
gate = scipy.linalg.expm(1j * hermitian)
original_gate = gate.copy() # for later to double check

mpos, sorted_wired = gate_matrix_decompose(gate, wires, np.complex128)
max_mpo_bond_dim = 2**len(wires)

mpos, sorted_wired = gate_matrix_decompose(gate, wires, max_mpo_bond_dim, np.complex128)

# restore the C-ordering of the matrices
mpo0 = np.transpose(mpos[0], axes=(2, 1, 0))
Expand Down

0 comments on commit a83e5d7

Please sign in to comment.