Skip to content

Commit bcf332e

Browse files
committed
adding pauli structs
1 parent 7536d27 commit bcf332e

File tree

19 files changed

+1175
-562
lines changed

19 files changed

+1175
-562
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pyo3 = "0.23"
2424
rand = "0.8"
2525
rand_chacha = "0.3"
2626
rand_xoshiro = "0.6"
27+
num-complex = "0.4"
2728

2829
pecos-core = { version = "0.1.1", path = "crates/pecos-core" }
2930
pecos-qsim = { version = "0.1.1", path = "crates/pecos-qsim" }

crates/benchmarks/benches/modules/element_ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn bench_conversion<E: IndexableElement + From<u16>, M: Measurement>(
3030
b.iter(|| {
3131
let mut sum = 0_usize;
3232
for i in 0..1000_u16 {
33-
sum += E::from(i).to_usize();
33+
sum += E::from(i).to_index();
3434
}
3535
black_box(sum)
3636
});
@@ -50,7 +50,7 @@ fn bench_memory_access<E: IndexableElement + From<u16>, M: Measurement>(
5050
b.iter(|| {
5151
let mut sum = E::from(0_u16);
5252
for &item in &vec {
53-
sum = E::from((sum.to_usize() + item.to_usize()) as u16);
53+
sum = E::from((sum.to_index() + item.to_index()) as u16);
5454
}
5555
black_box(sum)
5656
});

crates/pecos-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ description = "Provides core definitions and functions for PECOS simulations."
1414
rand = { workspace = true }
1515
rand_chacha = { workspace = true }
1616
rand_xoshiro = { workspace = true }
17+
num-complex = { workspace = true }
1718

1819
[lints]
1920
workspace = true

crates/pecos-core/src/sets/element.rs renamed to crates/pecos-core/src/element.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ impl<T: Debug + Clone + Ord + Copy + Hash> Element for T {}
2020

2121
#[allow(clippy::module_name_repetitions)]
2222
pub trait IndexableElement: Element {
23-
fn to_usize(&self) -> usize;
24-
fn from_usize(value: usize) -> Self;
23+
fn to_index(&self) -> usize;
24+
fn from_index(value: usize) -> Self;
2525
}
2626

2727
macro_rules! impl_indexable_element_safe {
2828
($t:ty) => {
2929
impl IndexableElement for $t {
3030
#[allow(clippy::as_conversions, clippy::cast_possible_truncation)]
3131
#[inline(always)]
32-
fn to_usize(&self) -> usize {
32+
fn to_index(&self) -> usize {
3333
*self as usize
3434
}
3535

3636
#[allow(clippy::as_conversions, clippy::cast_possible_truncation)]
3737
#[inline(always)]
38-
fn from_usize(value: usize) -> Self {
38+
fn from_index(value: usize) -> Self {
3939
value as $t
4040
}
4141
}
@@ -55,26 +55,26 @@ impl_indexable_element_safe!(u64);
5555
#[cfg(target_pointer_width = "32")]
5656
impl IndexableElement for u64 {
5757
#[inline(always)]
58-
fn to_usize(&self) -> usize {
58+
fn to_index(&self) -> usize {
5959
usize::try_from(*self).expect("u64 value too large for 32-bit usize")
6060
}
6161

6262
#[allow(clippy::as_conversions)]
6363
#[inline(always)]
64-
fn from_usize(value: usize) -> Self {
64+
fn from_index(value: usize) -> Self {
6565
value as u64
6666
}
6767
}
6868

6969
// u128 is always problematic for current architectures, so we'll implement it to always panic
7070
impl IndexableElement for u128 {
7171
#[inline(always)]
72-
fn to_usize(&self) -> usize {
72+
fn to_index(&self) -> usize {
7373
panic!("u128 cannot be safely converted to usize without potential data loss")
7474
}
7575

7676
#[inline(always)]
77-
fn from_usize(_value: usize) -> Self {
77+
fn from_index(_value: usize) -> Self {
7878
panic!("usize cannot be safely converted to u128 on all platforms")
7979
}
8080
}

crates/pecos-core/src/gate.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
pub enum Gate {
2+
// Paulis
3+
I,
4+
X,
5+
Y,
6+
Z,
7+
8+
// Sqrt of Paulis
9+
SX,
10+
SXdg,
11+
SY,
12+
SYdg,
13+
SZ,
14+
SZdg,
15+
16+
// Hadamards
17+
H,
18+
H2,
19+
H3,
20+
H4,
21+
H5,
22+
H6,
23+
24+
// Face rotations
25+
F,
26+
Fdg,
27+
F2,
28+
F2dg,
29+
F3,
30+
F3dg,
31+
F4,
32+
F4dg,
33+
34+
// Controlled-Paulis
35+
CX,
36+
CY,
37+
CZ,
38+
39+
// Sqrt of two Paulis
40+
SXX,
41+
SXXdg,
42+
SYY,
43+
SYYdg,
44+
SZZ,
45+
SZZdg,
46+
47+
// Other TQ gates
48+
SWAP,
49+
G,
50+
51+
// Measurements
52+
MX,
53+
MnX,
54+
MY,
55+
MnY,
56+
MZ,
57+
MnZ,
58+
59+
// Preps
60+
PX,
61+
PnX,
62+
PY,
63+
PnY,
64+
PZ,
65+
PnZ,
66+
67+
// Measure + Prep
68+
MPX,
69+
MPnX,
70+
MPY,
71+
MPnY,
72+
MPZ,
73+
MPnZ,
74+
75+
// # Non-Cliffords
76+
// SQ rotations
77+
RX(f64),
78+
RY(f64),
79+
RZ(f64),
80+
81+
U(f64, f64, f64),
82+
R1XY(f64, f64),
83+
84+
// T gates
85+
T,
86+
Tdg,
87+
88+
// TQ rotations
89+
RXX(f64),
90+
RYY(f64),
91+
RZZ(f64),
92+
93+
// Composite TQ rotation
94+
RXXRYYRZZ(f64, f64, f64),
95+
96+
// Custom user gate
97+
CustomGate,
98+
}

crates/pecos-core/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@
1010
// or implied. See the License for the specific language governing permissions and limitations under
1111
// the License.
1212

13-
mod pauli;
14-
mod sets;
15-
mod sims_rngs;
13+
pub mod element;
14+
pub mod gate;
15+
pub mod pauli;
16+
pub mod phase;
17+
pub mod qubit_id;
18+
pub mod sets;
19+
pub mod sign;
20+
pub mod sims_rngs;
1621

17-
pub use sets::element::{Element, IndexableElement};
22+
pub use element::{Element, IndexableElement};
23+
pub use phase::Phase;
24+
pub use qubit_id::QubitId;
1825
pub use sets::set::Set;
1926
pub use sets::vec_set::VecSet;
27+
pub use sign::Sign;
2028

2129
pub use crate::sims_rngs::chacha_rng::{ChaCha12Rng, ChaCha20Rng, ChaCha8Rng};
2230
pub use crate::sims_rngs::choices::Choices;
@@ -27,4 +35,8 @@ pub use crate::sims_rngs::xoshiro_rng::{
2735
Xoshiro128PlusPlus, Xoshiro128StarStar, Xoshiro256PlusPlus, Xoshiro256StarStar,
2836
Xoshiro512PlusPlus, Xoshiro512StarStar,
2937
};
30-
pub use pauli::{BitSetPauli, PauliCollection, PauliOperator, Phase, SetPauli, StdPauli};
38+
pub use gate::Gate;
39+
pub use pauli::pauli_bitmap::PauliBitmap;
40+
pub use pauli::pauli_sparse::PauliSparse;
41+
pub use pauli::pauli_string::PauliString;
42+
pub use pauli::{Pauli, PauliOperator};

0 commit comments

Comments
 (0)