From 78435b7a67a4c2a4fad84aee419efb74c299ab8f Mon Sep 17 00:00:00 2001 From: Wong Zi Cheng <70616433+chmwzc@users.noreply.github.com> Date: Tue, 9 Apr 2024 04:41:27 +0000 Subject: [PATCH] Rename expectation.py to result.py --- src/qibochem/measurement/__init__.py | 2 +- src/qibochem/measurement/optimization.py | 8 ++++---- src/qibochem/measurement/{expectation.py => result.py} | 0 tests/test_basis_rotation.py | 6 ++---- tests/test_hardware_efficient.py | 2 +- tests/test_hf_circuit.py | 6 +++--- tests/test_molecule.py | 2 +- tests/test_ucc.py | 2 +- 8 files changed, 13 insertions(+), 15 deletions(-) rename src/qibochem/measurement/{expectation.py => result.py} (100%) diff --git a/src/qibochem/measurement/__init__.py b/src/qibochem/measurement/__init__.py index 661f18d..e72e669 100644 --- a/src/qibochem/measurement/__init__.py +++ b/src/qibochem/measurement/__init__.py @@ -1 +1 @@ -from qibochem.measurement.expectation import expectation +from qibochem.measurement.result import expectation diff --git a/src/qibochem/measurement/optimization.py b/src/qibochem/measurement/optimization.py index 7a4ab5c..ac8b432 100644 --- a/src/qibochem/measurement/optimization.py +++ b/src/qibochem/measurement/optimization.py @@ -17,13 +17,13 @@ def check_terms_commutativity(term1, term2, qubitwise=False): """ # Get a list of common qubits for each term common_qubits = sorted( - {_term[1] for _term in term1 if _term[0] != "I"} & {_term[1] for _term in term2 if _term[0] != "I"} + {_term[1:] for _term in term1 if _term[0] != "I"} & {_term[1:] for _term in term2 if _term[0] != "I"} ) if not common_qubits: return True # Get the single Pauli operators for the common qubits for both Pauli terms - term1_ops = [_op for _op in term1 if _op[1] in common_qubits] - term2_ops = [_op for _op in term2 if _op[1] in common_qubits] + term1_ops = [_op for _op in term1 if _op[1:] in common_qubits] + term2_ops = [_op for _op in term2 if _op[1:] in common_qubits] if qubitwise: # Qubitwise: Compare the Pauli terms at the common qubits. Any difference => False return all(_op1 == _op2 for _op1, _op2 in zip(term1_ops, term2_ops)) @@ -61,7 +61,7 @@ def measurement_basis_rotations(hamiltonian, n_qubits, grouping=None): if z_only_terms: result.append(([gates.M(_i) for _i in range(n_qubits)], z_only_terms)) else: - result.append(([], [])) + result.append(([], [])) # No terms with only Z's # Then add the X/Y terms in if xy_terms: if grouping is None: diff --git a/src/qibochem/measurement/expectation.py b/src/qibochem/measurement/result.py similarity index 100% rename from src/qibochem/measurement/expectation.py rename to src/qibochem/measurement/result.py diff --git a/tests/test_basis_rotation.py b/tests/test_basis_rotation.py index 8f4dc8a..49b1a3f 100644 --- a/tests/test_basis_rotation.py +++ b/tests/test_basis_rotation.py @@ -7,10 +7,8 @@ from qibo import Circuit, gates, models from qibochem.ansatz import basis_rotation -from qibochem.driver.molecule import Molecule -from qibochem.measurement.expectation import expectation - -# from qibo.optimizers import optimize +from qibochem.driver import Molecule +from qibochem.measurement import expectation def test_unitary(): diff --git a/tests/test_hardware_efficient.py b/tests/test_hardware_efficient.py index e9ad4c7..56420e6 100644 --- a/tests/test_hardware_efficient.py +++ b/tests/test_hardware_efficient.py @@ -5,7 +5,7 @@ from qibochem.ansatz import he_circuit from qibochem.driver import Molecule -from qibochem.measurement.expectation import expectation +from qibochem.measurement import expectation def test_he_circuit(): diff --git a/tests/test_hf_circuit.py b/tests/test_hf_circuit.py index bd5bbe3..d6cdab0 100644 --- a/tests/test_hf_circuit.py +++ b/tests/test_hf_circuit.py @@ -4,9 +4,9 @@ import pytest -from qibochem.ansatz.hf_reference import hf_circuit -from qibochem.driver.molecule import Molecule -from qibochem.measurement.expectation import expectation +from qibochem.ansatz import hf_circuit +from qibochem.driver import Molecule +from qibochem.measurement import expectation @pytest.mark.parametrize( diff --git a/tests/test_molecule.py b/tests/test_molecule.py index 0b63ace..2fe1aed 100644 --- a/tests/test_molecule.py +++ b/tests/test_molecule.py @@ -12,7 +12,7 @@ from qibo.symbols import Z from qibochem.driver import Molecule -from qibochem.measurement.expectation import expectation +from qibochem.measurement import expectation @pytest.mark.parametrize( diff --git a/tests/test_ucc.py b/tests/test_ucc.py index 56d70e1..d6d6cc7 100644 --- a/tests/test_ucc.py +++ b/tests/test_ucc.py @@ -9,7 +9,7 @@ from qibo import Circuit, gates, symbols from qibo.hamiltonians import SymbolicHamiltonian -from qibochem.ansatz.hf_reference import hf_circuit +from qibochem.ansatz import hf_circuit from qibochem.ansatz.ucc import ( expi_pauli, generate_excitations,