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

[DAGCircuit Oxidation] Port DAGNode to Rust #12380

Merged
merged 10 commits into from May 14, 2024

Conversation

kevinhartman
Copy link
Contributor

Summary

Ports DAGNode and subclasses to Rust. This is precursory to writing efficient ports of methods on DAGCircuit in Rust, since we can avoid a lot of interpreter interaction.

Details and comments

Everything is ported over with the exception of semantic_eq, since its implementation has a lot of interplay with components that we currently must access through the Python interpreter (e.g. Expr, Parameter, registers, etc.).

@kevinhartman kevinhartman requested a review from a team as a code owner May 9, 2024 19:15
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

@kevinhartman kevinhartman added the Changelog: None Do not include in changelog label May 9, 2024
@coveralls
Copy link

coveralls commented May 9, 2024

Pull Request Test Coverage Report for Build 9068130816

Warning: 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

  • 184 of 203 (90.64%) changed or added relevant lines in 4 files are covered.
  • 84 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.05%) to 89.602%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/dagcircuit/dagnode.py 23 24 95.83%
crates/circuit/src/dag_node.rs 156 174 89.66%
Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py 1 99.11%
crates/qasm2/src/lex.rs 10 91.35%
qiskit/visualization/circuit/text.py 14 95.15%
qiskit/visualization/circuit/latex.py 16 92.9%
qiskit/transpiler/target.py 19 93.74%
crates/qasm2/src/parse.rs 24 96.23%
Totals Coverage Status
Change from base Build 9022222484: -0.05%
Covered Lines: 62285
Relevant Lines: 69513

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me, thanks for doing it! I mostly had comments about our pickle handling through these cases - I think there's a fair amount of places where we could entirely elide the __getstate__ and __setstate__ calls and do it all through __getnewargs__ (and some places where we're duplicating things already).

The other super minor point is whether you think it's worth deferring to Python-space formatting in __repr__ methods. It's not as fast, but if anything is bottlenecked on __repr__ we should probably make sure it isn't, and using the Python-space formatting means everything will be consistent no matter how deep or shallow in the object hierarchy a __repr__ is called.

crates/circuit/src/circuit_instruction.rs Outdated Show resolved Hide resolved
crates/circuit/src/dag_node.rs Outdated Show resolved Hide resolved
crates/circuit/src/dag_node.rs Show resolved Hide resolved
crates/circuit/src/dag_node.rs Show resolved Hide resolved
crates/circuit/src/dag_node.rs Outdated Show resolved Hide resolved
crates/circuit/src/dag_node.rs Show resolved Hide resolved
crates/circuit/src/dag_node.rs Outdated Show resolved Hide resolved
crates/circuit/src/dag_node.rs Outdated Show resolved Hide resolved
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

This looks fine to merge to me, thanks for the changes.

Just for visibility for anyone else looking: the three-tuple return from __reduce__ here where the callable is the Self type object can also be written as a __getnewargs__/__getstate__/__setstate__ triple, but the current way also works totally fine.

Comment on lines +34 to +40
fn __getstate__(&self) -> isize {
self._node_id
}

fn __setstate__(&mut self, nid: isize) {
self._node_id = nid;
}
Copy link
Member

Choose a reason for hiding this comment

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

Strictly these two could also be replaced with a __getnewargs__ as well, but it's unimportant - I wouldn't be surprised if they're never called at all, since I don't think we ever construct bare DAGNode.

@jakelishman jakelishman added this pull request to the merge queue May 14, 2024
@jakelishman jakelishman added Rust This PR or issue is related to Rust code in the repository mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels May 14, 2024
@jakelishman jakelishman added this to the 1.2.0 milestone May 14, 2024
Merged via the queue into Qiskit:main with commit 8985b24 May 14, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants