1{ lib
2, pythonOlder
3, buildPythonPackage
4, fetchFromGitHub
5 # Python requirements
6, cython
7, dill
8, fastjsonschema
9, jsonschema
10, numpy
11, networkx
12, ply
13, psutil
14, python-constraint
15, python-dateutil
16, retworkx
17, scipy
18, sympy
19, withVisualization ? false
20 # Python visualization requirements, optional
21, ipywidgets
22, matplotlib
23, pillow
24, pydot
25, pygments
26, pylatexenc
27, seaborn
28 # Crosstalk-adaptive layout pass
29, withCrosstalkPass ? false
30, z3
31 # Classical function -> Quantum Circuit compiler
32, withClassicalFunctionCompiler ? true
33, tweedledum
34 # test requirements
35, ddt
36, hypothesis
37, nbformat
38, nbconvert
39, pytestCheckHook
40, python
41}:
42
43let
44 visualizationPackages = [
45 ipywidgets
46 matplotlib
47 pillow
48 pydot
49 pygments
50 pylatexenc
51 seaborn
52 ];
53 crosstalkPackages = [ z3 ];
54 classicalCompilerPackages = [ tweedledum ];
55in
56
57buildPythonPackage rec {
58 pname = "qiskit-terra";
59 version = "0.17.0";
60
61 disabled = pythonOlder "3.6";
62
63 src = fetchFromGitHub {
64 owner = "Qiskit";
65 repo = pname;
66 rev = version;
67 hash = "sha256-LbNbaHAWAVG5YLc9juuwcOlrREBW6OjEl7VPtACfl3I=";
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 sympy
85 ] ++ lib.optionals withVisualization visualizationPackages
86 ++ lib.optionals withCrosstalkPass crosstalkPackages
87 ++ lib.optionals withClassicalFunctionCompiler classicalCompilerPackages;
88
89 # *** Tests ***
90 checkInputs = [
91 pytestCheckHook
92 ddt
93 hypothesis
94 nbformat
95 nbconvert
96 ] ++ lib.optionals (!withVisualization) visualizationPackages;
97
98 pythonImportsCheck = [
99 "qiskit"
100 "qiskit.transpiler.passes.routing.cython.stochastic_swap.swap_trial"
101 ];
102
103 disabledTestPaths = [
104 "test/randomized/test_transpiler_equivalence.py" # collection requires qiskit-aer, which would cause circular dependency
105 ] ++ lib.optionals (!withClassicalFunctionCompiler) [
106 "test/python/classical_function_compiler/"
107 ];
108 disabledTests = [
109 # Flaky tests
110 "test_cx_equivalence"
111 "test_pulse_limits"
112 ] ++ lib.optionals (!withClassicalFunctionCompiler) [
113 "TestPhaseOracle"
114 ]
115 # Disabling slow tests for build constraints
116 ++ [
117 "test_all_examples"
118 "test_controlled_random_unitary"
119 "test_controlled_standard_gates_1"
120 "test_jupyter_jobs_pbars"
121 "test_lookahead_swap_higher_depth_width_is_better"
122 "test_move_measurements"
123 "test_job_monitor"
124 "test_wait_for_final_state"
125 "test_multi_controlled_y_rotation_matrix_basic_mode"
126 "test_two_qubit_weyl_decomposition_abc"
127 "test_isometry"
128 "test_parallel"
129 "test_random_state"
130 "test_random_clifford_valid"
131 "test_to_matrix"
132 "test_block_collection_reduces_1q_gate"
133 "test_multi_controlled_rotation_gate_matrices"
134 "test_block_collection_runs_for_non_cx_bases"
135 "test_with_two_qubit_reduction"
136 "test_basic_aer_qasm"
137 "test_hhl"
138 "test_H2_hamiltonian"
139 "test_max_evals_grouped_2"
140 "test_qaoa_qc_mixer_4"
141 "test_abelian_grouper_random_2"
142 "test_pauli_two_design"
143 ];
144
145 # Moves tests to $PACKAGEDIR/test. They can't be run from /build because of finding
146 # cythonized modules and expecting to find some resource files in the test directory.
147 preCheck = ''
148 export PACKAGEDIR=$out/${python.sitePackages}
149 echo "Moving Qiskit test files to package directory"
150 cp -r $TMP/$sourceRoot/test $PACKAGEDIR
151 cp -r $TMP/$sourceRoot/examples $PACKAGEDIR
152 cp -r $TMP/$sourceRoot/qiskit/schemas/examples $PACKAGEDIR/qiskit/schemas/
153
154 # run pytest from Nix's $out path
155 pushd $PACKAGEDIR
156 '';
157 postCheck = ''
158 rm -rf test
159 rm -rf examples
160 popd
161 '';
162
163
164 meta = with lib; {
165 description = "Provides the foundations for Qiskit.";
166 longDescription = ''
167 Allows the user to write quantum circuits easily, and takes care of the constraints of real hardware.
168 '';
169 homepage = "https://qiskit.org/terra";
170 downloadPage = "https://github.com/QISKit/qiskit-terra/releases";
171 changelog = "https://qiskit.org/documentation/release_notes.html";
172 license = licenses.asl20;
173 maintainers = with maintainers; [ drewrisinger ];
174 };
175}