コード例 #1
0
def test_spin_z(orbitals, mapping, terms_exp, monkeypatch):
    r"""Tests the correctness of the :math:`\hat{S}_z` observable built by the
    function `'spin_z'`.

    The parametrized inputs are `.terms` attribute of the `QubitOperator. The equality
    checking is implemented in the `qchem` module itself as it could be something
    useful to the users as well.
    """

    Sz = qchem.spin_z(orbitals, mapping=mapping)

    Sz_qubit_op = QubitOperator()
    monkeypatch.setattr(Sz_qubit_op, "terms", terms_exp)

    assert qchem._qubit_operators_equivalent(Sz_qubit_op, Sz)
コード例 #2
0
def test_exception_spin_z(orbitals, msg_match):
    """Test that the function `'spin_z'` throws an exception if the
    number of orbitals is less than zero."""

    with pytest.raises(ValueError, match=msg_match):
        qchem.spin_z(orbitals)