Skip to content

Add Observables#10

Merged
raynelfss merged 18 commits into
mainfrom
add-qk-obs
May 4, 2026
Merged

Add Observables#10
raynelfss merged 18 commits into
mainfrom
add-qk-obs

Conversation

@emilkovacev
Copy link
Copy Markdown
Member

@emilkovacev emilkovacev commented Nov 17, 2025

emilkovacev and others added 3 commits January 10, 2026 14:03
* Also moves assertions from indices and coeffs doctests into tests
@mrossinek
Copy link
Copy Markdown
Member

Would it make sense to conditionally include a wrapper for this once we have #22?

@emilkovacev
Copy link
Copy Markdown
Member Author

emilkovacev commented Jan 26, 2026

Would it make sense to conditionally include a wrapper for this once we have #22?

I'm happy to include it in this PR as a regular method rather than having a conditional wrapper, if that is helpful for completing the python bindings feature.

@mrossinek
Copy link
Copy Markdown
Member

Would it make sense to conditionally include a wrapper for this once we have #22?

I'm happy to include it in this PR as a regular method rather than having a conditional wrapper, if that is helpful for completing the python bindings feature.

I think, if it is to be included, it should be placed behind a feature flag to avoid depending on pyo3 unconditionally.

@emilkovacev emilkovacev marked this pull request as ready for review April 13, 2026 00:47
@emilkovacev emilkovacev requested a review from mtreinish April 22, 2026 19:55
@emilkovacev emilkovacev assigned raynelfss and unassigned raynelfss Apr 22, 2026
@emilkovacev emilkovacev requested a review from raynelfss April 22, 2026 19:55
Copy link
Copy Markdown
Collaborator

@raynelfss raynelfss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a brief look at the code. It looks good but I have some comments.

Comment thread src/qiskit.rs Outdated
}
}

/// An observable over Pauli bases that stores its data in a qubit-sparse format.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sufficient for now but we should have a conversation as to how much documentation do we want to include for structures like these.

Comment thread src/qiskit.rs

#[derive(Clone, Copy, PartialEq, Debug)]
#[repr(u8)]
pub enum BitTerm {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may also benefit from some documentation. I also wonder if there is a way of automatically generating the bindings for C-enumerations into Rust bindings.

I know we were having issues with that before but I wonder if we could explore that again.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this very briefly, we could maybe implement https://docs.rs/bindgen/latest/bindgen/callbacks/trait.ParseCallbacks.html#method.item_name for bindgen in qiskit-sys? This may reduce the overhead in creating and maintaining all these enum mappings and structures.

I think this is out of scope of this PR, but happy to open an issue to investigate.

Comment thread src/qiskit.rs
Comment thread src/qiskit.rs Outdated
Comment thread src/qiskit.rs Outdated
Comment thread src/qiskit.rs
}

/// A complex, double-precision number representation.
pub type Complex64 = qiskit_sys::QkComplex64;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one thing I'm not sure should be brought over as is from C. Rust has its own implementation of Complex64, we could perhaps implement From for a wrapper over this. But then again, I can see how this is utterly complex as you'd have to constantly go from one abstraction to the other, but I don't believe it is a costly operation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to find an implementation of complex numbers in the rust standard library, is there an external crate typically used for this?

As for QkComplex64, my opinion is that the structure is sufficient for this use case, the rust struct generated is fairly simple:

pub struct QkComplex64 {
    #[doc = "````ignore\n The real part.\n````"]
    pub re: f64,
    #[doc = "````ignore\n The imaginary part.\n````"]
    pub im: f64,
}

Still, I'm not super familiar with rust, so if there is a standard library I'm missing, or a crate that would be more appropriate, happy to move it!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I misspoke. Rust doesn't have a native implementation for complex numbers. I believe that for Qiskit we used the num_complex trait to represent complex numbers.

That said, we could have methods and functions that accept complex numbers receive Complex64 and then perform the conversion internally. The purpose would be to use rust-y types instead of creating our own representations for every binding. But again, that is something we can discuss further.

Comment thread src/qiskit.rs Outdated
Comment thread src/qiskit.rs Outdated
Copy link
Copy Markdown
Collaborator

@raynelfss raynelfss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about ready to merge, just a couple more comments.

Comment thread src/qiskit.rs Outdated
Comment thread src/qiskit.rs Outdated
Comment thread src/qiskit.rs
@emilkovacev emilkovacev requested a review from raynelfss April 26, 2026 04:54
@raynelfss raynelfss added this pull request to the merge queue May 4, 2026
Merged via the queue into main with commit bc24bd7 May 4, 2026
2 checks passed
@raynelfss raynelfss deleted the add-qk-obs branch May 4, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add API for QkObs

3 participants