Skip to content

Commit

Permalink
Add tests for Pauli<->symplectic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chmwzc committed Nov 18, 2024
1 parent c10c471 commit 8d087ee
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/test_measurement_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

0 comments on commit 8d087ee

Please sign in to comment.