summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/stim/default.nix
blob: 8df37c45ac8efafe15735b462305a5795c1a8112 (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
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,

  # build-system
  pybind11,
  setuptools,

  # dependencies
  numpy,

  # tests
  cirq-core,
  matplotlib,
  networkx,
  pandas,
  pytest-xdist,
  pytestCheckHook,
  scipy,
}:

buildPythonPackage rec {
  pname = "stim";
  version = "1.15.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "quantumlib";
    repo = "Stim";
    tag = "v${version}";
    hash = "sha256-Wls7dJkuV/RXnMizwrYOJOKopWEf1r21FKoKHjmpEQ0=";
  };

  postPatch = ''
    # asked to relax this in https://github.com/quantumlib/Stim/issues/623
    substituteInPlace pyproject.toml \
      --replace-quiet "pybind11~=" "pybind11>="

    # Simple workgroud about https://github.com/networkx/networkx/pull/4829
    # https://github.com/quantumlib/Stim/commit/c0dd0b1c8125b2096cd54b6f72884a459e47fe3e
    substituteInPlace glue/lattice_surgery/stimzx/_zx_graph_solver.py \
      --replace-fail "networkx.testing.assert_graphs_equal" "assert networkx.utils.edges_equal"

    substituteInPlace glue/lattice_surgery/stimzx/_text_diagram_parsing.py \
      --replace-fail "nx.testing.assert_graphs_equal" "assert nx.utils.edges_equal"

    substituteInPlace glue/lattice_surgery/stimzx/_text_diagram_parsing_test.py \
      --replace-fail "nx.testing.assert_graphs_equal" "assert nx.utils.edges_equal"
  '';

  build-system = [
    pybind11
    setuptools
  ];

  dependencies = [ numpy ];

  nativeCheckInputs = [
    cirq-core
    matplotlib
    networkx
    pandas
    pytest-xdist
    pytestCheckHook
    scipy
  ];

  pythonImportsCheck = [ "stim" ];

  enableParallelBuilding = true;

  enabledTestPaths = [
    # From .github/workflows
    "src/"
    "glue/cirq"
  ];

  disabledTests = [
    # AssertionError: Sample rate 1.0 is over 5 standard deviations away from 1.0.
    "test_frame_simulator_sampling_noisy_gates_agrees_with_cirq_data"
    "test_tableau_simulator_sampling_noisy_gates_agrees_with_cirq_data"
  ];

  meta = {
    description = "Tool for high performance simulation and analysis of quantum stabilizer circuits, especially quantum error correction (QEC) circuits";
    mainProgram = "stim";
    homepage = "https://github.com/quantumlib/stim";
    changelog = "https://github.com/quantumlib/Stim/releases/tag/${src.tag}";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ chrispattison ];
  };
}