Skip to content

Commit

Permalink
Applying lint, mypy and updating explicit fidelity in test
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloAndresCQ committed Feb 1, 2024
1 parent 6416d5b commit 3f1a946
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 3 additions & 6 deletions pytket/extensions/cutensornet/tnstate/ttn_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions tests/test_tnstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -491,15 +489,15 @@ 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)

# Fixed virtual bond dimension
# 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)

Expand Down

0 comments on commit 3f1a946

Please sign in to comment.