-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 num_qubits
and num_clbits
in Rust
#12495
Conversation
* QuantumCircuit.num_qubits and num_clbits are twice as fast after this PR. * These are used in several places. For example QuantumCircuit.width() is three times faster. * num_qubits and num_clbits are introduced in circuit_data.rs. These functions are called by the corresponding Python methods. They are also used in circuit_data.rs itself.
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 9371133565Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, in general as the source of truth moves more to the rust side I think this is fine.
There is an open question about a rust native representation of bits after #12459 but in the meantime asserting the bit pyobject vec in the circuit data is the source of truth seems fine to me (which this PR is doing implicitly), especially once we move to the gate representation being owned by the rust domain.
@@ -220,6 +220,11 @@ impl CircuitData { | |||
self.qubits.clone_ref(py) | |||
} | |||
|
|||
#[getter] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to throw a docstring on this and the other new methods just for completeness? While we don't publish docs for this as a pyclass (since it's internal only), it sometimes is a nice hint for people using IDEs that show the __doc__
attribute of a python class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah. I forgot to add some of this when I moved it out of draft.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 2ffac76
It wasn't 100% clear to me that qiskit/crates/circuit/src/circuit_data.rs Lines 151 to 152 in 797bb28
made it seem more likely.
Unfortunately, I expect there will be a lot of churn like this is gradually moving things to Rust. But this PR is pretty light in terms of changed code, so not too onerous to replace. |
My mistake tou're right it already is, I was misremembering the state of the code. The Python side |
self.clbits_native.len() | ||
} | ||
|
||
pub fn width(&self) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing a docstring too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here 16755cd
* Implement num_qubits and num_clbits in Rust * QuantumCircuit.num_qubits and num_clbits are twice as fast after this PR. * These are used in several places. For example QuantumCircuit.width() is three times faster. * num_qubits and num_clbits are introduced in circuit_data.rs. These functions are called by the corresponding Python methods. They are also used in circuit_data.rs itself. * Add doc strings for rust implemented num_qubits and num_clbits * Add doc string for `width` in Rust
* Implement num_qubits and num_clbits in Rust * QuantumCircuit.num_qubits and num_clbits are twice as fast after this PR. * These are used in several places. For example QuantumCircuit.width() is three times faster. * num_qubits and num_clbits are introduced in circuit_data.rs. These functions are called by the corresponding Python methods. They are also used in circuit_data.rs itself. * Add doc strings for rust implemented num_qubits and num_clbits * Add doc string for `width` in Rust
QuantumCircuit.num_qubits
andnum_clbits
are twice as fast after this PR.QuantumCircuit.width()
is three times faster.num_qubits
andnum_clbits
are introduced in circuit_data.rs. These functions are called by the corresponding Python methods. They are also used in circuit_data.rs itself.