ket-lang 0.10.4.3.dev2__tar.gz → 0.10.4.3.dev3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/PKG-INFO +18 -3
  2. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/README.md +17 -2
  3. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/pyproject.toml +2 -5
  4. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/pyproject.toml.orig +5 -4
  5. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/base/__init__.py +19 -4
  6. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/kbw.py +17 -2
  7. ket_lang-0.10.4.3.dev3/src/ket/clib/libs/__init__.py +101 -0
  8. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/.gitlab-ci.yml +121 -49
  9. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/build.rs +1 -1
  10. ket_lang-0.10.4.3.dev3/src/ket/clib/libs/kbw/src/bitwise.rs +40 -0
  11. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/c_api.rs +18 -3
  12. ket_lang-0.10.4.3.dev3/src/ket/clib/libs/kbw/src/equivalence_tests.rs +499 -0
  13. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/lib.rs +32 -7
  14. ket_lang-0.10.4.3.dev3/src/ket/clib/libs/kbw/src/sparse.rs +477 -0
  15. ket_lang-0.10.4.3.dev3/src/ket/clib/libs/kbw/src/sparse_frame.rs +486 -0
  16. ket_lang-0.10.4.3.dev3/src/ket/clib/libs/kbw/src/sparse_gpu/kernel.rs +603 -0
  17. ket_lang-0.10.4.3.dev3/src/ket/clib/libs/kbw/src/sparse_gpu/mod.rs +826 -0
  18. ket_lang-0.10.4.3.dev3/src/ket/clib/libs/kbw/src/sparse_v2.rs +712 -0
  19. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/qulib/__init__.py +18 -6
  20. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/qulib/qubo.py +1 -3
  21. ket_lang-0.10.4.3.dev2/src/ket/clib/libs/__init__.py +0 -45
  22. ket_lang-0.10.4.3.dev2/src/ket/clib/libs/kbw/src/bitwise.rs +0 -69
  23. ket_lang-0.10.4.3.dev2/src/ket/clib/libs/kbw/src/equivalence_tests.rs +0 -204
  24. ket_lang-0.10.4.3.dev2/src/ket/clib/libs/kbw/src/sparse.rs +0 -475
  25. ket_lang-0.10.4.3.dev2/src/ket/clib/libs/kbw/src/sparse_v2.rs +0 -334
  26. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/LICENSE +0 -0
  27. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/__init__.py +0 -0
  28. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/_shared_control.py +0 -0
  29. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/_verification.py +0 -0
  30. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/amazon.py +0 -0
  31. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/base/qasm.py +0 -0
  32. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/base/quant.py +0 -0
  33. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/__init__.py +0 -0
  34. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libket/__init__.py +0 -0
  35. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libket/execution.py +0 -0
  36. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/.git +0 -0
  37. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/.gitignore +0 -0
  38. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/.pre-commit-config.yaml +0 -0
  39. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/CHANGELOG.md +0 -0
  40. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/Cargo.toml +0 -0
  41. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/LICENSE +0 -0
  42. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/LICENSES/Apache-2.0.txt +0 -0
  43. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/README.md +0 -0
  44. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/REUSE.toml +0 -0
  45. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/cbindgen.toml +0 -0
  46. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/examples/grover_batch.rs +0 -0
  47. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/examples/grover_live.rs +0 -0
  48. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/examples/grover_live_dv2.rs +0 -0
  49. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/kbw.h +0 -0
  50. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/block.rs +0 -0
  51. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/convert.rs +0 -0
  52. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/dense.rs +0 -0
  53. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/dense_gpu/kernel.rs +0 -0
  54. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/dense_gpu/mod.rs +0 -0
  55. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/dense_gpu/tuning.rs +0 -0
  56. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/dense_v2.rs +0 -0
  57. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/pauli.rs +0 -0
  58. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/quantum_execution.rs +0 -0
  59. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/kbw/src/sampling.rs +0 -0
  60. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/.git +0 -0
  61. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/.gitignore +0 -0
  62. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/.gitlab-ci.yml +0 -0
  63. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/.pre-commit-config.yaml +0 -0
  64. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/CHANGELOG.md +0 -0
  65. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/Cargo.toml +0 -0
  66. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/LICENSE +0 -0
  67. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/LICENSES/Apache-2.0.txt +0 -0
  68. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/README.md +0 -0
  69. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/REUSE.toml +0 -0
  70. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/build.rs +0 -0
  71. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/cbindgen.toml +0 -0
  72. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/examples/grover.rs +0 -0
  73. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/examples/qft.rs +0 -0
  74. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/libket.h +0 -0
  75. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/annealing.rs +0 -0
  76. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/c_api/annealing.rs +0 -0
  77. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/c_api/block.rs +0 -0
  78. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/c_api/execute.rs +0 -0
  79. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/c_api/mod.rs +0 -0
  80. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/c_api/process.rs +0 -0
  81. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/mod.rs +0 -0
  82. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/network.rs +0 -0
  83. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/su2.rs +0 -0
  84. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/u2.rs +0 -0
  85. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/util.rs +0 -0
  86. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/x/c2to4x.rs +0 -0
  87. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/x/mod.rs +0 -0
  88. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/x/single_aux.rs +0 -0
  89. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/decompose/x/v_chain.rs +0 -0
  90. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/error.rs +0 -0
  91. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/execution.rs +0 -0
  92. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/ir/block.rs +0 -0
  93. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/ir/gate.rs +0 -0
  94. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/ir/hamiltonian.rs +0 -0
  95. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/ir/macros.rs +0 -0
  96. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/ir/mod.rs +0 -0
  97. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/lib.rs +0 -0
  98. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/mapping/allocation.rs +0 -0
  99. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/mapping/dynamic_look_ahead.rs +0 -0
  100. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/mapping/graph.rs +0 -0
  101. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/mapping/mod.rs +0 -0
  102. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/matrix.rs +0 -0
  103. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/process/classical_shadow.rs +0 -0
  104. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/process/known_zero.rs +0 -0
  105. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/process/mod.rs +0 -0
  106. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/process/qwc.rs +0 -0
  107. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/qasm/ast.rs +0 -0
  108. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/qasm/executor.rs +0 -0
  109. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/qasm/gates.rs +0 -0
  110. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/qasm/mod.rs +0 -0
  111. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/qasm/openqasm.lalrpop +0 -0
  112. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/libs/libket/src/tests.rs +0 -0
  113. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/clib/wrapper.py +0 -0
  114. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/expv.py +0 -0
  115. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/fermion.py +0 -0
  116. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/gates.py +0 -0
  117. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/gateset.py +0 -0
  118. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/ibm.py +0 -0
  119. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/measurement.py +0 -0
  120. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/mps.py +0 -0
  121. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/npsim.py +0 -0
  122. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/operations.py +0 -0
  123. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/qint.py +0 -0
  124. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/quantumstate.py +0 -0
  125. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/qulib/gates.py +0 -0
  126. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/qulib/ham.py +0 -0
  127. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/qulib/oracle.py +0 -0
  128. {ket_lang-0.10.4.3.dev2 → ket_lang-0.10.4.3.dev3}/src/ket/qulib/prepare.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ket-lang
3
- Version: 0.10.4.3.dev2
3
+ Version: 0.10.4.3.dev3
4
4
  Summary: Ket quantum programming language interpreter and library
5
5
  Keywords: quantum computer,quantum programming,quantum simulator
6
6
  Author: Evandro Chagas Ribeiro da Rosa
@@ -156,14 +156,29 @@ To get started with Ket development, follow these steps:
156
156
  git clone --recursive https://gitlab.com/quantum-ket/ket.git
157
157
  cd ket
158
158
 
159
- cargo build -F c_api --manifest-path src/ket/clib/libs/libket/Cargo.toml
159
+ cargo build --manifest-path src/ket/clib/libs/libket/Cargo.toml
160
160
  cargo build --manifest-path src/ket/clib/libs/kbw/Cargo.toml
161
161
 
162
- # Create symlinks from within the libs directory
162
+ # Link the libraries into the libs directory (paths are relative to it)
163
163
  ln -s libket/target/debug/libket.so src/ket/clib/libs/libket.so
164
164
  ln -s kbw/target/debug/libkbw.so src/ket/clib/libs/libkbw.so
165
165
  ```
166
166
 
167
+ The GPU simulators (`"dense gpu"`, `"sparse gpu"`) and the CUDA simulators (`"dense cuda"`, `"sparse cuda"`) need KBW built with the `gpu` and `cuda` features (Linux with glibc 2.34 or newer):
168
+
169
+ ```shell
170
+ cargo build -F gpu,cuda --manifest-path src/ket/clib/libs/kbw/Cargo.toml
171
+ ```
172
+
173
+ If the libraries are missing, importing `ket` compiles them in release mode (see `ket.clib.libs.make_libs`). On Linux with glibc 2.34 or newer, KBW is then built with the `gpu` and `cuda` features. Set these environment variables to change that:
174
+
175
+ | Variable | Effect |
176
+ | ---------------- | ------------------------------------------------------- |
177
+ | `KET_BUILD_GPU` | `1` builds KBW with the `gpu` feature, `0` without it. |
178
+ | `KET_BUILD_CUDA` | `1` builds KBW with the `cuda` feature, `0` without it. |
179
+
180
+ For example, with `KET_BUILD_CUDA=0` set, the first `import ket` builds the GPU simulators but not the CUDA ones. The variables only take effect when the libraries are built: delete `libket.so` and `libkbw.so` from `src/ket/clib/libs/` to rebuild them.
181
+
167
182
  3. **Set Up Virtual Environment**
168
183
 
169
184
  Set up a virtual environment for Python:
@@ -114,14 +114,29 @@ To get started with Ket development, follow these steps:
114
114
  git clone --recursive https://gitlab.com/quantum-ket/ket.git
115
115
  cd ket
116
116
 
117
- cargo build -F c_api --manifest-path src/ket/clib/libs/libket/Cargo.toml
117
+ cargo build --manifest-path src/ket/clib/libs/libket/Cargo.toml
118
118
  cargo build --manifest-path src/ket/clib/libs/kbw/Cargo.toml
119
119
 
120
- # Create symlinks from within the libs directory
120
+ # Link the libraries into the libs directory (paths are relative to it)
121
121
  ln -s libket/target/debug/libket.so src/ket/clib/libs/libket.so
122
122
  ln -s kbw/target/debug/libkbw.so src/ket/clib/libs/libkbw.so
123
123
  ```
124
124
 
125
+ The GPU simulators (`"dense gpu"`, `"sparse gpu"`) and the CUDA simulators (`"dense cuda"`, `"sparse cuda"`) need KBW built with the `gpu` and `cuda` features (Linux with glibc 2.34 or newer):
126
+
127
+ ```shell
128
+ cargo build -F gpu,cuda --manifest-path src/ket/clib/libs/kbw/Cargo.toml
129
+ ```
130
+
131
+ If the libraries are missing, importing `ket` compiles them in release mode (see `ket.clib.libs.make_libs`). On Linux with glibc 2.34 or newer, KBW is then built with the `gpu` and `cuda` features. Set these environment variables to change that:
132
+
133
+ | Variable | Effect |
134
+ | ---------------- | ------------------------------------------------------- |
135
+ | `KET_BUILD_GPU` | `1` builds KBW with the `gpu` feature, `0` without it. |
136
+ | `KET_BUILD_CUDA` | `1` builds KBW with the `cuda` feature, `0` without it. |
137
+
138
+ For example, with `KET_BUILD_CUDA=0` set, the first `import ket` builds the GPU simulators but not the CUDA ones. The variables only take effect when the libraries are built: delete `libket.so` and `libkbw.so` from `src/ket/clib/libs/` to rebuild them.
139
+
125
140
  3. **Set Up Virtual Environment**
126
141
 
127
142
  Set up a virtual environment for Python:
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "ket-lang"
7
- version = "0.10.4.3.dev2"
7
+ version = "0.10.4.3.dev3"
8
8
  description = "Ket quantum programming language interpreter and library"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -62,10 +62,7 @@ mps = [
62
62
  [tool.uv.build-backend]
63
63
  module-name = "ket"
64
64
  module-root = "src"
65
- wheel-exclude = [
66
- "ket/clib/libs/kbw",
67
- "ket/clib/libs/libket",
68
- ]
65
+ wheel-exclude = ["target"]
69
66
  source-exclude = ["target"]
70
67
 
71
68
  [tool.pytest.ini_options]
@@ -9,7 +9,7 @@ build-backend = "uv_build"
9
9
 
10
10
  [project]
11
11
  name = "ket-lang"
12
- version = "0.10.4.3.dev2"
12
+ version = "0.10.4.3.dev3"
13
13
  description = "Ket quantum programming language interpreter and library"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.10"
@@ -49,9 +49,10 @@ mps = ["quimb", "jax", "jaxlib", "cotengra"]
49
49
  [tool.uv.build-backend]
50
50
  module-name = "ket"
51
51
  module-root = "src"
52
- # The libkbw/libket binaries in src/ket/clib/libs are shipped; the Rust
53
- # submodules next to them are build inputs only.
54
- wheel-exclude = ["ket/clib/libs/kbw", "ket/clib/libs/libket"]
52
+ # The Rust sources in src/ket/clib/libs are shipped too: a wheel built from
53
+ # the sdist has no binaries, and `ket.clib.libs.make_libs` compiles them on
54
+ # the first import. Build outputs are left out.
55
+ wheel-exclude = ["target"]
55
56
  source-exclude = ["target"]
56
57
 
57
58
  [tool.pytest.ini_options]
@@ -103,16 +103,21 @@ class Process(LibketProcess): # pylint: disable=too-many-instance-attributes
103
103
 
104
104
  :Simulators:
105
105
 
106
- KBW provides four simulators with different performance characteristics.
106
+ KBW provides several simulators with different performance characteristics.
107
107
  The best simulator to use depends on the number of qubits being simulated
108
108
  and on the specific quantum algorithm. Benchmarking is recommended to
109
109
  determine the most suitable simulator for a given workload.
110
110
 
111
- - ``"sparse"``: Sparse simulator with limited multithreading capabilities.
111
+ - ``"sparse"``: Sparse simulator: stores only the basis states with nonzero
112
+ amplitude, in a sorted array. Best when few states are nonzero, as in
113
+ one-hot encodings.
114
+ - ``"sparse gpu"``: The ``"sparse"`` algorithm on most GPUs.
115
+ - ``"sparse cuda"``: The ``"sparse"`` algorithm on NVIDIA GPUs, using CUDA.
112
116
  - ``"dense"``: Dense simulator with good multithreaded performance.
113
117
  - ``"dense gpu"``: Dense simulator designed to run on most GPUs, including
114
118
  integrated Intel, AMD, and Apple GPUs, as well as NVIDIA GPUs. This simulator
115
119
  is generally recommended for simulations involving a large number of qubits.
120
+ - ``"dense cuda"``: Dense simulator on NVIDIA GPUs, using CUDA.
116
121
 
117
122
 
118
123
  Args:
@@ -121,7 +126,8 @@ class Process(LibketProcess): # pylint: disable=too-many-instance-attributes
121
126
  num_qubits: Number of qubits for the KBW simulator.
122
127
  Defaults to 32 for sparse mode, or 12 for dense mode.
123
128
  simulator: Simulation mode for the KBW simulator. Options are
124
- ``"sparse"``, ``"dense"``, and ``"dense gpu"``.
129
+ ``"sparse"``, ``"sparse gpu"``, ``"sparse cuda"``, ``"dense"``,
130
+ ``"dense gpu"``, and ``"dense cuda"``.
125
131
  Defaults to ``"sparse"``.
126
132
  execution: Execution mode for the KBW simulator, either ``"live"`` or ``"batch"``.
127
133
  Defaults to ``"live"``.
@@ -131,7 +137,16 @@ class Process(LibketProcess): # pylint: disable=too-many-instance-attributes
131
137
  self,
132
138
  execution_target: BatchExecution | LiveExecution | None = None,
133
139
  num_qubits: Optional[int] = None,
134
- simulator: Optional[Literal["sparse", "dense", "dense gpu"]] = None,
140
+ simulator: Optional[
141
+ Literal[
142
+ "sparse",
143
+ "sparse gpu",
144
+ "sparse cuda",
145
+ "dense",
146
+ "dense gpu",
147
+ "dense cuda",
148
+ ]
149
+ ] = None,
135
150
  execution: Optional[Literal["live", "batch"]] = None,
136
151
  gradient: bool = False,
137
152
  **kwargs,
@@ -57,11 +57,15 @@ def get_simulator( # pylint: disable=too-many-arguments,too-many-positional-arg
57
57
  execution: Literal["live", "batch"] = "live",
58
58
  simulator: Literal[
59
59
  "sparse",
60
+ "sparse v1",
60
61
  "sparse v2",
62
+ "sparse gpu",
63
+ "sparse cuda",
61
64
  "dense",
62
65
  "dense v1",
63
66
  "dense v2",
64
67
  "dense gpu",
68
+ "dense cuda",
65
69
  ] = "dense",
66
70
  coupling_graph: list[tuple[int, int]] | None = None,
67
71
  gradient: bool = False,
@@ -76,8 +80,16 @@ def get_simulator( # pylint: disable=too-many-arguments,too-many-positional-arg
76
80
  Defaults to ``"live"``.
77
81
  simulator: Simulator backend to use. Available options:
78
82
 
79
- - ``"sparse"``: Sparse state-vector simulator.
80
- - ``"sparse v2"``: Updated sparse simulator variant.
83
+ - ``"sparse"``: Sparse state-vector simulator: stores only the
84
+ basis states with nonzero amplitude, in a sorted array. Same as
85
+ ``"sparse v2"``.
86
+ - ``"sparse v1"``: Previous sparse simulator (sharded hash map).
87
+ - ``"sparse gpu"``: The ``"sparse"`` algorithm on most GPUs.
88
+ Needs a build of KBW with GPU support.
89
+ - ``"sparse cuda"``: The ``"sparse"`` algorithm on NVIDIA GPUs,
90
+ using CUDA. Needs a build of KBW with CUDA support; the
91
+ ``KBW_CUDA_DEVICE`` environment variable selects the GPU
92
+ (default ``0``).
81
93
  - ``"dense"``: Dense state-vector simulator with good multithreaded
82
94
  performance. This is the default.
83
95
  - ``"dense v1"``: Previous dense simulator variant.
@@ -87,6 +99,9 @@ def get_simulator( # pylint: disable=too-many-arguments,too-many-positional-arg
87
99
  states are split into blocks to keep gates inside the GPU
88
100
  caches; the block size is tuned for the device on first use
89
101
  (about two seconds) and stored, see :func:`tune_gpu_block_size`.
102
+ - ``"dense cuda"``: Dense simulator on NVIDIA GPUs, using CUDA.
103
+ Needs a build of KBW with CUDA support; the ``KBW_CUDA_DEVICE``
104
+ environment variable selects the GPU (default ``0``).
90
105
 
91
106
  coupling_graph: Optional list of ``(control, target)`` qubit pairs
92
107
  describing the hardware connectivity. When provided, the compiler
@@ -0,0 +1,101 @@
1
+ # SPDX-FileCopyrightText: 2020 Evandro Chagas Ribeiro da Rosa <evandro@quantuloop.com>
2
+ # SPDX-FileCopyrightText: 2020 Rafael de Santiago <r.santiago@ufsc.br>
3
+ #
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ """C Libs"""
7
+
8
+ import os
9
+ import platform
10
+ import shutil
11
+ import subprocess
12
+ import warnings
13
+
14
+ _TRUE = {"1", "true", "yes", "on"}
15
+ _FALSE = {"0", "false", "no", "off"}
16
+
17
+ # KBW features and the environment variables that enable or disable them.
18
+ _KBW_FEATURES = (("gpu", "KET_BUILD_GPU"), ("cuda", "KET_BUILD_CUDA"))
19
+
20
+
21
+ def libs():
22
+ """Name Rust libs"""
23
+ if os.name == "nt":
24
+ return [("libket", "ket.dll"), ("kbw", "kbw.dll")]
25
+ if os.uname().sysname == "Linux":
26
+ return [("libket", "libket.so"), ("kbw", "libkbw.so")]
27
+ if os.uname().sysname == "Darwin":
28
+ return [("libket", "libket.dylib"), ("kbw", "libkbw.dylib")]
29
+ raise OSError("unsupported operational system")
30
+
31
+
32
+ def _glibc_version() -> tuple[int, int] | None:
33
+ """The glibc version on Linux, or ``None`` (other systems or libcs)."""
34
+ if platform.system() != "Linux":
35
+ return None
36
+ name, version = platform.libc_ver()
37
+ if name != "glibc" or not version:
38
+ return None
39
+ try:
40
+ major, minor = version.split(".")[:2]
41
+ return int(major), int(minor)
42
+ except ValueError:
43
+ return None
44
+
45
+
46
+ def _env_flag(name: str, default: bool) -> bool:
47
+ """Reads a boolean environment variable; unset or empty gives ``default``."""
48
+ value = os.environ.get(name, "").strip().lower()
49
+ if not value:
50
+ return default
51
+ if value in _TRUE:
52
+ return True
53
+ if value in _FALSE:
54
+ return False
55
+ raise ValueError(f"{name} must be 1 or 0, got {os.environ[name]!r}")
56
+
57
+
58
+ def kbw_features() -> list[str]:
59
+ """Cargo features to build KBW with.
60
+
61
+ The ``gpu`` (``"dense gpu"`` and ``"sparse gpu"`` simulators) and ``cuda``
62
+ (``"dense cuda"`` and ``"sparse cuda"``) features are enabled by default
63
+ on Linux with glibc 2.34 or newer, as in the released wheels. The
64
+ environment variables ``KET_BUILD_GPU`` and ``KET_BUILD_CUDA`` override
65
+ this: ``1`` enables the feature and ``0`` disables it.
66
+ """
67
+ glibc = _glibc_version()
68
+ default = glibc is not None and glibc >= (2, 34)
69
+ return [feature for feature, env in _KBW_FEATURES if _env_flag(env, default)]
70
+
71
+
72
+ def make_libs():
73
+ """Make Rust libs if missing.
74
+
75
+ KBW is built with the features of :func:`kbw_features`.
76
+ """
77
+ dirname = os.path.dirname(__file__)
78
+
79
+ if all(os.path.isfile(f"{dirname}/{lib}") for _, lib in libs()):
80
+ return
81
+
82
+ features = kbw_features()
83
+ warnings.warn(
84
+ "Compiling Libket and KBW"
85
+ + (f" (features: {', '.join(features)})" if features else "")
86
+ + "... may take a while. If it fails, check if Rust is installed "
87
+ "https://www.rust-lang.org/tools/install."
88
+ )
89
+
90
+ build = ["cargo", "build", "--release", "--quiet"]
91
+ subprocess.run(build, cwd=f"{dirname}/libket", check=True)
92
+ kbw_build = build + (["--features", ",".join(features)] if features else [])
93
+ subprocess.run(kbw_build, cwd=f"{dirname}/kbw", check=True)
94
+
95
+ for dirlib, lib in libs():
96
+ src = f"{dirname}/{dirlib}/target/release/{lib}"
97
+ dst = f"{dirname}/{lib}"
98
+ shutil.move(src, dst)
99
+
100
+
101
+ make_libs()
@@ -8,32 +8,98 @@ stages:
8
8
  - build
9
9
  - deploy
10
10
 
11
- # Redirect Cargo's home into the project directory so GitLab's cache can
12
- # pick it up reliably (the default ~/.cargo is outside the project root).
11
+ # Only the default branch updates the caches; other branches read them (and
12
+ # fall back to the default branch's caches when they have none yet).
13
+ workflow:
14
+ rules:
15
+ # Branch pipelines only (no duplicate merge request pipelines).
16
+ - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
17
+ when: never
18
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
19
+ variables:
20
+ CACHE_POLICY: pull-push
21
+ - when: always
22
+ variables:
23
+ CACHE_POLICY: pull
24
+
25
+ default:
26
+ # A new push cancels the jobs of an outdated pipeline.
27
+ interruptible: true
28
+
13
29
  variables:
14
30
  CARGO_HOME: $CI_PROJECT_DIR/.cargo
31
+ CARGO_INCREMENTAL: "0"
32
+ CARGO_PROFILE_DEV_DEBUG: "0"
33
+
34
+ # Cache entries, shared by the jobs below.
35
+ .registry-cache: &registry-cache
36
+ key: cargo-registry-v1
37
+ paths:
38
+ - .cargo/registry/index/
39
+ - .cargo/registry/cache/
40
+ policy: $CACHE_POLICY
41
+
42
+ .llvm-cache: &llvm-cache
43
+ key: tracel-llvm-v1
44
+ paths:
45
+ - .data/tracel/
46
+ policy: $CACHE_POLICY
47
+
48
+ # Rule: the code that only the GPU and CUDA features compile changed.
49
+ .gpu-changes: &gpu-changes
50
+ changes:
51
+ - src/dense_gpu/**/*
52
+ - src/sparse_gpu/**/*
53
+ - src/block.rs
54
+ - Cargo.toml
55
+ - Cargo.lock
56
+ - .gitlab-ci.yml
15
57
 
16
58
  # ---------------------------------------------------------------------------
17
59
  # Lint stage
18
60
  # ---------------------------------------------------------------------------
19
61
 
62
+ # Default features (dense + sparse): fast, on every push.
20
63
  cargo-clippy:
21
- image: registry.gitlab.com/quantum-ket/ket-building-images:linux-2.34-1.97
64
+ image: registry.gitlab.com/quantum-ket/ket-building-images:linux-2.28-1.97
22
65
  stage: lint
23
66
  cache:
24
- - key: cargo-registry-v1
67
+ - *registry-cache
68
+ - key: cargo-clippy-2.28-$CI_COMMIT_REF_SLUG
69
+ fallback_keys:
70
+ - cargo-clippy-2.28-$CI_DEFAULT_BRANCH
25
71
  paths:
26
- - .cargo/registry/index/
27
- - .cargo/registry/cache/
28
- policy: pull-push
29
- - key: cargo-debug-$CI_COMMIT_REF_SLUG
72
+ - target/debug/
73
+ - target/.rustc_info.json
74
+ - target/CACHEDIR.TAG
75
+ policy: $CACHE_POLICY
76
+ script:
77
+ - cargo clippy --lib --tests -- -D warnings
78
+
79
+ # All features (GPU and CUDA): slow (builds LLVM bindings), so only on the
80
+ # default branch and when GPU-specific code changes. Changes to shared code
81
+ # are checked by this job on the default branch, before `publish`.
82
+ cargo-clippy-all:
83
+ image: registry.gitlab.com/quantum-ket/ket-building-images:linux-2.34-1.97
84
+ stage: lint
85
+ variables:
86
+ XDG_DATA_HOME: $CI_PROJECT_DIR/.data
87
+ cache:
88
+ - *registry-cache
89
+ - *llvm-cache
90
+ - key: cargo-clippy-2.34-all-$CI_COMMIT_REF_SLUG
91
+ fallback_keys:
92
+ - cargo-clippy-2.34-all-$CI_DEFAULT_BRANCH
30
93
  paths:
31
94
  - target/debug/
32
95
  - target/.rustc_info.json
33
96
  - target/CACHEDIR.TAG
34
- policy: pull-push
97
+ policy: $CACHE_POLICY
35
98
  script:
36
99
  - cargo clippy --all-features -- -D warnings
100
+ rules:
101
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
102
+ - *gpu-changes
37
103
 
38
104
  reuse:
39
105
  image: ghcr.io/astral-sh/uv:python3.10-trixie-slim
@@ -45,44 +111,44 @@ reuse:
45
111
  # Test stage
46
112
  # ---------------------------------------------------------------------------
47
113
 
114
+ # Default features only (dense + sparse) on the oldest supported glibc: the
115
+ # GPU and CUDA features need a GPU to run their tests, and linking their test
116
+ # binaries exhausts the CI runner. Clippy still checks them (--all-features).
48
117
  cargo-test:
49
- image: registry.gitlab.com/quantum-ket/ket-building-images:linux-2.34-1.97
118
+ image: registry.gitlab.com/quantum-ket/ket-building-images:linux-2.28-1.97
50
119
  stage: test
120
+ needs: []
51
121
  cache:
52
- - key: cargo-registry-v1
53
- paths:
54
- - .cargo/registry/index/
55
- - .cargo/registry/cache/
56
- policy: pull-push
57
- - key: cargo-debug-$CI_COMMIT_REF_SLUG
122
+ - *registry-cache
123
+ - key: cargo-test-2.28-$CI_COMMIT_REF_SLUG
124
+ fallback_keys:
125
+ - cargo-test-2.28-$CI_DEFAULT_BRANCH
58
126
  paths:
59
127
  - target/debug/
60
128
  - target/.rustc_info.json
61
129
  - target/CACHEDIR.TAG
62
- policy: pull-push
130
+ policy: $CACHE_POLICY
63
131
  script:
64
- - cargo test --all-features
132
+ - cargo test
65
133
 
66
134
  # ---------------------------------------------------------------------------
67
- # Build stage
135
+ # Build stage (default branch only). The builds start right away (`needs:
136
+ # []`); `publish` waits for them and for the lint and test jobs.
68
137
  # ---------------------------------------------------------------------------
69
138
 
70
139
  # glibc >= 2.28, default features (dense + sparse).
71
140
  linux-build:
72
141
  image: registry.gitlab.com/quantum-ket/ket-building-images:linux-2.28-1.97
73
142
  stage: build
143
+ needs: []
74
144
  cache:
75
- - key: cargo-registry-v1
76
- paths:
77
- - .cargo/registry/index/
78
- - .cargo/registry/cache/
79
- policy: pull
145
+ - *registry-cache
80
146
  - key: cargo-release-linux-2.28-$CI_COMMIT_REF_SLUG
81
147
  paths:
82
148
  - target/release/
83
149
  - target/.rustc_info.json
84
150
  - target/CACHEDIR.TAG
85
- policy: pull-push
151
+ policy: $CACHE_POLICY
86
152
  script:
87
153
  - cargo build --release
88
154
  - cp target/release/libkbw.so libkbw.so
@@ -90,24 +156,26 @@ linux-build:
90
156
  paths:
91
157
  - libkbw.so
92
158
  rules:
93
- - if: '$CI_COMMIT_BRANCH == "main"'
159
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
94
160
 
95
161
  # glibc >= 2.34, default features + GPU (wgpu) and CUDA.
96
162
  linux-gpu-build:
97
163
  image: registry.gitlab.com/quantum-ket/ket-building-images:linux-2.34-1.97
98
164
  stage: build
165
+ needs: []
166
+ variables:
167
+ # Keeps the LLVM bundle of the `cuda` feature in the cache (.data/tracel).
168
+ # Not global: uv (in `reuse`) would also write there and fail the lint.
169
+ XDG_DATA_HOME: $CI_PROJECT_DIR/.data
99
170
  cache:
100
- - key: cargo-registry-v1
101
- paths:
102
- - .cargo/registry/index/
103
- - .cargo/registry/cache/
104
- policy: pull
171
+ - *registry-cache
172
+ - *llvm-cache
105
173
  - key: cargo-release-linux-2.34-gpu-$CI_COMMIT_REF_SLUG
106
174
  paths:
107
175
  - target/release/
108
176
  - target/.rustc_info.json
109
177
  - target/CACHEDIR.TAG
110
- policy: pull-push
178
+ policy: $CACHE_POLICY
111
179
  script:
112
180
  - cargo build --release -F gpu,cuda
113
181
  - cp target/release/libkbw.so libkbw.gpu.so
@@ -115,41 +183,34 @@ linux-gpu-build:
115
183
  paths:
116
184
  - libkbw.gpu.so
117
185
  rules:
118
- - if: '$CI_COMMIT_BRANCH == "main"'
186
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
119
187
 
120
188
  windows-build:
121
189
  image: registry.gitlab.com/quantum-ket/ket-building-images:windows-1.97
122
190
  stage: build
191
+ needs: []
123
192
  cache:
124
- - key: cargo-registry-v1
125
- paths:
126
- - .cargo/registry/index/
127
- - .cargo/registry/cache/
128
- policy: pull-push
193
+ - *registry-cache
129
194
  - key: cargo-release-windows-$CI_COMMIT_REF_SLUG
130
195
  paths:
131
196
  - target/x86_64-pc-windows-gnu/release/
132
- - target/debug/
133
197
  - target/.rustc_info.json
134
198
  - target/CACHEDIR.TAG
135
- policy: pull-push
199
+ policy: $CACHE_POLICY
136
200
  script:
137
201
  - cargo build --release --target x86_64-pc-windows-gnu
138
202
  artifacts:
139
203
  paths:
140
204
  - target/x86_64-pc-windows-gnu/release/kbw.dll
141
205
  rules:
142
- - if: '$CI_COMMIT_BRANCH == "main"'
206
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
143
207
 
144
208
  macos-build:
145
209
  image: registry.gitlab.com/quantum-ket/ket-building-images:macos-1.97
146
210
  stage: build
211
+ needs: []
147
212
  cache:
148
- - key: cargo-registry-v1
149
- paths:
150
- - .cargo/registry/index/
151
- - .cargo/registry/cache/
152
- policy: pull
213
+ - *registry-cache
153
214
  - key: cargo-release-macos-$CI_COMMIT_REF_SLUG
154
215
  paths:
155
216
  - target/universal2-apple-darwin/release/
@@ -158,14 +219,14 @@ macos-build:
158
219
  - target/release/
159
220
  - target/.rustc_info.json
160
221
  - target/CACHEDIR.TAG
161
- policy: pull-push
222
+ policy: $CACHE_POLICY
162
223
  script:
163
224
  - cargo zigbuild --release --target universal2-apple-darwin
164
225
  artifacts:
165
226
  paths:
166
227
  - target/universal2-apple-darwin/release/libkbw.dylib
167
228
  rules:
168
- - if: '$CI_COMMIT_BRANCH == "main"'
229
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
169
230
 
170
231
  # ---------------------------------------------------------------------------
171
232
  # Deploy stage
@@ -173,8 +234,19 @@ macos-build:
173
234
 
174
235
  publish:
175
236
  stage: deploy
237
+ # Never cancel a publish half-way.
238
+ interruptible: false
239
+ needs:
240
+ - cargo-clippy
241
+ - cargo-clippy-all
242
+ - reuse
243
+ - cargo-test
244
+ - linux-build
245
+ - linux-gpu-build
246
+ - windows-build
247
+ - macos-build
176
248
  rules:
177
- - if: '$CI_COMMIT_BRANCH == "main"'
249
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
178
250
  script:
179
251
  - |
180
252
  curl --location --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
@@ -16,7 +16,7 @@ fn main() {
16
16
  }
17
17
 
18
18
  if accelerators.is_empty() {
19
- println!("cargo:rustc-env=KBW_ACCELERATORS=", );
19
+ println!("cargo:rustc-env=KBW_ACCELERATORS=",);
20
20
  } else {
21
21
  println!(
22
22
  "cargo:rustc-env=KBW_ACCELERATORS=[{}]",
@@ -0,0 +1,40 @@
1
+ // SPDX-FileCopyrightText: 2020 Evandro Chagas Ribeiro da Rosa <evandro@quantuloop.com>
2
+ // SPDX-FileCopyrightText: 2020 Rafael de Santiago <r.santiago@ufsc.br>
3
+ //
4
+ // SPDX-License-Identifier: Apache-2.0
5
+
6
+ //! Bit-manipulation helpers shared by all simulator backends.
7
+ //!
8
+ //! These work on scalar `usize` basis states, used by the dense backends
9
+ //! where the entire basis state fits in a single machine word. The sparse
10
+ //! backends use the keys of [`crate::sparse_frame`].
11
+
12
+ use std::ops::{BitOrAssign, Shl};
13
+
14
+ use num::Integer;
15
+
16
+ /// Build a control bitmask from a list of control qubit indices.
17
+ ///
18
+ /// The resulting mask has a `1` in position `c` for each control qubit `c`.
19
+ /// Used by dense simulators to check all controls with a single `&` operation.
20
+ pub(crate) fn get_ctrl_mask<T: Integer + BitOrAssign + Shl<usize, Output = T>>(
21
+ control: &[usize],
22
+ ) -> T {
23
+ let mut control_mask = T::zero();
24
+ for c in control {
25
+ control_mask |= T::one() << *c;
26
+ }
27
+ control_mask
28
+ }
29
+
30
+ /// Flip bit `index` in `state` (scalar, dense representation).
31
+ ///
32
+ /// Equivalent to applying a NOT gate on qubit `index` in the index space.
33
+ pub(crate) const fn bit_flip(state: usize, index: usize) -> usize {
34
+ state ^ (1 << index)
35
+ }
36
+
37
+ /// Test whether bit `target` is set in `state` (scalar, dense representation).
38
+ pub(crate) const fn is_one_at(state: usize, target: usize) -> bool {
39
+ state & (1 << target) != 0
40
+ }