quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.28k stars 1.02k forks source link

Increase performance of simulator tests #10

Closed Strilanc closed 6 years ago

Strilanc commented 6 years ago

At the moment, 90% of testing time (~1 minute) is spent in the simulator tests. Making them more performant would save a lot of test time.

dabacon commented 6 years ago

============================================================================================= slowest 100 test durations ============================================================================================= 3.62s call cirq/sim/google/xmon_simulator_test.py::test_initial_state[2] 3.54s call cirq/sim/google/xmon_simulator_test.py::test_large_circuit_unitary[2] 3.43s call cirq/sim/google/xmon_simulator_test.py::test_initial_state[0] 3.40s call cirq/sim/google/xmon_simulator_test.py::test_large_circuit_unitary[0] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_xy_y2[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_phase_z0[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_xy_xy2[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_phase_z2[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_xy_x1[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_xy_x0[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_xy_y0[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_xy_xy0[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_xy_y1[2] 0.91s call cirq/sim/google/xmon_simulator_test.py::test_xy_x2[2] 0.90s call cirq/sim/google/xmon_simulator_test.py::test_phase_z1[2] 0.90s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz01[2-indices3] 0.90s call cirq/sim/google/xmon_simulator_test.py::test_xy_xy1[2] 0.90s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz12[2-indices1] 0.90s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz02[2-indices1] 0.89s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz01[2-indices1] 0.87s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz02[2-indices3] 0.87s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz12[2-indices3] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_multiple_phases[2] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_xy0[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_y2[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_x1[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_y0[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz02[0-indices0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_x0[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_phase_z1[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_y1[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_phase_z0[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_x2[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz12[0-indices2] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_xy1[0] 0.86s call cirq/sim/google/xmon_simulator_test.py::test_xy_xy2[0] 0.85s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz01[0-indices2] 0.85s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz02[0-indices2] 0.85s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz01[0-indices0] 0.85s call cirq/sim/google/xmon_simulator_test.py::test_phase_z2[0] 0.84s call cirq/sim/google/xmon_simulator_test.py::test_phase_cz12[0-indices0] 0.83s call cirq/sim/google/xmon_simulator_test.py::test_multiple_phases[0]

dabacon commented 6 years ago

Going to add a benchmarking tool

dabacon commented 6 years ago

Benchmarks show the xmon simulator is fast and fine. I tracked down the slowness to the multiprocessing Pool close and join when running pytest. There is a way to make the tests faster but I'd like to understand why this is happening in pytest but not with normal python.

dabacon commented 6 years ago

Fixed in #15