From 8d087eec6dc856384a983f5abfa67652d85e6e9f Mon Sep 17 00:00:00 2001 From: Wong Zi Cheng <70616433+chmwzc@users.noreply.github.com> Date: Mon, 18 Nov 2024 02:47:08 +0000 Subject: [PATCH] Add tests for Pauli<->symplectic functions --- tests/test_measurement_util.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/test_measurement_util.py b/tests/test_measurement_util.py index 09bab62..d64c18c 100644 --- a/tests/test_measurement_util.py +++ b/tests/test_measurement_util.py @@ -2,9 +2,15 @@ Test functionality to reduce the measurement cost of running VQE """ +import numpy as np import pytest -from qibochem.measurement.util import check_terms_commutativity, group_commuting_terms +from qibochem.measurement.util import ( + check_terms_commutativity, + group_commuting_terms, + pauli_to_symplectic, + symplectic_to_pauli, +) @pytest.mark.parametrize( @@ -36,3 +42,29 @@ def test_group_commuting_terms(term_list, qwc_expected, gc_expected): assert qwc_result == qwc_expected gc_result = group_commuting_terms(term_list, qubitwise=False) assert gc_result == gc_expected + + +@pytest.mark.parametrize( + # "pauli_string,n_qubits,expected", + "function_args,expected", + [ + ({"pauli_string": ["X0", "Y1", "Z2"], "n_qubits": 4}, np.array([1, 1, 0, 0, 0, 1, 1, 0])), + ({"pauli_string": ["Z1", "X3"], "n_qubits": 4}, np.array([0, 0, 0, 1, 0, 1, 0, 0])), + ({"pauli_string": [], "n_qubits": 4}, np.array([0, 0, 0, 0, 0, 0, 0, 0])), + ], +) +def test_pauli_to_symplectic(function_args, expected): + result = pauli_to_symplectic(**function_args) + assert np.array_equal(result, expected) + + +@pytest.mark.parametrize( + "function_args,expected", + [ + ({"symplectic_vector": np.array([1, 1, 0, 0, 0, 1, 1, 0])}, ["X0", "Y1", "Z2"]), + ({"symplectic_vector": np.array([0, 1, 0, 1, 0, 1, 0, 0])}, ["Y1", "X3"]), + ], +) +def test_symplectic_to_pauli(function_args, expected): + result = symplectic_to_pauli(**function_args) + assert result == expected