qudit_expr/library/
states.rs

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