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