ket-lang 0.10.2.dev3__tar.gz → 0.10.3.dev1__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 (117) hide show
  1. {ket_lang-0.10.2.dev3/src/ket_lang.egg-info → ket_lang-0.10.3.dev1}/PKG-INFO +1 -1
  2. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/__init__.py +1 -1
  3. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/Cargo.toml +9 -4
  4. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/c_api.rs +14 -2
  5. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/dense_v2.rs +2 -0
  6. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/lib.rs +20 -0
  7. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/examples/qft.rs +7 -10
  8. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/c_api/block.rs +1 -1
  9. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/ir/block.rs +17 -3
  10. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/lib.rs +6 -6
  11. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/mapping/dynamic_look_ahead.rs +6 -2
  12. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/process/mod.rs +5 -1
  13. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/qasm/executor.rs +5 -8
  14. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/qasm/gates.rs +37 -66
  15. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/tests.rs +1 -1
  16. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1/src/ket_lang.egg-info}/PKG-INFO +1 -1
  17. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/LICENSE +0 -0
  18. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/MANIFEST.in +0 -0
  19. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/README.md +0 -0
  20. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/pyproject.toml +0 -0
  21. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/setup.cfg +0 -0
  22. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/setup.py +0 -0
  23. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/amazon.py +0 -0
  24. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/base/__init__.py +0 -0
  25. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/base/qasm.py +0 -0
  26. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/base/quant.py +0 -0
  27. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/__init__.py +0 -0
  28. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/kbw.py +0 -0
  29. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libket/__init__.py +0 -0
  30. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libket/execution.py +0 -0
  31. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/__init__.py +0 -0
  32. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/.git +0 -0
  33. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/.gitignore +0 -0
  34. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/.gitlab-ci.yml +0 -0
  35. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/.pre-commit-config.yaml +0 -0
  36. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/CHANGELOG.md +0 -0
  37. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/LICENSE +0 -0
  38. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/LICENSES/Apache-2.0.txt +0 -0
  39. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/README.md +0 -0
  40. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/REUSE.toml +0 -0
  41. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/build.rs +0 -0
  42. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/cbindgen.toml +0 -0
  43. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/examples/grover_batch.rs +0 -0
  44. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/examples/grover_live.rs +0 -0
  45. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/examples/grover_live_dv2.rs +0 -0
  46. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/kbw.h +0 -0
  47. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/bitwise.rs +0 -0
  48. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/block.rs +0 -0
  49. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/convert.rs +0 -0
  50. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/dense.rs +0 -0
  51. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/dense_gpu/kernel.rs +0 -0
  52. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/dense_gpu/mod.rs +0 -0
  53. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/quantum_execution.rs +0 -0
  54. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/sparse.rs +0 -0
  55. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/kbw/src/sparse_v2.rs +0 -0
  56. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/.git +0 -0
  57. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/.gitignore +0 -0
  58. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/.gitlab-ci.yml +0 -0
  59. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/.pre-commit-config.yaml +0 -0
  60. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/CHANGELOG.md +0 -0
  61. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/Cargo.toml +0 -0
  62. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/LICENSE +0 -0
  63. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/LICENSES/Apache-2.0.txt +0 -0
  64. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/README.md +0 -0
  65. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/REUSE.toml +0 -0
  66. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/build.rs +0 -0
  67. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/cbindgen.toml +0 -0
  68. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/examples/grover.rs +0 -0
  69. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/libket.h +0 -0
  70. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/c_api/execute.rs +0 -0
  71. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/c_api/mod.rs +0 -0
  72. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/c_api/process.rs +0 -0
  73. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/mod.rs +0 -0
  74. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/network.rs +0 -0
  75. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/su2.rs +0 -0
  76. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/u2.rs +0 -0
  77. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/util.rs +0 -0
  78. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/x/c2to4x.rs +0 -0
  79. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/x/mod.rs +0 -0
  80. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/x/single_aux.rs +0 -0
  81. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/decompose/x/v_chain.rs +0 -0
  82. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/error.rs +0 -0
  83. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/execution.rs +0 -0
  84. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/ir/gate.rs +0 -0
  85. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/ir/hamiltonian.rs +0 -0
  86. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/ir/mod.rs +0 -0
  87. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/mapping/allocation.rs +0 -0
  88. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/mapping/graph.rs +0 -0
  89. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/mapping/mod.rs +0 -0
  90. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/matrix.rs +0 -0
  91. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/process/classical_shadow.rs +0 -0
  92. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/process/qwc.rs +0 -0
  93. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/qasm/ast.rs +0 -0
  94. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/qasm/mod.rs +0 -0
  95. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/libs/libket/src/qasm/openqasm.lalrpop +0 -0
  96. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/clib/wrapper.py +0 -0
  97. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/expv.py +0 -0
  98. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/fermion.py +0 -0
  99. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/gates.py +0 -0
  100. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/ibm.py +0 -0
  101. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/measurement.py +0 -0
  102. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/mps.py +0 -0
  103. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/npsim.py +0 -0
  104. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/operations.py +0 -0
  105. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/qint.py +0 -0
  106. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/quantumstate.py +0 -0
  107. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/qulib/__init__.py +0 -0
  108. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/qulib/gates.py +0 -0
  109. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/qulib/ham.py +0 -0
  110. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/qulib/oracle.py +0 -0
  111. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket/qulib/prepare.py +0 -0
  112. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket_lang.egg-info/SOURCES.txt +0 -0
  113. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket_lang.egg-info/dependency_links.txt +0 -0
  114. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket_lang.egg-info/not-zip-safe +0 -0
  115. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket_lang.egg-info/requires.txt +0 -0
  116. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/src/ket_lang.egg-info/top_level.txt +0 -0
  117. {ket_lang-0.10.2.dev3 → ket_lang-0.10.3.dev1}/tests/test_fermion.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ket-lang
3
- Version: 0.10.2.dev3
3
+ Version: 0.10.3.dev1
4
4
  Summary: Ket quantum programming language interpreter and library
5
5
  Home-page: https://quantumket.org
6
6
  Author: Evandro Chagas Ribeiro da Rosa
@@ -83,7 +83,7 @@ from .fermion import *
83
83
  from .fermion import __all__ as all_fermion
84
84
  from . import qulib
85
85
 
86
- __version__ = "0.10.2.dev3"
86
+ __version__ = "0.10.3.dev1"
87
87
 
88
88
  __all__ = (
89
89
  all_base
@@ -28,11 +28,11 @@ build-info = { version = "0.0.45", default-features = false, features = [] }
28
28
  serde = { version = "1.0.228", features = ["derive"] }
29
29
  serde_json = "1.0.150"
30
30
  num-traits = "0.2"
31
- cubecl = { version = "0.10.0", features = ["wgpu"] }
32
- bimap = "0.6.3"
33
- pollster = "1.0.1"
31
+ cubecl = { version = "0.10.0", features = ["wgpu"], optional = true }
32
+ bimap = { version = "0.6.3", optional = true }
33
+ pollster = { version = "1.0.1", optional = true }
34
34
  smallvec = "1.15.2"
35
- rustc-hash = "2.1.3"
35
+ rustc-hash = { version = "2.1.3", optional = true }
36
36
 
37
37
  [build-dependencies]
38
38
  build-info-build = "0.0.45"
@@ -44,3 +44,8 @@ crate-type = ["cdylib", "rlib"]
44
44
  strip = true
45
45
 
46
46
  [features]
47
+ default = ["dense", "sparse", "gpu"]
48
+ gpu = ["block", "cubecl", "pollster"]
49
+ dense = []
50
+ sparse = ["rustc-hash"]
51
+ block = ["bimap"]
@@ -17,7 +17,14 @@
17
17
 
18
18
  use std::ffi::{c_char, CStr};
19
19
 
20
- use crate::{Dense, DenseGPU, DenseGPUBlock, DenseV2, Sparse, SparseV2};
20
+ #[cfg(feature = "dense")]
21
+ use crate::{Dense, DenseV2};
22
+
23
+ #[cfg(feature = "gpu")]
24
+ use crate::{DenseGPU, DenseGPUBlock};
25
+
26
+ #[cfg(feature = "sparse")]
27
+ use crate::{Sparse, SparseV2};
21
28
  use ket::{error::KetError, process::QPUConfig};
22
29
 
23
30
  use crate::quantum_execution::QubitManager;
@@ -68,18 +75,21 @@ pub unsafe extern "C" fn kbw_make_configuration(
68
75
 
69
76
  let Ok(Ok(coupling_graph)) = unsafe { CStr::from_ptr(coupling_graph_json) }
70
77
  .to_str()
71
- .map(serde_json::from_str)
78
+ .map(serde_json::from_str::<Option<Vec<(usize, usize)>>>)
72
79
  else {
73
80
  return KetError::SerdeError.error_code();
74
81
  };
75
82
 
76
83
  let config = match simulator.as_str() {
84
+ #[cfg(feature = "dense")]
77
85
  "densev1" => {
78
86
  make_config::<Dense>(num_qubits, use_live, decompose, coupling_graph, gradient)
79
87
  }
88
+ #[cfg(feature = "dense")]
80
89
  "dense" | "densev2" => {
81
90
  make_config::<DenseV2>(num_qubits, use_live, decompose, coupling_graph, gradient)
82
91
  }
92
+ #[cfg(feature = "gpu")]
83
93
  "densegpu" => {
84
94
  if num_qubits
85
95
  < std::env::var("KBW_BLOCK_SIZE")
@@ -98,9 +108,11 @@ pub unsafe extern "C" fn kbw_make_configuration(
98
108
  )
99
109
  }
100
110
  }
111
+ #[cfg(feature = "sparse")]
101
112
  "sparse" => {
102
113
  make_config::<Sparse>(num_qubits, use_live, decompose, coupling_graph, gradient)
103
114
  }
115
+ #[cfg(feature = "sparse")]
104
116
  "sparsev2" => {
105
117
  make_config::<SparseV2>(num_qubits, use_live, decompose, coupling_graph, gradient)
106
118
  }
@@ -21,6 +21,7 @@
21
21
 
22
22
  use std::fmt::Display;
23
23
 
24
+ #[cfg(feature = "block")]
24
25
  use crate::block::BlockSimulator;
25
26
  use crate::quantum_execution::QuantumExecution;
26
27
  use crate::{
@@ -340,6 +341,7 @@ impl<F: FloatOps> QuantumExecution for DenseV2<F> {
340
341
  }
341
342
  }
342
343
 
344
+ #[cfg(feature = "block")]
343
345
  impl<F: FloatOps + Display> BlockSimulator<Self, ()> for DenseV2<F> {
344
346
  fn new_blocks(
345
347
  num_local_qubits: usize,
@@ -69,14 +69,20 @@ use std::{
69
69
  };
70
70
 
71
71
  pub mod bitwise;
72
+ #[cfg(feature = "block")]
72
73
  pub mod block;
73
74
  pub mod c_api;
74
75
  pub mod convert;
76
+ #[cfg(feature = "dense")]
75
77
  pub mod dense;
78
+ #[cfg(feature = "gpu")]
76
79
  pub mod dense_gpu;
80
+ #[cfg(feature = "dense")]
77
81
  pub mod dense_v2;
78
82
  pub mod quantum_execution;
83
+ #[cfg(feature = "sparse")]
79
84
  pub mod sparse;
85
+ #[cfg(feature = "sparse")]
80
86
  pub mod sparse_v2;
81
87
 
82
88
  /// Extension trait that adds simulator-specific helpers on top of the standard
@@ -118,36 +124,45 @@ impl FloatOps for f64 {
118
124
  }
119
125
  }
120
126
 
127
+ #[cfg(feature = "dense")]
121
128
  /// Double-buffered, dense state-vector simulator using `f32` amplitudes.
122
129
  /// Supports up to 32 qubits.
123
130
  pub type Dense = dense::Dense<f32>;
124
131
 
132
+ #[cfg(feature = "dense")]
125
133
  /// [`QubitManager`](quantum_execution::QubitManager) wrapping the [`Dense`] backend.
126
134
  /// The recommended entry point for single-process dense simulation.
127
135
  pub type DenseSimulator = quantum_execution::QubitManager<Dense>;
128
136
 
137
+ #[cfg(feature = "dense")]
129
138
  /// In-place dense state-vector simulator using `f32` amplitudes.
130
139
  /// Slightly lower memory overhead than [`Dense`] due to the single-buffer design.
131
140
  pub type DenseV2 = dense_v2::DenseV2<f32>;
132
141
 
142
+ #[cfg(feature = "dense")]
133
143
  /// [`QubitManager`](quantum_execution::QubitManager) wrapping the [`DenseV2`] backend.
134
144
  pub type DenseV2Simulator = quantum_execution::QubitManager<DenseV2>;
135
145
 
146
+ #[cfg(all(feature = "block", feature = "dense"))]
136
147
  /// Blocked [`DenseV2`] simulator that partitions the qubit register into
137
148
  /// *local* (simulated) and *global* (index) portions, enabling circuits
138
149
  /// with more qubits than fit in a single state-vector.
139
150
  pub type DenseV2Block = block::Block<(), DenseV2>;
140
151
 
152
+ #[cfg(all(feature = "block", feature = "dense"))]
141
153
  /// [`QubitManager`](quantum_execution::QubitManager) wrapping the [`DenseV2Block`] backend.
142
154
  pub type DenseV2BlockSimulator = quantum_execution::QubitManager<DenseV2Block>;
143
155
 
156
+ #[cfg(feature = "gpu")]
144
157
  /// GPU-accelerated dense state-vector simulator using the WGPU runtime and `f32` amplitudes.
145
158
  /// Requires a compatible GPU and the `wgpu` feature of `CubeCL`.
146
159
  pub type DenseGPU = dense_gpu::DenseGPU<cubecl::wgpu::WgpuRuntime, f32>;
147
160
 
161
+ #[cfg(feature = "gpu")]
148
162
  /// [`QubitManager`](quantum_execution::QubitManager) wrapping the [`DenseGPU`] backend.
149
163
  pub type DenseGPUSimulator = quantum_execution::QubitManager<DenseGPU>;
150
164
 
165
+ #[cfg(feature = "gpu")]
151
166
  /// Blocked GPU dense state-vector; combines the WGPU backend with the block
152
167
  /// partitioning scheme for circuits exceeding on-device memory.
153
168
  pub type DenseGPUBlock = block::Block<
@@ -161,21 +176,26 @@ pub type DenseGPUBlock = block::Block<
161
176
  dense_gpu::DenseGPU<cubecl::wgpu::WgpuRuntime, f32>,
162
177
  >;
163
178
 
179
+ #[cfg(feature = "gpu")]
164
180
  /// [`QubitManager`](quantum_execution::QubitManager) wrapping the [`DenseGPUBlock`] backend.
165
181
  /// Note: the typo `DenseGPUS` is preserved for backwards compatibility.
166
182
  pub type DenseGPUBlockSimulator = quantum_execution::QubitManager<DenseGPUBlock>;
167
183
 
184
+ #[cfg(feature = "sparse")]
168
185
  /// Sparse state-vector simulator backed by a [`HashMap`](std::collections::HashMap),
169
186
  /// using `f32` amplitudes. Efficient for circuits that remain in a low-entanglement
170
187
  /// regime (e.g. few non-zero amplitudes).
171
188
  pub type Sparse = sparse::Sparse<f32>;
172
189
 
190
+ #[cfg(feature = "sparse")]
173
191
  /// [`QubitManager`](quantum_execution::QubitManager) wrapping the [`Sparse`] backend.
174
192
  pub type SparseSimulator = quantum_execution::QubitManager<Sparse>;
175
193
 
194
+ #[cfg(feature = "sparse")]
176
195
  /// Sparse state-vector simulator backed by a sorted `Vec`, providing better
177
196
  /// cache locality than [`Sparse`] at the cost of periodic sort-and-reduce passes.
178
197
  pub type SparseV2 = sparse_v2::SparseV2<f32>;
179
198
 
199
+ #[cfg(feature = "sparse")]
180
200
  /// [`QubitManager`](quantum_execution::QubitManager) wrapping the [`SparseV2`] backend.
181
201
  pub type SparseV2Simulator = quantum_execution::QubitManager<SparseV2>;
@@ -26,20 +26,17 @@ fn qft(qubits: &[usize], do_swap: bool) -> Result<BasicBlock, KetError> {
26
26
  let last = qubits[qubits.len() - 1];
27
27
  quantum_code.append_gate(QuantumGate::Hadamard, last);
28
28
  for (i, c) in init.iter().enumerate() {
29
- quantum_code.append_block(
30
- controlled_gate(
31
- QuantumGate::Phase(Param::Value(PI / 2.0_f64.powi(i as i32 + 1))),
32
- &[*c],
33
- last,
34
- )?,
35
- None,
36
- );
29
+ quantum_code.append_block(controlled_gate(
30
+ QuantumGate::Phase(Param::Value(PI / 2.0_f64.powi(i as i32 + 1))),
31
+ &[*c],
32
+ last,
33
+ )?);
37
34
  }
38
- quantum_code.append_block(qft(init, false)?, None);
35
+ quantum_code.append_block(qft(init, false)?);
39
36
 
40
37
  if do_swap {
41
38
  for i in 0..qubits.len() / 2 {
42
- quantum_code.append_block(swap_gate(qubits[i], qubits[qubits.len() - i - 1])?, None);
39
+ quantum_code.append_block(swap_gate(qubits[i], qubits[qubits.len() - i - 1])?);
43
40
  }
44
41
  }
45
42
 
@@ -86,7 +86,7 @@ pub extern "C" fn ket_block_lock_control(block: &mut BasicBlock) -> i32 {
86
86
  #[no_mangle]
87
87
  pub extern "C" fn ket_block_append_block(block: &mut BasicBlock, other: *mut BasicBlock) -> i32 {
88
88
  let other = unsafe { Box::from_raw(other) };
89
- block.append_block(*other, None);
89
+ block.append_block(*other);
90
90
  c_ok()
91
91
  }
92
92
 
@@ -126,6 +126,7 @@ impl BasicBlock {
126
126
  new_inst: GateInstruction,
127
127
  epsilon: Option<f64>,
128
128
  check_propiety: bool,
129
+ min_index: usize,
129
130
  ) {
130
131
  let epsilon = epsilon.unwrap_or(1e-10);
131
132
 
@@ -134,6 +135,9 @@ impl BasicBlock {
134
135
  }
135
136
 
136
137
  for (index, inst) in self.gates.iter().enumerate().rev() {
138
+ if index < min_index {
139
+ break;
140
+ }
137
141
  let shares_qubits = inst.target == new_inst.target
138
142
  || inst.control.contains(&new_inst.target)
139
143
  || new_inst.control.contains(&inst.target)
@@ -165,7 +169,7 @@ impl BasicBlock {
165
169
 
166
170
  /// Appends an uncontrolled gate to the block.
167
171
  pub fn append_gate(&mut self, gate: QuantumGate, target: usize) {
168
- self.append_instruction(GateInstruction::new(gate, target), None, true);
172
+ self.append_instruction(GateInstruction::new(gate, target), None, true, 0);
169
173
  }
170
174
 
171
175
  /// Return a new basic block with the inverse of the circuit.
@@ -229,6 +233,7 @@ impl BasicBlock {
229
233
  },
230
234
  None,
231
235
  true,
236
+ 0,
232
237
  );
233
238
  }
234
239
 
@@ -255,9 +260,18 @@ impl BasicBlock {
255
260
  /// After draining `block.gates`, the global phases are summed and the
256
261
  /// `qubits_op` dependency maps are merged (restricting propriety to the
257
262
  /// more-general of the two).
258
- pub fn append_block(&mut self, mut block: Self, epsilon: Option<f64>) {
263
+ pub fn append_block(&mut self, block: Self) {
264
+ self.append_block_with_epsilon_and_min_index(block, None, 0);
265
+ }
266
+
267
+ pub fn append_block_with_epsilon_and_min_index(
268
+ &mut self,
269
+ mut block: Self,
270
+ epsilon: Option<f64>,
271
+ min_index: usize,
272
+ ) {
259
273
  for inst in block.gates {
260
- self.append_instruction(inst, epsilon, false);
274
+ self.append_instruction(inst, epsilon, false, min_index);
261
275
  }
262
276
 
263
277
  self.global = match (self.global, block.global) {
@@ -58,9 +58,9 @@ pub fn controlled_gate(
58
58
  /// Propagates any [`KetError`] that occurs during the `controlled_gate` operation.
59
59
  pub fn swap_gate(a: usize, b: usize) -> Result<BasicBlock, KetError> {
60
60
  let mut quantum_code = BasicBlock::new();
61
- quantum_code.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?, None);
62
- quantum_code.append_block(controlled_gate(QuantumGate::PauliX, &[b], a)?, None);
63
- quantum_code.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?, None);
61
+ quantum_code.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?);
62
+ quantum_code.append_block(controlled_gate(QuantumGate::PauliX, &[b], a)?);
63
+ quantum_code.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?);
64
64
  Ok(quantum_code)
65
65
  }
66
66
 
@@ -84,9 +84,9 @@ where
84
84
 
85
85
  let action = action(BasicBlock::new())?;
86
86
 
87
- quantum_code.append_block(compute, None);
88
- quantum_code.append_block(action, None);
89
- quantum_code.append_block(uncompute, None);
87
+ quantum_code.append_block(compute);
88
+ quantum_code.append_block(action);
89
+ quantum_code.append_block(uncompute);
90
90
 
91
91
  Ok(quantum_code)
92
92
  }
@@ -192,8 +192,12 @@ pub(super) fn map(
192
192
  let mut next_state = physical_to_logical.clone();
193
193
  let log_a = next_state.remove(&phys_a);
194
194
  let log_b = next_state.remove(&phys_b);
195
- if let Some(la) = log_a { next_state.insert(phys_b, la); }
196
- if let Some(lb) = log_b { next_state.insert(phys_a, lb); }
195
+ if let Some(la) = log_a {
196
+ next_state.insert(phys_b, la);
197
+ }
198
+ if let Some(lb) = log_b {
199
+ next_state.insert(phys_a, lb);
200
+ }
197
201
 
198
202
  if visited_states.contains(&next_state) {
199
203
  total_score - 1000000
@@ -234,7 +234,11 @@ impl Process {
234
234
  });
235
235
  }
236
236
 
237
- self.main_block.append_block(block, Some(self.epsilon));
237
+ self.main_block.append_block_with_epsilon_and_min_index(
238
+ block,
239
+ Some(self.epsilon),
240
+ self.live_pc,
241
+ );
238
242
  Ok(())
239
243
  }
240
244
 
@@ -360,7 +360,7 @@ fn apply_gate_call(
360
360
  } else {
361
361
  let mut inner = BasicBlock::new();
362
362
  append_u3(&mut inner, theta, phi, lambda, q);
363
- block.append_block(inner.control(extra_controls)?, None);
363
+ block.append_block(inner.control(extra_controls)?);
364
364
  }
365
365
  }
366
366
  }
@@ -388,7 +388,7 @@ fn apply_gate_call(
388
388
  };
389
389
  let mut controls: Vec<usize> = extra_controls.to_vec();
390
390
  controls.push(c);
391
- block.append_block(controlled_gate(QuantumGate::PauliX, &controls, t)?, None);
391
+ block.append_block(controlled_gate(QuantumGate::PauliX, &controls, t)?);
392
392
  }
393
393
  }
394
394
 
@@ -522,7 +522,7 @@ fn apply_gate_call_body(
522
522
  } else {
523
523
  let mut inner = BasicBlock::new();
524
524
  append_u3(&mut inner, theta, phi, lambda, qubits[0]);
525
- block.append_block(inner.control(extra_controls)?, None);
525
+ block.append_block(inner.control(extra_controls)?);
526
526
  }
527
527
  }
528
528
  "CX" => {
@@ -531,10 +531,7 @@ fn apply_gate_call_body(
531
531
  }
532
532
  let mut controls: Vec<usize> = extra_controls.to_vec();
533
533
  controls.push(qubits[0]);
534
- block.append_block(
535
- controlled_gate(QuantumGate::PauliX, &controls, qubits[1])?,
536
- None,
537
- );
534
+ block.append_block(controlled_gate(QuantumGate::PauliX, &controls, qubits[1])?);
538
535
  }
539
536
  name if is_qelib1_gate(name) => {
540
537
  apply_qelib1_gate_raw(
@@ -816,7 +813,7 @@ fn apply_qelib1_gate_raw(
816
813
  } else {
817
814
  let mut inner = BasicBlock::new();
818
815
  append_qelib1_gate(&mut inner, gate)?;
819
- block.append_block(inner.control(extra_controls)?, None);
816
+ block.append_block(inner.control(extra_controls)?);
820
817
  }
821
818
  Ok(())
822
819
  }
@@ -69,7 +69,7 @@ pub fn append_controlled_u3(
69
69
  let mut u3_block = BasicBlock::new();
70
70
  append_u3(&mut u3_block, theta, phi, lambda, target);
71
71
  let controlled = u3_block.control(controls)?;
72
- block.append_block(controlled, None);
72
+ block.append_block(controlled);
73
73
  Ok(())
74
74
  }
75
75
 
@@ -261,101 +261,75 @@ pub fn append_qelib1_gate(block: &mut BasicBlock, gate: Qelib1Gate) -> Result<()
261
261
 
262
262
  // ── Two-qubit ─────────────────────────────────────────────────────
263
263
  Qelib1Gate::Cx { control, target } => {
264
- block.append_block(
265
- controlled_gate(QuantumGate::PauliX, &[control], target)?,
266
- None,
267
- );
264
+ block.append_block(controlled_gate(QuantumGate::PauliX, &[control], target)?);
268
265
  }
269
266
  Qelib1Gate::Cy { control, target } => {
270
- block.append_block(
271
- controlled_gate(QuantumGate::PauliY, &[control], target)?,
272
- None,
273
- );
267
+ block.append_block(controlled_gate(QuantumGate::PauliY, &[control], target)?);
274
268
  }
275
269
  Qelib1Gate::Cz { control, target } => {
276
- block.append_block(
277
- controlled_gate(QuantumGate::PauliZ, &[control], target)?,
278
- None,
279
- );
270
+ block.append_block(controlled_gate(QuantumGate::PauliZ, &[control], target)?);
280
271
  }
281
272
  Qelib1Gate::Ch { control, target } => {
282
- block.append_block(
283
- controlled_gate(QuantumGate::Hadamard, &[control], target)?,
284
- None,
285
- );
273
+ block.append_block(controlled_gate(QuantumGate::Hadamard, &[control], target)?);
286
274
  }
287
275
  Qelib1Gate::Cs { control, target } => {
288
- block.append_block(controlled_gate(QuantumGate::s(), &[control], target)?, None);
276
+ block.append_block(controlled_gate(QuantumGate::s(), &[control], target)?);
289
277
  }
290
278
  Qelib1Gate::Csdg { control, target } => {
291
- block.append_block(
292
- controlled_gate(QuantumGate::sd(), &[control], target)?,
293
- None,
294
- );
279
+ block.append_block(controlled_gate(QuantumGate::sd(), &[control], target)?);
295
280
  }
296
281
  Qelib1Gate::Ct { control, target } => {
297
- block.append_block(controlled_gate(QuantumGate::t(), &[control], target)?, None);
282
+ block.append_block(controlled_gate(QuantumGate::t(), &[control], target)?);
298
283
  }
299
284
  Qelib1Gate::Ctdg { control, target } => {
300
- block.append_block(
301
- controlled_gate(QuantumGate::td(), &[control], target)?,
302
- None,
303
- );
285
+ block.append_block(controlled_gate(QuantumGate::td(), &[control], target)?);
304
286
  }
305
287
  Qelib1Gate::Swap { a, b } => {
306
- block.append_block(swap_gate(a, b)?, None);
288
+ block.append_block(swap_gate(a, b)?);
307
289
  }
308
290
  Qelib1Gate::Crx {
309
291
  theta,
310
292
  control,
311
293
  target,
312
294
  } => {
313
- block.append_block(
314
- controlled_gate(
315
- QuantumGate::RotationX(Param::Value(theta)),
316
- &[control],
317
- target,
318
- )?,
319
- None,
320
- );
295
+ block.append_block(controlled_gate(
296
+ QuantumGate::RotationX(Param::Value(theta)),
297
+ &[control],
298
+ target,
299
+ )?);
321
300
  }
322
301
  Qelib1Gate::Cry {
323
302
  theta,
324
303
  control,
325
304
  target,
326
305
  } => {
327
- block.append_block(
328
- controlled_gate(
329
- QuantumGate::RotationY(Param::Value(theta)),
330
- &[control],
331
- target,
332
- )?,
333
- None,
334
- );
306
+ block.append_block(controlled_gate(
307
+ QuantumGate::RotationY(Param::Value(theta)),
308
+ &[control],
309
+ target,
310
+ )?);
335
311
  }
336
312
  Qelib1Gate::Crz {
337
313
  phi,
338
314
  control,
339
315
  target,
340
316
  } => {
341
- block.append_block(
342
- controlled_gate(
343
- QuantumGate::RotationZ(Param::Value(phi)),
344
- &[control],
345
- target,
346
- )?,
347
- None,
348
- );
317
+ block.append_block(controlled_gate(
318
+ QuantumGate::RotationZ(Param::Value(phi)),
319
+ &[control],
320
+ target,
321
+ )?);
349
322
  }
350
323
  Qelib1Gate::Cu1 {
351
324
  lambda,
352
325
  control,
353
326
  target,
354
327
  } => {
355
- block.append_block(
356
- controlled_gate(QuantumGate::Phase(Param::Value(lambda)), &[control], target)?,
357
- None,
358
- );
328
+ block.append_block(controlled_gate(
329
+ QuantumGate::Phase(Param::Value(lambda)),
330
+ &[control],
331
+ target,
332
+ )?);
359
333
  }
360
334
  Qelib1Gate::Cu3 {
361
335
  theta,
@@ -370,17 +344,14 @@ pub fn append_qelib1_gate(block: &mut BasicBlock, gate: Qelib1Gate) -> Result<()
370
344
  // ── Three-qubit ───────────────────────────────────────────────────
371
345
  Qelib1Gate::Ccx { c0, c1, target } => {
372
346
  // Toffoli = CCX
373
- block.append_block(
374
- controlled_gate(QuantumGate::PauliX, &[c0, c1], target)?,
375
- None,
376
- );
347
+ block.append_block(controlled_gate(QuantumGate::PauliX, &[c0, c1], target)?);
377
348
  }
378
349
  Qelib1Gate::Cswap { control, a, b } => {
379
350
  // Fredkin = controlled SWAP (3 CNOTs controlled)
380
351
  let mut cswap_block = BasicBlock::new();
381
- cswap_block.append_block(swap_gate(a, b)?, None);
352
+ cswap_block.append_block(swap_gate(a, b)?);
382
353
  let controlled = cswap_block.control(&[control])?;
383
- block.append_block(controlled, None);
354
+ block.append_block(controlled);
384
355
  }
385
356
 
386
357
  // ── Two-qubit parametric (Ising-type) ────────────────────────────
@@ -389,18 +360,18 @@ pub fn append_qelib1_gate(block: &mut BasicBlock, gate: Qelib1Gate) -> Result<()
389
360
  // Decomposition: H⊗H → CX(a,b) → Rz(θ) on b → CX(a,b) → H⊗H
390
361
  block.append_gate(QuantumGate::Hadamard, a);
391
362
  block.append_gate(QuantumGate::Hadamard, b);
392
- block.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?, None);
363
+ block.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?);
393
364
  block.append_gate(QuantumGate::RotationZ(Param::Value(theta)), b);
394
- block.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?, None);
365
+ block.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?);
395
366
  block.append_gate(QuantumGate::Hadamard, a);
396
367
  block.append_gate(QuantumGate::Hadamard, b);
397
368
  }
398
369
  Qelib1Gate::Rzz { theta, a, b } => {
399
370
  // Rzz(θ) = exp(-i θ/2 · Z⊗Z)
400
371
  // Decomposition: CX(a,b) → Rz(θ) on b → CX(a,b)
401
- block.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?, None);
372
+ block.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?);
402
373
  block.append_gate(QuantumGate::RotationZ(Param::Value(theta)), b);
403
- block.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?, None);
374
+ block.append_block(controlled_gate(QuantumGate::PauliX, &[a], b)?);
404
375
  }
405
376
  }
406
377
 
@@ -605,7 +605,7 @@ mod basic_block_tests {
605
605
  a.append_gate(QuantumGate::PauliX, 0);
606
606
  let mut b = BasicBlock::new();
607
607
  b.append_gate(QuantumGate::PauliX, 0);
608
- a.append_block(b, None);
608
+ a.append_block(b);
609
609
  assert_eq!(
610
610
  a.gates.len(),
611
611
  0,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ket-lang
3
- Version: 0.10.2.dev3
3
+ Version: 0.10.3.dev1
4
4
  Summary: Ket quantum programming language interpreter and library
5
5
  Home-page: https://quantumket.org
6
6
  Author: Evandro Chagas Ribeiro da Rosa
File without changes
File without changes
File without changes
File without changes