From e82322dbd09e20317a93be6c7596a8f0b82a68ff Mon Sep 17 00:00:00 2001 From: Pablo Andres-Martinez Date: Wed, 3 Apr 2024 08:51:28 -0700 Subject: [PATCH] Adding a test of copy state using different configurations --- tests/test_structured_state.py | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_structured_state.py b/tests/test_structured_state.py index 6a14a87a..5617ca44 100644 --- a/tests/test_structured_state.py +++ b/tests/test_structured_state.py @@ -51,6 +51,44 @@ def test_init() -> None: assert ttn_gate.is_valid() +@pytest.mark.parametrize( + "algorithm", + [ + SimulationAlgorithm.MPSxGate, + SimulationAlgorithm.MPSxMPO, + SimulationAlgorithm.TTNxGate, + ], +) +def test_copy(algorithm: SimulationAlgorithm) -> None: + simple_circ = Circuit(2).H(0).H(1).CX(0, 1) + + with CuTensorNetHandle() as libhandle: + + # Default config + cfg = Config() + state = simulate(libhandle, simple_circ, algorithm, cfg) + assert state.is_valid() + copy_state = state.copy() + assert copy_state.is_valid() + assert np.isclose(copy_state.vdot(state), 1.0, atol=cfg._atol) + + # Bounded chi + cfg = Config(chi=8) + state = simulate(libhandle, simple_circ, algorithm, cfg) + assert state.is_valid() + copy_state = state.copy() + assert copy_state.is_valid() + assert np.isclose(copy_state.vdot(state), 1.0, atol=cfg._atol) + + # Bounded truncation_fidelity + cfg = Config(truncation_fidelity=0.9999) + state = simulate(libhandle, simple_circ, algorithm, cfg) + assert state.is_valid() + copy_state = state.copy() + assert copy_state.is_valid() + assert np.isclose(copy_state.vdot(state), 1.0, atol=cfg._atol) + + def test_canonicalise_mps() -> None: cp.random.seed(1) circ = Circuit(5)