qudit_expr/library/
measurements.rs1use crate::BraSystemExpression;
2
3#[cfg_attr(feature = "python", pyo3::pyfunction)]
5#[cfg_attr(feature = "python", pyo3(signature = (radix = 2)))]
6pub fn ZMeasurement(radix: usize) -> BraSystemExpression {
7 let proto = format!("ZMeasurement<{}>()", radix);
8 let mut body = "".to_string();
9 body += "[";
10 for i in 0..radix {
11 body += "[[";
12 for j in 0..radix {
13 if i == j {
14 body += "1,";
15 } else {
16 body += "0,";
17 }
18 }
19 body += "]],";
20 }
21 body += "]";
22
23 BraSystemExpression::new(proto + "{" + &body + "}")
24}
25
26#[cfg(feature = "python")]
27mod python {
28 use super::*;
29 use crate::python::PyExpressionRegistrar;
30 use pyo3::prelude::*;
31
32 fn register(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
34 parent_module.add_function(wrap_pyfunction!(ZMeasurement, parent_module)?)?;
35 Ok(())
36 }
37 inventory::submit!(PyExpressionRegistrar { func: register });
38}