Skip to content

Commit

Permalink
Refactoring: CliffordGateable
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranra committed Dec 21, 2024
1 parent 0cade4c commit e39cf4c
Show file tree
Hide file tree
Showing 11 changed files with 669 additions and 614 deletions.
68 changes: 42 additions & 26 deletions crates/pecos-python/src/sparse_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,48 @@ impl SparseSim {
self.inner.szdg(location);
Ok(None)
}
"MZ" | "MX" | "MY" | "MZForced" | "PZ" | "PX" | "PY" | "PZForced" | "PnZ" | "PnX"
| "PnY" => {
let (result, _) = match symbol {
"PZ" => {
self.inner.pz(location);
Ok(None)
}
"PX" => {
self.inner.px(location);
Ok(None)
}
"PY" => {
self.inner.py(location);
Ok(None)
}
"PnZ" => {
self.inner.pnz(location);
Ok(None)
}
"PnX" => {
self.inner.pnx(location);
Ok(None)
}
"PnY" => {
self.inner.pny(location);
Ok(None)
}
"PZForced" => {
let forced_value = params
.ok_or_else(|| {
PyErr::new::<pyo3::exceptions::PyValueError, _>("PZForced requires params")
})?
.get_item("forced_outcome")?
.ok_or_else(|| {
PyErr::new::<pyo3::exceptions::PyValueError, _>(
"PZForced requires a 'forced_outcome' parameter",
)
})?
.call_method0("__bool__")?
.extract::<bool>()?;
self.inner.pz_forced(location, forced_value);
Ok(None)
}
"MZ" | "MX" | "MY" | "MZForced" => {
let result = match symbol {
"MZ" => self.inner.mz(location),
"MX" => self.inner.mx(location),
"MY" => self.inner.my(location),
Expand All @@ -156,29 +195,6 @@ impl SparseSim {
.extract::<bool>()?;
self.inner.mz_forced(location, forced_value)
}
"PZ" => self.inner.pz(location),
"PX" => self.inner.px(location),
"PY" => self.inner.py(location),
"PZForced" => {
let forced_value = params
.ok_or_else(|| {
PyErr::new::<pyo3::exceptions::PyValueError, _>(
"PZForced requires params",
)
})?
.get_item("forced_outcome")?
.ok_or_else(|| {
PyErr::new::<pyo3::exceptions::PyValueError, _>(
"PZForced requires a 'forced_outcome' parameter",
)
})?
.call_method0("__bool__")?
.extract::<bool>()?;
self.inner.pz_forced(location, forced_value)
}
"PnZ" => self.inner.pnz(location),
"PnX" => self.inner.pnx(location),
"PnY" => self.inner.pny(location),
_ => unreachable!(),
};
Ok(Some(u8::from(result)))
Expand Down
1 change: 0 additions & 1 deletion crates/pecos-qsim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ num-complex = { workspace = true }

[lints]
workspace = true

Loading

0 comments on commit e39cf4c

Please sign in to comment.