Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ stdenv 2, lib 3, pythonOlder 4, buildPythonPackage 5, fetchFromGitHub 6, cargo 7, rustPlatform 8, rustc 9 # Python requirements 10, dill 11, numpy 12, networkx 13, ply 14, psutil 15, python-constraint 16, python-dateutil 17, rustworkx 18, scipy 19, scikit-quant ? null 20, setuptools-rust 21, stevedore 22, symengine 23, sympy 24, tweedledum 25, withVisualization ? false 26 # Python visualization requirements, optional 27, ipywidgets 28, matplotlib 29, pillow 30, pydot 31, pygments 32, pylatexenc 33, seaborn 34 # Crosstalk-adaptive layout pass 35, withCrosstalkPass ? false 36, z3 37 # test requirements 38, ddt 39, hypothesis 40, nbformat 41, nbconvert 42, pytestCheckHook 43, python 44}: 45 46let 47 visualizationPackages = [ 48 ipywidgets 49 matplotlib 50 pillow 51 pydot 52 pygments 53 pylatexenc 54 seaborn 55 ]; 56 crosstalkPackages = [ z3 ]; 57in 58 59buildPythonPackage rec { 60 pname = "qiskit-terra"; 61 version = "0.21.0"; 62 63 disabled = pythonOlder "3.7"; 64 65 src = fetchFromGitHub { 66 owner = "qiskit"; 67 repo = pname; 68 rev = version; 69 hash = "sha256-imktzBpgP+lq6FsVWIUK82+t76gKTgt53kPfKOnsseQ="; 70 }; 71 72 nativeBuildInputs = [ setuptools-rust rustc cargo rustPlatform.cargoSetupHook ]; 73 74 cargoDeps = rustPlatform.fetchCargoTarball { 75 inherit src; 76 name = "${pname}-${version}"; 77 hash = "sha256-SXC0UqWjWqLlZvKCRBylSX73r4Vale130KzS0zM8gjQ="; 78 }; 79 80 propagatedBuildInputs = [ 81 dill 82 numpy 83 networkx 84 ply 85 psutil 86 python-constraint 87 python-dateutil 88 rustworkx 89 scipy 90 scikit-quant 91 stevedore 92 symengine 93 sympy 94 tweedledum 95 ] ++ lib.optionals withVisualization visualizationPackages 96 ++ lib.optionals withCrosstalkPass crosstalkPackages; 97 98 # *** Tests *** 99 nativeCheckInputs = [ 100 pytestCheckHook 101 ddt 102 hypothesis 103 nbformat 104 nbconvert 105 ] ++ lib.optionals (!withVisualization) visualizationPackages; 106 107 pythonImportsCheck = [ 108 "qiskit" 109 "qiskit.pulse" 110 ]; 111 112 disabledTestPaths = [ 113 "test/randomized/test_transpiler_equivalence.py" # collection requires qiskit-aer, which would cause circular dependency 114 # These tests are nondeterministic and can randomly fail. 115 # We ignore them here for deterministic building. 116 "test/randomized/" 117 # These tests consistently fail on GitHub Actions build 118 "test/python/quantum_info/operators/test_random.py" 119 ]; 120 pytestFlagsArray = [ "--durations=10" ]; 121 disabledTests = [ 122 "TestUnitarySynthesisPlugin" # use unittest mocks for transpiler.run(), seems incompatible somehow w/ pytest infrastructure 123 # matplotlib tests seems to fail non-deterministically 124 "TestMatplotlibDrawer" 125 "TestGraphMatplotlibDrawer" 126 "test_copy" # assertNotIn doesn't seem to work as expected w/ pytest vs unittest 127 128 # Flaky tests 129 "test_pulse_limits" # Fails on GitHub Actions, probably due to minor floating point arithmetic error. 130 "test_cx_equivalence" # Fails due to flaky test 131 "test_two_qubit_synthesis_not_pulse_optimal" # test of random circuit, seems to randomly fail depending on seed 132 "test_qv_natural" # fails due to sign error. Not sure why 133 ] ++ lib.optionals (lib.versionAtLeast matplotlib.version "3.4.0") [ 134 "test_plot_circuit_layout" 135 ] 136 # Disabling slow tests for build constraints 137 ++ [ 138 "test_all_examples" 139 "test_controlled_random_unitary" 140 "test_controlled_standard_gates_1" 141 "test_jupyter_jobs_pbars" 142 "test_lookahead_swap_higher_depth_width_is_better" 143 "test_move_measurements" 144 "test_job_monitor" 145 "test_wait_for_final_state" 146 "test_multi_controlled_y_rotation_matrix_basic_mode" 147 "test_two_qubit_weyl_decomposition_abc" 148 "test_isometry" 149 "test_parallel" 150 "test_random_state" 151 "test_random_clifford_valid" 152 "test_to_matrix" 153 "test_block_collection_reduces_1q_gate" 154 "test_multi_controlled_rotation_gate_matrices" 155 "test_block_collection_runs_for_non_cx_bases" 156 "test_with_two_qubit_reduction" 157 "test_basic_aer_qasm" 158 "test_hhl" 159 "test_H2_hamiltonian" 160 "test_max_evals_grouped_2" 161 "test_qaoa_qc_mixer_4" 162 "test_abelian_grouper_random_2" 163 "test_pauli_two_design" 164 "test_shor_factoring" 165 "test_sample_counts_memory_ghz" 166 "test_two_qubit_weyl_decomposition_ab0" 167 "test_sample_counts_memory_superposition" 168 "test_piecewise_polynomial_function" 169 "test_piecewise_chebyshev_mutability" 170 "test_bit_conditional_no_cregbundle" 171 "test_gradient_wrapper2" 172 "test_two_qubit_weyl_decomposition_abmb" 173 "test_two_qubit_weyl_decomposition_abb" 174 "test_vqe_qasm" 175 "test_dag_from_networkx" 176 "test_defaults_to_dict_46" 177 ]; 178 179 # Moves tests to $PACKAGEDIR/test. They can't be run from /build because of finding 180 # cythonized modules and expecting to find some resource files in the test directory. 181 preCheck = '' 182 export PACKAGEDIR=$out/${python.sitePackages} 183 echo "Moving Qiskit test files to package directory" 184 cp -r $TMP/$sourceRoot/test $PACKAGEDIR 185 cp -r $TMP/$sourceRoot/examples $PACKAGEDIR 186 187 # run pytest from Nix's $out path 188 pushd $PACKAGEDIR 189 ''; 190 postCheck = '' 191 rm -r test 192 rm -r examples 193 popd 194 ''; 195 196 197 meta = with lib; { 198 broken = true; # tests segfault python 199 description = "Provides the foundations for Qiskit."; 200 longDescription = '' 201 Allows the user to write quantum circuits easily, and takes care of the constraints of real hardware. 202 ''; 203 homepage = "https://qiskit.org/terra"; 204 downloadPage = "https://github.com/QISKit/qiskit-terra/releases"; 205 changelog = "https://qiskit.org/documentation/release_notes.html"; 206 license = licenses.asl20; 207 maintainers = with maintainers; [ drewrisinger ]; 208 }; 209}