From 3f1a9468aefeb64687aeff3d8fa8fd993732db3a Mon Sep 17 00:00:00 2001 From: Pablo Andres-Martinez Date: Thu, 1 Feb 2024 09:17:11 -0800 Subject: [PATCH] Applying lint, mypy and updating explicit fidelity in test --- pytket/extensions/cutensornet/tnstate/ttn_gate.py | 9 +++------ tests/test_tnstate.py | 8 +++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/pytket/extensions/cutensornet/tnstate/ttn_gate.py b/pytket/extensions/cutensornet/tnstate/ttn_gate.py index 1c4d99fa..5c7d2c85 100644 --- a/pytket/extensions/cutensornet/tnstate/ttn_gate.py +++ b/pytket/extensions/cutensornet/tnstate/ttn_gate.py @@ -26,7 +26,6 @@ warnings.warn("local settings failed to import cutensornet", ImportWarning) from pytket.circuit import Op, Qubit -from .general import Tensor from .ttn import TTN, DirTTN, RootPath @@ -240,7 +239,7 @@ def _apply_2q_gate(self, q0: Qubit, q1: Qubit, gate: Op) -> TTNxGate: # We must push the `msg_tensor` all the way to the common ancestor # of `q0` and `q1`. - bond_addresses = reversed(bonds_to_q0) # From `q0` to the ancestor + bond_addresses = list(reversed(bonds_to_q0)) # From `q0` to the ancestor # For all of these nodes; push `msg_tensor` through to their parent bond for child_bond in bond_addresses[:-1]: # Doesn't do it on common ancestor! @@ -362,14 +361,12 @@ def _apply_2q_gate(self, q0: Qubit, q1: Qubit, gate: Op) -> TTNxGate: if self._cfg.truncation_fidelity < 1: # Truncate as much as possible before violating the truncation fidelity self._fidelity_bound_sequential_weighted_truncation( - reversed(bonds_to_q1), bonds_to_q0 + list(reversed(bonds_to_q1)), bonds_to_q0 ) else: # Truncate so that all bonds have dimension less or equal to chi - self._chi_sequential_truncation( - reversed(bonds_to_q1), bonds_to_q0 - ) + self._chi_sequential_truncation(list(reversed(bonds_to_q1)), bonds_to_q0) return self diff --git a/tests/test_tnstate.py b/tests/test_tnstate.py index 1a71ca45..b8253597 100644 --- a/tests/test_tnstate.py +++ b/tests/test_tnstate.py @@ -401,9 +401,7 @@ def test_float_point_options( # Approximate, bound truncation fidelity cfg = Config( - truncation_fidelity=0.99, - float_precision=fp_precision, - leaf_size=2 + truncation_fidelity=0.99, float_precision=fp_precision, leaf_size=2 ) tnstate = simulate( libhandle, @@ -491,7 +489,7 @@ def test_circ_approx_explicit_ttn(circuit: Circuit) -> None: # Check for TTNxGate cfg = Config(truncation_fidelity=0.99) ttn_gate = simulate(libhandle, circuit, SimulationAlgorithm.TTNxGate, cfg) - assert np.isclose(ttn_gate.get_fidelity(), 0.70, atol=1e-2) + assert np.isclose(ttn_gate.get_fidelity(), 0.729, atol=1e-3) assert ttn_gate.is_valid() assert np.isclose(ttn_gate.vdot(ttn_gate), 1.0, atol=cfg._atol) @@ -499,7 +497,7 @@ def test_circ_approx_explicit_ttn(circuit: Circuit) -> None: # Check for TTNxGate cfg = Config(chi=120, leaf_size=3) ttn_gate = simulate(libhandle, circuit, SimulationAlgorithm.TTNxGate, cfg) - assert np.isclose(ttn_gate.get_fidelity(), 0.84, atol=1e-2) + assert np.isclose(ttn_gate.get_fidelity(), 0.857, atol=1e-3) assert ttn_gate.is_valid() assert np.isclose(ttn_gate.vdot(ttn_gate), 1.0, atol=cfg._atol)