CQCL/pytket-pennylane

Test failure on MacOS

Closed this issue · 0 comments

The following errors are observed on the CI on MacOS (though not on other platforms):

pytest --doctest-modules
============================= test session starts ==============================
platform darwin -- Python 3.9.13, pytest-7.1.3, pluggy-1.0.0
rootdir: /Users/runner/work/pytket-pennylane/pytket-pennylane
plugins: flaky-3.7.0, mock-3.8.2
collected 5 items / 1 error

==================================== ERRORS ====================================
________________ ERROR collecting tests/run_pennylane_tests.py _________________
../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests/__init__.py:169: in test_device
    subprocess.run(cmds + pytest_args, check=not interactive)
../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/subprocess.py:528: in run
    raise CalledProcessError(retcode, process.args,
E   subprocess.CalledProcessError: Command '['pytest', '/Users/runner/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests', '--device=pytket.pytketdevice', '--shots=None', '--skip-ops', '--no-flaky-report', '-x', '-s']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:
run_pennylane_tests.py:6: in <module>
    test_device("pytket.pytketdevice", shots=None, pytest_args=["-x", "-s"])
../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests/__init__.py:181: in test_device
    sys.exit(1)
E   SystemExit: 1
------------------------------- Captured stdout --------------------------------
============================= test session starts ==============================
platform darwin -- Python 3.9.13, pytest-7.1.3, pluggy-1.0.0
rootdir: /Users/runner/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests, configfile: pytest.ini
plugins: flaky-3.7.0, mock-3.8.2
collected 372 items

../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests/test_compare_default_qubit.py sssss....
../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests/test_gates.py ....................................................................................................................................................ss..s..............ss..............................................
../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests/test_gates_with_expval.py ..............................................F

=================================== FAILURES ===================================
_ TestGatesQubitExpval.test_supported_gate_two_wires_with_parameters[device_kwargs0-QubitUnitary-par18-expected_output18] _

self = <pennylane.devices.tests.test_gates_with_expval.TestGatesQubitExpval object at 0x11d375940>
device = <function device.<locals>._device at 0x125d19310>
tol = <function tol.<locals>._tol at 0x125d19940>, name = 'QubitUnitary'
par = [array([[ 1.        ,  0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.70710678,  0.70710678,  0.      ...   [ 0.        ,  0.70710678, -0.70710678,  0.        ],
       [ 0.        ,  0.        ,  0.        ,  1.        ]])]
expected_output = [-0.5, -0.5]

    @pytest.mark.parametrize(
        "name,par,expected_output",
        [
            ("CRX", [0], [-1 / 2, -1 / 2]),
            ("CRX", [-pi], [-1 / 2, 1]),
            ("CRX", [pi / 2], [-1 / 2, 1 / 4]),
            ("CRY", [0], [-1 / 2, -1 / 2]),
            ("CRY", [-pi], [-1 / 2, 1]),
            ("CRY", [pi / 2], [-1 / 2, 1 / 4]),
            ("CRZ", [0], [-1 / 2, -1 / 2]),
            ("CRZ", [-pi], [-1 / 2, -1 / 2]),
            ("CRZ", [pi / 2], [-1 / 2, -1 / 2]),
            ("MultiRZ", [0], [-1 / 2, -1 / 2]),
            ("MultiRZ", [-pi], [-1 / 2, -1 / 2]),
            ("MultiRZ", [pi / 2], [-1 / 2, -1 / 2]),
            ("CRot", [pi / 2, 0, 0], [-1 / 2, -1 / 2]),
            ("CRot", [0, pi / 2, 0], [-1 / 2, 1 / 4]),
            ("CRot", [0, 0, pi / 2], [-1 / 2, -1 / 2]),
            ("CRot", [pi / 2, 0, -pi], [-1 / 2, -1 / 2]),
            ("CRot", [0, pi / 2, -pi], [-1 / 2, 1 / 4]),
            ("CRot", [-pi, 0, pi / 2], [-1 / 2, -1 / 2]),
            (
                "QubitUnitary",
                [
                    np.array(
                        [
                            [1, 0, 0, 0],
                            [0, 1 / sqrt(2), 1 / sqrt(2), 0],
                            [0, 1 / sqrt(2), -1 / sqrt(2), 0],
                            [0, 0, 0, 1],
                        ]
                    )
                ],
                [-1 / 2, -1 / 2],
            ),
            (
                "QubitUnitary",
                [
                    np.array(
                        [
                            [-1, 0, 0, 0],
                            [0, 1 / sqrt(2), 1 / sqrt(2), 0],
                            [0, 1 / sqrt(2), -1 / sqrt(2), 0],
                            [0, 0, 0, -1],
                        ]
                    )
                ],
                [-1 / 2, -1 / 2],
            ),
        ],
    )
    def test_supported_gate_two_wires_with_parameters(
        self, device, tol, name, par, expected_output
    ):
        """Tests supported parametrized gates that act on two wires"""
    
        n_wires = 2
        dev = device(n_wires)
        op = getattr(qml.ops, name)
    
        @qml.qnode(dev)
        def circuit():
            qml.QubitStateVector(np.array([1 / 2, 0, 0, sqrt(3) / 2]), wires=[0, 1])
            op(*par, wires=[0, 1])
            return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
    
>       assert np.allclose(circuit(), expected_output, atol=tol(dev.shots))
E       AssertionError: assert False
E        +  where False = <function allclose at 0x1071ab430>(tensor([-0.06525979,  0.06575039], requires_grad=True), [-0.5, -0.5], atol=1e-06)
E        +    where <function allclose at 0x1071ab430> = np.allclose
E        +    and   tensor([-0.06525979,  0.06575039], requires_grad=True) = <QNode: wires=2, device='pytket.pytketdevice', interface='autograd', diff_method='best'>()
E        +    and   1e-06 = <function tol.<locals>._tol at 0x125d19940>(None)
E        +      where None = <PytketDevice device (wires=2, shots=None) at 0x125844400>.shots

../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests/test_gates_with_expval.py:220: AssertionError
=============================== warnings summary ===============================
../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/ops/qubit/non_parametric_ops.py:1962
  /Users/runner/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/ops/qubit/non_parametric_ops.py:1962: UserWarning: The control_wires keyword will be removed soon. Use wires = (control_wires, target_wire) instead. See the documentation for more information.
    warnings.warn(

test_compare_default_qubit.py::TestComparison::test_hermitian_expectation[device_kwargs0]
  /Users/runner/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/qiskit/providers/aer/noise/errors/standard_errors.py:26: DeprecationWarning: Importing from 'qiskit.quantum_info.operators.pauli' is deprecated since Qiskit Terra 0.21 and the module will be removed in a future release.  Import directly from 'qiskit.quantum_info'.
    from qiskit.quantum_info.operators.pauli import Pauli

test_compare_default_qubit.py::TestComparison::test_hermitian_expectation[device_kwargs0]
  /Users/runner/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pytket/extensions/qiskit/backends/aer.py:102: PendingDeprecationWarning: The qiskit.Aer entry point will be deprecated in a future release and subsequently removed. Instead you should use this directly from the root of the qiskit-aer package.
    self._backend: "QiskitAerBackend" = Aer.get_backend(backend_name)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED ../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pennylane/devices/tests/test_gates_with_expval.py::TestGatesQubitExpval::test_supported_gate_two_wires_with_parameters[device_kwargs0-QubitUnitary-par18-expected_output18]
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
============ 1 failed, 260 passed, 10 skipped, 3 warnings in 21.66s ============
=============================== warnings summary ===============================
../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/qiskit/providers/aer/noise/errors/standard_errors.py:26
  /Users/runner/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/qiskit/providers/aer/noise/errors/standard_errors.py:26: DeprecationWarning: Importing from 'qiskit.quantum_info.operators.pauli' is deprecated since Qiskit Terra 0.21 and the module will be removed in a future release.  Import directly from 'qiskit.quantum_info'.
    from qiskit.quantum_info.operators.pauli import Pauli

../../../../hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pytket/extensions/qiskit/backends/aer.py:102
  /Users/runner/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/pytket/extensions/qiskit/backends/aer.py:102: PendingDeprecationWarning: The qiskit.Aer entry point will be deprecated in a future release and subsequently removed. Instead you should use this directly from the root of the qiskit-aer package.
    self._backend: "QiskitAerBackend" = Aer.get_backend(backend_name)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
ERROR run_pennylane_tests.py - SystemExit: 1
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=================== 2 warnings, 1 error in 62.39s (0:01:02) ====================