Make test Fatal Python error

Hey there, I’m trying to make my first contribution to the PennyLane source code following the Development Guide. To setup my environment I ran the following:

git clone https://github.com/PennyLaneAI/pennylane
cd pennylane
pip install -e .
pip install -r requirements.txt
pip install flaky
pip install pytest pytest-cov pytest-mock

To ensure everything was working correctly, I ran

make test

which resulted in

tests/circuit_graph/test_qasm.py ....................Fatal Python error: Aborted

Is this a problem with that PennyLane module or with my installation?

Hi @ryanhill1,

Hey there, I’m trying to make my first contribution to the PennyLane source code

Awesome, look forward to seeing it! :slight_smile:

Is this a problem with that PennyLane module or with my installation?

I’ve been able to run the tests in a fresh environment with the same sequence of steps (in Python 3.7), so it’d be good to get some additional information.

  • What OS are you using?
  • What version of Python are you using?
  • In what directory are you running make test?

Could you also please paste any additional error messages or warnings that appear near the test_qasm.py output when it fails? Does it indicate a specific test that causes it to fail?

Thanks!

Thanks for your quick response! I am using,

macOS Big Sur Version 11.2.3
Python 3.8.5

I am running make test in

/Users/ryanhill/Desktop/pennylane

i.e. directly after I cd pennylane. And here is the full output / error message:

(qml) ryanhill@ryans-mbp pennylane % make test
python3 -m pytest tests --tb=native --no-flaky-report
====================================== test session starts =======================================
platform darwin -- Python 3.8.5, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /Users/ryanhill/Desktop/pennylane
plugins: flaky-3.7.0, cov-2.11.1, mock-3.5.1
collected 7537 items / 5 skipped / 7532 selected                                                 

tests/test_about.py ..                                                                     [  0%]
tests/test_classical_gradients.py ...................                                      [  0%]
tests/test_configuration.py .........                                                      [  0%]
tests/test_device.py .........................................ss..........                 [  1%]
tests/test_finite_diff.py ...................                                              [  1%]
tests/test_hermitian_edge_cases.py ....................................................... [  2%]
.............................                                                              [  2%]
tests/test_init.py ....................................................................... [  3%]
............s.s.............s.s.........s.s.............s.s............s..s............s.s [  4%]
.............s.s.........s.s.............s.s............s..s............s.s.............s. [  5%]
s.........s.s.............s.s............s..s............................................. [  6%]
............................................s.s.............s.s.........s.s.............s. [  8%]
s............s..s............s.s.............s.s.........s.s.............s.s............s. [  9%]
.s............s.s.............s.s.........s.s.............s.s............s..s............. [ 10%]
............................................................................s.s........... [ 11%]
..s.s.........s.s.............s.s............s..s............s.s.............s.s.........s [ 12%]
.s.............s.s............s..s............s.s.............s.s.........s.s............. [ 14%]
s.s............s..s....................................................................... [ 15%]
..............                                                                             [ 15%]
tests/test_io.py .......                                                                   [ 15%]
tests/test_measure.py .................................................................... [ 16%]
............................................................                               [ 17%]
tests/test_measurement_transformations.py ......................                           [ 17%]
tests/test_numpy_wrapper.py ...............................................                [ 18%]
tests/test_observable.py .                                                                 [ 18%]
tests/test_operation.py .................................................................. [ 19%]
......s......s............................................................................ [ 20%]
...............................................                                            [ 20%]
tests/test_optimize.py ................................................................... [ 21%]
.......................................................................................... [ 23%]
.................................................................................          [ 24%]
tests/test_optimize_qng.py .....                                                           [ 24%]
tests/test_optimize_shot_adapative.py ..................                                   [ 24%]
tests/test_prob.py ......                                                                  [ 24%]
tests/test_qaoa.py ..........................................                              [ 25%]
tests/test_quantum_gradients.py .......................................................... [ 25%]
.............................................................................              [ 26%]
tests/test_qubit_device.py ............................................................... [ 27%]
..................                                                                         [ 27%]
tests/test_qubit_device_adjoint_jacobian.py .............................................. [ 28%]
............................................................................               [ 29%]
tests/test_queuing.py .........................                                            [ 29%]
tests/test_tensor_measurements.py ........................................................ [ 30%]
....................................................................................       [ 31%]
tests/test_utils.py ...................................................................... [ 32%]
............................................................                               [ 33%]
tests/test_vqe.py ........................................................................ [ 34%]
.......................................................................................... [ 35%]
.......................................................................................... [ 36%]
...........................................s.....s.....s...                                [ 37%]
tests/test_wires.py .....................................................                  [ 38%]
tests/beta/test_default_tensor.py ........................................................ [ 39%]
.......................................................................................... [ 40%]
......................s................................................................... [ 41%]
.......................................................................................... [ 42%]
...............................................................                            [ 43%]
tests/beta/test_default_tensor_tf.py .........................................s.s......... [ 44%]
.....................................................................................      [ 45%]
tests/circuit_drawer/test_circuit_drawer.py ..........................                     [ 45%]
tests/circuit_drawer/test_grid.py .........................................                [ 46%]
tests/circuit_drawer/test_representation_resolver.py ..................................... [ 46%]
.......................................................................................... [ 47%]
.......................................................................................... [ 49%]
.........................................................................                  [ 50%]
tests/circuit_graph/test_circuit_graph.py .........                                        [ 50%]
tests/circuit_graph/test_circuit_graph_hash.py ........................................... [ 50%]
.................................................                                          [ 51%]
tests/circuit_graph/test_qasm.py ....................Fatal Python error: Aborted

Thread 0x000070000f4a5000 (most recent call first):
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/concurrent/futures/thread.py", line 78 in _worker
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 870 in run
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 890 in _bootstrap

Thread 0x000070000e4a2000 (most recent call first):
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/concurrent/futures/thread.py", line 78 in _worker
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 870 in run
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 890 in _bootstrap

Thread 0x000070000d49f000 (most recent call first):
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/concurrent/futures/thread.py", line 78 in _worker
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 870 in run
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 890 in _bootstrap

Thread 0x000070000c49c000 (most recent call first):
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/concurrent/futures/thread.py", line 78 in _worker
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 870 in run
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/threading.py", line 890 in _bootstrap

Thread 0x000070000b499000 (most recent call first):
<no Python frame>

Current thread 0x0000000104a57e00 (most recent call first):
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/qiskit/providers/aer/backends/backend_utils.py", line 51 in cpp_execute
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/qiskit/providers/aer/backends/backend_utils.py", line 65 in available_methods
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/qiskit/providers/aer/backends/qasm_simulator.py", line 284 in __init__
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/qiskit/providers/aer/aerprovider.py", line 33 in __init__
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/qiskit/providers/aer/__init__.py", line 74 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 783 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/qiskit/__init__.py", line 57 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 783 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/outcomes.py", line 208 in importorskip
  File "/Users/ryanhill/Desktop/pennylane/tests/circuit_graph/test_qasm.py", line 679 in check_dependencies
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/fixtures.py", line 932 in call_fixture_func
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/fixtures.py", line 1126 in pytest_fixture_setup
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/fixtures.py", line 1072 in execute
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/fixtures.py", line 687 in _compute_fixture_value
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/fixtures.py", line 601 in _get_active_fixturedef
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/fixtures.py", line 581 in getfixturevalue
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/fixtures.py", line 568 in _fillfixtures
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/python.py", line 1647 in setup
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/runner.py", line 449 in prepare
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/runner.py", line 150 in pytest_runtest_setup
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/runner.py", line 255 in <lambda>
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/runner.py", line 311 in from_call
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/runner.py", line 254 in call_runtest_hook
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/flaky/flaky_pytest_plugin.py", line 138 in call_and_report
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/runner.py", line 120 in runtestprotocol
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/runner.py", line 109 in pytest_runtest_protocol
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/flaky/flaky_pytest_plugin.py", line 94 in pytest_runtest_protocol
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/main.py", line 348 in pytest_runtestloop
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/main.py", line 323 in _main
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/main.py", line 269 in wrap_session
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/main.py", line 316 in pytest_cmdline_main
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/config/__init__.py", line 162 in main
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/_pytest/config/__init__.py", line 185 in console_main
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/site-packages/pytest/__main__.py", line 5 in <module>
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/runpy.py", line 87 in _run_code
  File "/Users/ryanhill/opt/anaconda3/envs/qml/lib/python3.8/runpy.py", line 194 in _run_module_as_main
make: *** [test] Abort trap: 6

Hey @ryanhill1!

In the file tests/circuit_graph/test_qasm.py, we have a test class that tests integration between our QASM conversion and Qiskit:

class TestQASMConformanceTests:
    """Conformance tests to ensure that the CircuitGraph
    serialized QASM conforms to the QASM standard as implemented
    by Qiskit. Note that this test class requires Qiskit and
    PennyLane-Qiskit as a dependency."""

Based on the traceback, it seems to me that this is the test that is failing :thinking: This test is automatically skipped if Qiskit is not found, but run if it is.

Two potential thoughts on solving this:

  1. Could you try upgrading to the latest Qiskit version (if not yet upgraded?)
  2. Could you try installing the latest GitHub master version of the Qiskit plugin (pip install git+https://github.com/PennyLaneAI/pennylane-qiskit.git)?

If this doesn’t work, what might work is to ‘skip’ this particular test class from running:

python -m pytest tests --tb=native --no-flaky-report -k "not TestQASMConformanceTests"

(the -k flag is great, and allows you to pass a boolean string to choose exactly the tests that you want to run :slight_smile: )

Hi @josh , thanks for your response!

I tried your two suggestions with Qiskit and for some reason that still didn’t fix it; I ended up with the same error message. However, “skipping” that test class using the -k flag did work!

Since I’m only adding code to pennylane/devices/default_qubit.py, the only test class I really care about is pennylane/tests/devices/test_default_qubit.py. Is there a way I can use a flag to run only that test? Sorry if that’s a dumb question, my background is in physics so I’m new to software development and still learning commands.

Is there a way I can use a flag to run only that test?

Definitely! If you want to only run a single test file, simply pass the filepath to the file when calling pytest:

python -m pytest tests/devices/test_default_qubit.py --tb=native --no-flaky-report

You can also use this in addition to the -k flag if you only want to run certain test functions or classes from within this file.

1 Like

Resolved the issue! Sorry to bother you.

Glad you got it working @ryanhill1 :slightly_smiling_face: Let us know if you have any other questions!