def test_exceptions_observable(fermion_ops, mapping, msg_match): """Test that the 'observable' function throws an exception if any element in the list 'fermion_ops' is not a FermionOperator objector or if the fermionic-to-qubit transformation is not properly defined.""" with pytest.raises(TypeError, match=msg_match): qchem.observable(fermion_ops, mapping=mapping)
def test_mapping_observable(message_match="transformation is not available"): """Test that the 'observable' function throws an exception if the fermionic-to-qubit mapping is not properly defined.""" me_table = np.array([[0.0, 0.0, 0.5], [1.0, 1.0, -0.5]]) with pytest.raises(TypeError, match=message_match): qchem.observable(me_table, mapping="no_valid_transformation")
def test_exceptions_observable( me_table, message_match="expected entries of 'me_table' to be of shape"): """Test that the 'observable' function throws an exception if the array containing the matrix elements has incorrect shapes.""" with pytest.raises(ValueError, match=message_match): qchem.observable(me_table)
def test_observable(me_table, init_term, mapping, terms_exp, monkeypatch): r"""Tests the correctness of the 'observable' function used to build many-body observables. The parametrized inputs `terms_exp` are `.terms` attribute of the corresponding `QubitOperator. The equality checking is implemented in the `qchem` module itself as it could be something useful to the users as well. """ res_obs = qchem.observable(me_table, init_term=init_term, mapping=mapping) qubit_op = QubitOperator() monkeypatch.setattr(qubit_op, "terms", terms_exp) assert qchem._qubit_operators_equivalent(qubit_op, res_obs)
def test_build_s2_observable(mol_name, n_act_elect, n_act_orb, mapping, terms_exp, monkeypatch): r"""Tests the correctness of the built total-spin observable. The parametrized inputs are `.terms` attribute of the total spin `QubitOperator. The equality checking is implemented in the `qchem` module itself as it could be something useful to the users as well. """ s2_me_table, init_term = qchem.get_spin2_matrix_elements( mol_name, ref_dir, n_active_electrons=n_act_elect, n_active_orbitals=n_act_orb ) s2_obs = qchem.observable(s2_me_table, init_term=init_term, mapping=mapping) s2_qubit_op = QubitOperator() monkeypatch.setattr(s2_qubit_op, "terms", terms_exp) assert qchem._qubit_operators_equivalent(s2_qubit_op, s2_obs)
def test_exceptions_observable(matrix_elements, msg_match): """Test that the 'observable' function throws an exception if the array containing the matrix elements has incorrect shapes.""" with pytest.raises(ValueError, match=msg_match): qchem.observable(matrix_elements)