From 85dd54696776fb06c73cb45879ab9940ab728bfd Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Mon, 9 Mar 2026 11:39:34 +0000 Subject: [PATCH] Fix magnet tests. --- source/pip/qsharp/magnets/trotter/trotter.py | 8 ++++++-- source/pip/tests/magnets/test_trotter.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/pip/qsharp/magnets/trotter/trotter.py b/source/pip/qsharp/magnets/trotter/trotter.py index 20ef8cb845..f7ac8b18f0 100644 --- a/source/pip/qsharp/magnets/trotter/trotter.py +++ b/source/pip/qsharp/magnets/trotter/trotter.py @@ -4,7 +4,7 @@ """Base Trotter class for first- and second-order Trotter-Suzuki decomposition.""" -from typing import Iterator +from typing import Iterator, Optional class TrotterStep: @@ -53,6 +53,7 @@ def __init__(self, num_terms: int = 0, time_step: float = 0.0): self._nterms = num_terms self._time_step = time_step self._order = 1 if num_terms > 0 else 0 + self._repr_string: Optional[str] = None self.terms: list[tuple[float, int]] = [(time_step, j) for j in range(num_terms)] @property @@ -114,7 +115,10 @@ def __str__(self) -> str: def __repr__(self) -> str: """String representation of the Trotter decomposition.""" - return f"TrotterStep(num_terms={self._nterms}, time_step={self._time_step})" + if self._repr_string is not None: + return self._repr_string + else: + return f"TrotterStep(num_terms={self._nterms}, time_step={self._time_step})" def suzuki_recursion(trotter: TrotterStep) -> TrotterStep: diff --git a/source/pip/tests/magnets/test_trotter.py b/source/pip/tests/magnets/test_trotter.py index fb7c72046d..2b2fe22572 100644 --- a/source/pip/tests/magnets/test_trotter.py +++ b/source/pip/tests/magnets/test_trotter.py @@ -429,7 +429,7 @@ def test_trotter_expansion_num_steps_property(): """Test TrotterExpansion num_steps property.""" step = TrotterStep(num_terms=2, time_step=0.25) expansion = TrotterExpansion(step, num_steps=8) - assert expansion.num_steps == 8 + assert expansion.nsteps == 8 def test_trotter_expansion_total_time_property():