1{ lib
2, stdenv
3, pythonOlder
4, buildPythonPackage
5, fetchFromGitHub
6 # Python requirements
7, cython
8, dill
9, fastjsonschema
10, jsonschema
11, numpy
12, networkx
13, ply
14, psutil
15, python-constraint
16, python-dateutil
17, retworkx
18, scipy
19, scikit-quant ? null
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.18.3";
60
61 disabled = pythonOlder "3.6";
62
63 src = fetchFromGitHub {
64 owner = "Qiskit";
65 repo = pname;
66 rev = version;
67 sha256 = "sha256-w/EnkdlC1hvmLqm4I8ajEYADxqMYGdHKrySLcb/yWGs=";
68 };
69
70 nativeBuildInputs = [ cython ];
71
72 propagatedBuildInputs = [
73 dill
74 fastjsonschema
75 jsonschema
76 numpy
77 networkx
78 ply
79 psutil
80 python-constraint
81 python-dateutil
82 retworkx
83 scipy
84 scikit-quant
85 symengine
86 sympy
87 tweedledum
88 ] ++ lib.optionals withVisualization visualizationPackages
89 ++ lib.optionals withCrosstalkPass crosstalkPackages;
90
91 # *** Tests ***
92 checkInputs = [
93 pytestCheckHook
94 ddt
95 hypothesis
96 nbformat
97 nbconvert
98 ] ++ lib.optionals (!withVisualization) visualizationPackages;
99
100 pythonImportsCheck = [
101 "qiskit"
102 "qiskit.transpiler.passes.routing.cython.stochastic_swap.swap_trial"
103 ];
104
105 disabledTestPaths = [
106 "test/randomized/test_transpiler_equivalence.py" # collection requires qiskit-aer, which would cause circular dependency
107 # These tests are nondeterministic and can randomly fail.
108 # We ignore them here for deterministic building.
109 "test/randomized/"
110 # These tests consistently fail on GitHub Actions build
111 "test/python/quantum_info/operators/test_random.py"
112 ];
113 pytestFlagsArray = [ "--durations=10" ];
114 disabledTests = [
115 # Flaky tests
116 "test_pulse_limits" # Fails on GitHub Actions, probably due to minor floating point arithmetic error.
117 "test_cx_equivalence" # Fails due to flaky test
118 "test_two_qubit_synthesis_not_pulse_optimal" # test of random circuit, seems to randomly fail depending on seed
119 "test_qv_natural" # fails due to sign error. Not sure why
120 ] ++ lib.optionals (lib.versionAtLeast matplotlib.version "3.4.0") [
121 "test_plot_circuit_layout"
122 ]
123 # Disabling slow tests for build constraints
124 ++ [
125 "test_all_examples"
126 "test_controlled_random_unitary"
127 "test_controlled_standard_gates_1"
128 "test_jupyter_jobs_pbars"
129 "test_lookahead_swap_higher_depth_width_is_better"
130 "test_move_measurements"
131 "test_job_monitor"
132 "test_wait_for_final_state"
133 "test_multi_controlled_y_rotation_matrix_basic_mode"
134 "test_two_qubit_weyl_decomposition_abc"
135 "test_isometry"
136 "test_parallel"
137 "test_random_state"
138 "test_random_clifford_valid"
139 "test_to_matrix"
140 "test_block_collection_reduces_1q_gate"
141 "test_multi_controlled_rotation_gate_matrices"
142 "test_block_collection_runs_for_non_cx_bases"
143 "test_with_two_qubit_reduction"
144 "test_basic_aer_qasm"
145 "test_hhl"
146 "test_H2_hamiltonian"
147 "test_max_evals_grouped_2"
148 "test_qaoa_qc_mixer_4"
149 "test_abelian_grouper_random_2"
150 "test_pauli_two_design"
151 "test_shor_factoring"
152 "test_sample_counts_memory_ghz"
153 "test_two_qubit_weyl_decomposition_ab0"
154 "test_sample_counts_memory_superposition"
155 "test_piecewise_polynomial_function"
156 "test_vqe_qasm"
157 ];
158
159 # Moves tests to $PACKAGEDIR/test. They can't be run from /build because of finding
160 # cythonized modules and expecting to find some resource files in the test directory.
161 preCheck = ''
162 export PACKAGEDIR=$out/${python.sitePackages}
163 echo "Moving Qiskit test files to package directory"
164 cp -r $TMP/$sourceRoot/test $PACKAGEDIR
165 cp -r $TMP/$sourceRoot/examples $PACKAGEDIR
166 cp -r $TMP/$sourceRoot/qiskit/schemas/examples $PACKAGEDIR/qiskit/schemas/
167
168 # run pytest from Nix's $out path
169 pushd $PACKAGEDIR
170 '';
171 postCheck = ''
172 rm -r test
173 rm -r examples
174 popd
175 '';
176
177
178 meta = with lib; {
179 description = "Provides the foundations for Qiskit.";
180 longDescription = ''
181 Allows the user to write quantum circuits easily, and takes care of the constraints of real hardware.
182 '';
183 homepage = "https://qiskit.org/terra";
184 downloadPage = "https://github.com/QISKit/qiskit-terra/releases";
185 changelog = "https://qiskit.org/documentation/release_notes.html";
186 license = licenses.asl20;
187 maintainers = with maintainers; [ drewrisinger ];
188 };
189}