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