From cbccf2dfc7d5ada536d8beef7975881772d73a05 Mon Sep 17 00:00:00 2001 From: Shuli Shu <08cnbj@gmail.com> Date: Tue, 17 Sep 2024 17:42:09 +0000 Subject: [PATCH] apply python layer comments --- .../lightning_tensor/_tensornet.py | 18 ++++++++++-------- .../lightning_tensor/lightning_tensor.py | 5 ++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pennylane_lightning/lightning_tensor/_tensornet.py b/pennylane_lightning/lightning_tensor/_tensornet.py index 5b4a444e09..c91c10570b 100644 --- a/pennylane_lightning/lightning_tensor/_tensornet.py +++ b/pennylane_lightning/lightning_tensor/_tensornet.py @@ -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: # [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: # [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))) 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))) return mpos, sorted_wires @@ -365,12 +365,14 @@ def _apply_lightning(self, operations): method = getattr(tensornet, "applyMatrix") try: method(qml.matrix(operation), wires, False) - 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) - 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) diff --git a/pennylane_lightning/lightning_tensor/lightning_tensor.py b/pennylane_lightning/lightning_tensor/lightning_tensor.py index 60406aadc8..ff53d41ede 100644 --- a/pennylane_lightning/lightning_tensor/lightning_tensor.py +++ b/pennylane_lightning/lightning_tensor/lightning_tensor.py @@ -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):