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