Skip to content

Commit

Permalink
apply python layer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
multiphaseCFD committed Sep 17, 2024
1 parent 160657c commit cbccf2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 10 additions & 8 deletions pennylane_lightning/lightning_tensor/_tensornet.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ def gate_matrix_decompose(gate_ops_matrix, wires, c_dtype):

# Convert the MPOs to the correct order for the cutensornet backend
mpos = []
for i in range(len(MPOs)):
if i == 0:
for index, MPO in enumerate(MPOs):
if index == 0:

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

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L113-L115

Added lines #L113 - L115 were not covered by tests
# [ket, bra, bond](0, 1, 2) -> [ket, bond, bra](0, 2, 1) -> Fortran order or reverse indices(1, 2, 0) to match the order requirement of cutensornet backend.
mpos.append(np.transpose(MPOs[i], axes=(1, 2, 0)))
elif i == len(MPOs) - 1:
mpos.append(np.transpose(MPO, axes=(1, 2, 0)))
elif index == len(MPOs) - 1:

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

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L117-L118

Added lines #L117 - L118 were not covered by tests
# [bond, ket, bra](0, 1, 2) -> Fortran order or reverse indices(2, 1, 0) to match the order requirement of cutensornet backend.
mpos.append(np.transpose(MPOs[i], axes=(2, 1, 0)))
mpos.append(np.transpose(MPO, axes=(2, 1, 0)))

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

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L120

Added line #L120 was not covered by tests
else:
# [bondL, ket, bra, bondR](0, 1, 2, 3) -> [bondL, ket, bondR, bra](0, 1, 3, 2) -> Fortran order or reverse indices(2, 3, 1, 0) to match the requirement of cutensornet backend.
mpos.append(np.transpose(MPOs[i], axes=(2, 3, 1, 0)))
mpos.append(np.transpose(MPO, axes=(2, 3, 1, 0)))

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

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L123

Added line #L123 was not covered by tests

return mpos, sorted_wires

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

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L125

Added line #L125 was not covered by tests

Expand Down Expand Up @@ -365,12 +365,14 @@ def _apply_lightning(self, operations):
method = getattr(tensornet, "applyMatrix")
try:
method(qml.matrix(operation), wires, False)

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

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L365-L367

Added lines #L365 - L367 were not covered by tests
except AttributeError:
except AttributeError: # pragma: no cover
# To support older versions of PL
method(operation.matrix(), wires, False)
else:
try:
gate_ops_matrix = qml.matrix(operation)

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

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L373

Added line #L373 was not covered by tests
except AttributeError:
except AttributeError: # pragma: no cover
# To support older versions of PL
gate_ops_matrix = operation.matrix()

self._apply_MPO(gate_ops_matrix, wires)

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

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_tensor/_tensornet.py#L378

Added line #L378 was not covered by tests
Expand Down
5 changes: 2 additions & 3 deletions pennylane_lightning/lightning_tensor/lightning_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@

def stopping_condition(op: Operator) -> bool:
"""A function that determines whether or not an operation is supported by the ``mps`` method of ``lightning.tensor``."""
# These thresholds are adapted from `lightning_base.py`
# To avoid building matrices beyond the given thresholds.
# This should reduce runtime overheads for larger systems.
# TODOs: These thresholds are from ``lightning.qubit`` and should be adjuested based on the benchmarking tests for the MPS
# simulator (against both max_mps_bond_dim and number of qubits).
if isinstance(op, qml.QFT):
return len(op.wires) < 10
if isinstance(op, qml.GroverOperator):
Expand Down

0 comments on commit cbccf2d

Please sign in to comment.