aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/development/python-modules/qiskit-aqua/default.nix
blob: 11274c525f0978ab2e3151d8696d8ebecac277a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{ lib
, pythonOlder
, buildPythonPackage
, fetchFromGitHub
, cvxpy
, dlx
, docplex
, fastdtw
, h5py
, networkx
, numpy
, psutil
, python
, qiskit-ignis
, qiskit-terra
, quandl
, scikitlearn
, yfinance
  # Optional inputs
, withTorch ? false
, pytorch
, withPyscf ? false
, pyscf ? null
, withScikitQuant ? false
, scikit-quant ? null
, withCplex ? false
, cplex ? null
  # Check Inputs
, ddt
, pytestCheckHook
, pytest-timeout
, qiskit-aer
}:

buildPythonPackage rec {
  pname = "qiskit-aqua";
  version = "0.8.1";

  disabled = pythonOlder "3.6";

  # Pypi's tarball doesn't contain tests
  src = fetchFromGitHub {
    owner = "Qiskit";
    repo = "qiskit-aqua";
    rev = version;
    sha256 = "11qyya3vyq50wpzrzzl8v46yx5p72rhpqhybwn47qgazxgg82r1b";
  };

  # Optional packages: pyscf (see below NOTE) & pytorch. Can install via pip/nix if needed.
  propagatedBuildInputs = [
    cvxpy
    docplex
    dlx # Python Dancing Links package
    fastdtw
    h5py
    networkx
    numpy
    psutil
    qiskit-terra
    qiskit-ignis
    quandl
    scikitlearn
    yfinance
  ] ++ lib.optionals (withTorch) [ pytorch ]
  ++ lib.optionals (withPyscf) [ pyscf ]
  ++ lib.optionals (withScikitQuant) [ scikit-quant ]
  ++ lib.optionals (withCplex) [ cplex ];

  # *** NOTE ***
  # We make pyscf optional in this package, due to difficulties packaging it in Nix (test failures, complicated flags, etc).
  # See nixpkgs#78772, nixpkgs#83447. You are welcome to try to package it yourself,
  # or use the Nix User Repository version (https://github.com/drewrisinger/nur-packages).
  # It can also be installed at runtime from the pip wheel.
  # We disable appropriate tests below to allow building without pyscf installed

  # NOTE: we remove cplex b/c we can't build pythonPackages.cplex.
  # cplex is only distributed in manylinux1 wheel (no source), and Nix python is not manylinux1 compatible

  postPatch = ''
    substituteInPlace setup.py \
      --replace "pyscf; sys_platform != 'win32'" "" \
      --replace "cplex; python_version >= '3.6' and python_version < '3.8'" ""

    # Add ImportWarning when running qiskit.chemistry (pyscf is a chemistry package) that pyscf is not included
    echo -e "\nimport warnings\ntry: import pyscf;\nexcept ImportError:\n    " \
      "warnings.warn('pyscf is not supported on Nixpkgs so some qiskit features will fail." \
        "You must install it yourself via pip or add it to your environment from the Nix User Repository." \
        "See https://github.com/NixOS/nixpkgs/pull/83447 for details', ImportWarning)\n" \
      >> qiskit/chemistry/__init__.py

    # Add ImportWarning when running qiskit.optimization that cplex (optimization package) is not included
    echo -e "\nimport warnings\ntry: import cplex;\nexcept ImportError:\n    " \
      "warnings.warn('cplex is not supported on Nixpkgs so some qiskit features will fail." \
        "You must install it yourself via pip or add it to your environment from the Nix User Repository." \
        "', ImportWarning)\n" \
      >> qiskit/optimization/__init__.py
  '';

  postInstall = "rm -rf $out/${python.sitePackages}/docs";  # Remove docs dir b/c it can cause conflicts.

  checkInputs = [
    pytestCheckHook
    ddt
    pytest-timeout
    qiskit-aer
  ];
  pythonImportsCheck = [
    "qiskit.aqua"
    "qiskit.aqua.algorithms"
    "qiskit.chemistry"
    "qiskit.finance"
    "qiskit.ml"
    "qiskit.optimization"
  ];
  pytestFlagsArray = [
    "--timeout=30"
    "--durations=10"
  ] ++ lib.optionals (!withPyscf) [
    "--ignore=test/chemistry/test_qeom_ee.py"
    "--ignore=test/chemistry/test_qeom_vqe.py"
    "--ignore=test/chemistry/test_vqe_uccsd_adapt.py"
    "--ignore=test/chemistry/test_bopes_sampler.py"
  ];
  disabledTests = [
    # Disabled due to missing pyscf
    "test_validate" # test/chemistry/test_inputparser.py

    # Online tests
    "test_exchangedata"
    "test_yahoo"

    # Disabling slow tests > 10 seconds
    "TestVQE"
    "TestOOVQE"
    "TestVQC"
    "TestQSVM"
    "TestOptimizerAQGD"
    "test_graph_partition_vqe"
    "TestLookupRotation"
    "_vqe"
    "TestHHL"
    "TestQGAN"
    "test_evaluate_qasm_mode"
    "test_measurement_error_mitigation_auto_refresh"
    "test_wikipedia"
    "test_shor_factoring_1__15___qasm_simulator____3__5__"
    "test_readme_sample"
    "test_ecev"
    "test_expected_value"
    "test_qubo_gas_int_paper_example"
    "test_shor_no_factors_1_5"
    "test_shor_no_factors_2_7"
    "test_evolve_2___suzuki___1__3_"
    "test_delta"
    "test_swaprz"
    "test_deprecated_algo_result"
    "test_unsorted_grouping"
    "test_ad_hoc_data"
    "test_nft"
    "test_oh"
    "test_confidence_intervals_00001"
    "test_eoh"
    "test_qasm_5"
    "test_uccsd_hf"
  ];

  meta = with lib; {
    description = "An extensible library of quantum computing algorithms";
    homepage = "https://github.com/QISKit/qiskit-aqua";
    changelog = "https://qiskit.org/documentation/release_notes.html";
    license = licenses.asl20;
    maintainers = with maintainers; [ drewrisinger ];
  };
}