Skip to content

Commit 9c188d1

Browse files
authored
Adding an engine that runs HUGR directly (#222)
* Adding an engine that runs HUGR directly
1 parent 9f64024 commit 9c188d1

38 files changed

+7307
-56
lines changed

Cargo.lock

Lines changed: 17 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
@@ -120,6 +120,7 @@ pecos-qis-ffi-types = { version = "0.1.1", path = "crates/pecos-qis-ffi-types" }
120120
pecos-qis-selene = { version = "0.1.1", path = "crates/pecos-qis-selene" }
121121
pecos-qis-core = { version = "0.1.1", path = "crates/pecos-qis-core" }
122122
pecos-hugr-qis = { version = "0.1.1", path = "crates/pecos-hugr-qis" }
123+
pecos-hugr = { version = "0.1.1", path = "crates/pecos-hugr" }
123124
pecos-llvm = { version = "0.1.1", path = "crates/pecos-llvm" }
124125
pecos-rslib = { version = "0.1.1", path = "python/pecos-rslib" }
125126
pecos-wasm = { version = "0.1.1", path = "crates/pecos-wasm" }

crates/pecos-core/src/gate_type.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ pub enum GateType {
4747
R1XY = 36,
4848

4949
CX = 50,
50-
// CY = 51
51-
// CZ = 52
50+
CY = 51,
51+
CZ = 52,
5252
// SXX = 53
5353
// SXXdg = 54
5454
// SYY = 55
@@ -110,6 +110,8 @@ impl From<u8> for GateType {
110110
35 => GateType::U,
111111
36 => GateType::R1XY,
112112
50 => GateType::CX,
113+
51 => GateType::CY,
114+
52 => GateType::CZ,
113115
57 => GateType::SZZ,
114116
58 => GateType::SZZdg,
115117
82 => GateType::RZZ,
@@ -147,6 +149,8 @@ impl GateType {
147149
| GateType::T
148150
| GateType::Tdg
149151
| GateType::CX
152+
| GateType::CY
153+
| GateType::CZ
150154
| GateType::SZZ
151155
| GateType::SZZdg
152156
| GateType::Measure
@@ -204,7 +208,12 @@ impl GateType {
204208
| GateType::MeasCrosstalkLocalPayload => 1,
205209

206210
// Two-qubit gates
207-
GateType::CX | GateType::SZZ | GateType::SZZdg | GateType::RZZ => 2,
211+
GateType::CX
212+
| GateType::CY
213+
| GateType::CZ
214+
| GateType::SZZ
215+
| GateType::SZZdg
216+
| GateType::RZZ => 2,
208217
}
209218
}
210219

@@ -270,6 +279,8 @@ impl fmt::Display for GateType {
270279
GateType::U => write!(f, "U"),
271280
GateType::R1XY => write!(f, "R1XY"),
272281
GateType::CX => write!(f, "CX"),
282+
GateType::CY => write!(f, "CY"),
283+
GateType::CZ => write!(f, "CZ"),
273284
GateType::SZZ => write!(f, "SZZ"),
274285
GateType::SZZdg => write!(f, "SZZdg"),
275286
GateType::RZZ => write!(f, "RZZ"),

crates/pecos-engines/src/noise/biased_depolarizing.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ impl BiasedDepolarizingNoiseModel {
173173
trace!("Applying single-qubit gate with possible fault");
174174
self.apply_sq_faults(&mut builder, gate);
175175
}
176-
GateType::CX | GateType::RZZ | GateType::SZZ | GateType::SZZdg => {
176+
GateType::CX
177+
| GateType::CY
178+
| GateType::CZ
179+
| GateType::RZZ
180+
| GateType::SZZ
181+
| GateType::SZZdg => {
177182
NoiseUtils::add_gate_to_builder(&mut builder, gate);
178183
trace!("Applying two-qubit gate with possible fault");
179184
self.apply_tq_faults(&mut builder, gate);

crates/pecos-engines/src/noise/depolarizing.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,12 @@ impl DepolarizingNoiseModel {
178178
trace!("Applying single-qubit gate with possible fault");
179179
self.apply_sq_faults(&mut builder, gate);
180180
}
181-
GateType::CX | GateType::RZZ | GateType::SZZ | GateType::SZZdg => {
181+
GateType::CX
182+
| GateType::CY
183+
| GateType::CZ
184+
| GateType::RZZ
185+
| GateType::SZZ
186+
| GateType::SZZdg => {
182187
NoiseUtils::add_gate_to_builder(&mut builder, gate);
183188
trace!("Applying two-qubit gate with possible fault");
184189
self.apply_tq_faults(&mut builder, gate);

crates/pecos-engines/src/quantum.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,38 @@ impl Engine for StateVecEngine {
193193
.cx(usize::from(qubits[0]), usize::from(qubits[1]));
194194
}
195195
}
196+
GateType::CY => {
197+
if cmd.qubits.len() % 2 != 0 {
198+
return Err(quantum_error(format!(
199+
"CY gate requires even number of qubits, got {}",
200+
cmd.qubits.len()
201+
)));
202+
}
203+
for qubits in cmd.qubits.chunks_exact(2) {
204+
debug!(
205+
"Processing CY gate with control {:?} and target {:?}",
206+
qubits[0], qubits[1]
207+
);
208+
self.simulator
209+
.cy(usize::from(qubits[0]), usize::from(qubits[1]));
210+
}
211+
}
212+
GateType::CZ => {
213+
if cmd.qubits.len() % 2 != 0 {
214+
return Err(quantum_error(format!(
215+
"CZ gate requires even number of qubits, got {}",
216+
cmd.qubits.len()
217+
)));
218+
}
219+
for qubits in cmd.qubits.chunks_exact(2) {
220+
debug!(
221+
"Processing CZ gate with control {:?} and target {:?}",
222+
qubits[0], qubits[1]
223+
);
224+
self.simulator
225+
.cz(usize::from(qubits[0]), usize::from(qubits[1]));
226+
}
227+
}
196228
GateType::RZZ => {
197229
if cmd.qubits.len() % 2 != 0 {
198230
return Err(quantum_error(format!(

crates/pecos-hugr/Cargo.toml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[package]
2+
name = "pecos-hugr"
3+
version.workspace = true
4+
edition.workspace = true
5+
readme.workspace = true
6+
authors.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
license.workspace = true
10+
keywords.workspace = true
11+
categories.workspace = true
12+
description = "Direct HUGR interpreter engine for PECOS quantum simulator"
13+
14+
[dependencies]
15+
# Logging
16+
log.workspace = true
17+
18+
# Error handling
19+
anyhow.workspace = true
20+
thiserror.workspace = true
21+
22+
# Serialization
23+
serde_json.workspace = true
24+
25+
# HUGR support
26+
tket.workspace = true
27+
28+
# Workspace dependencies
29+
pecos-core.workspace = true
30+
pecos-engines.workspace = true
31+
pecos-quantum = { workspace = true, features = ["hugr"] }
32+
33+
[dev-dependencies]
34+
tempfile.workspace = true
35+
# For creating test HUGRs from DagCircuit
36+
pecos-quantum = { workspace = true, features = ["hugr"] }
37+
# For integration testing with quantum simulator
38+
pecos-quest.workspace = true
39+
40+
[lints]
41+
workspace = true

0 commit comments

Comments
 (0)