Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the qargs temporary state for SparseObservable #13391

Open
jakelishman opened this issue Nov 1, 2024 · 0 comments
Open

Implement the qargs temporary state for SparseObservable #13391

jakelishman opened this issue Nov 1, 2024 · 0 comments
Labels
mod: quantum info Related to the Quantum Info module (States & Operators) type: feature request New feature or request
Milestone

Comments

@jakelishman
Copy link
Member

What should we add?

Most quantum_info operators, including SparsePauliOp, have a qargs argument in several of their mathematical methods, and have a __call__ method that creates a shallow copy of the SparsePauliOp with the qargs temporarily set, for use with the Python binary operators (like +). The Python version of SparseObservable should also gain this functionality.

A qargs keyword argument to certain methods is straightforwards enough. Making the shallow-copy-on-__call__ behaviour is more challenging because the data is owned by Rust, and can't be easily shared like it can in Python. Likely we will want to make an entirely clean split between the Rust-space SparseObservable and the Python-exposed version (which I'll call PySparseObservable, but its Python name will also be SparseObservable) that contains something like an Arc<RwLock<SparseObservable>> and whatever shallow additional Python state we want. Something like:

// The same as it is now.  *Not* a pyclass.
pub struct SparseObservable {
    num_qubits: u32,
    coeffs: Vec<Complex64>,
    bit_terms: Vec<BitTerm>,
    indices: Vec<u32>,
    boundaries: Vec<usize>,
}
impl SparseObservable {
    // All the actual worker methods on the struct.
}

#[pyclass(name="SparseObservable")]
struct PySparseObservable {
    inner: Arc<RwLock<SparseObservable>>,
    qargs: Option<Vec<u32>>,
}
#[pymethods]
impl PySparseObservable {
    // All the Python methods.  These should generally be thin wrappers around proper
    // `SparseObservable` Rust-space methods, and the pymethods only handle interaction
    // with Python.
}
@jakelishman jakelishman added mod: quantum info Related to the Quantum Info module (States & Operators) type: feature request New feature or request labels Nov 1, 2024
@jakelishman jakelishman added this to the 2.0.0 milestone Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: quantum info Related to the Quantum Info module (States & Operators) type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant