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

Add Expr support to DAGCircuit.compose #10377

Merged
merged 2 commits into from
Jul 19, 2023

Conversation

jakelishman
Copy link
Member

Summary

The remapping facilities are (except for some esoteric behaviour for mapping registers to others in a different order) the same as for QuantumCircuit, so it makes sense to unify the handling. As part of switching the old DAGCircuit classical-resource-mapping methods over to the new general-purpose forms, this does most of the necessary work to upgrade substitute_node_with_dag as well.

Details and comments

Resolve #10230. Depends on #10375 (since I elected to generalise some of the new handling from that PR). Changelog in #10331.

@jakelishman jakelishman added the Changelog: New Feature Include in the "Added" section of the changelog label Jul 4, 2023
@jakelishman jakelishman added this to the 0.25.0 milestone Jul 4, 2023
@jakelishman jakelishman requested a review from a team as a code owner July 4, 2023 00:14
@qiskit-bot
Copy link
Collaborator

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

@coveralls
Copy link

coveralls commented Jul 4, 2023

Pull Request Test Coverage Report for Build 5602299220

  • 77 of 85 (90.59%) changed or added relevant lines in 3 files are covered.
  • 22 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.02%) to 86.057%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/dagcircuit/dagcircuit.py 9 10 90.0%
qiskit/circuit/_classical_resource_map.py 66 73 90.41%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 1 90.33%
crates/qasm2/src/lex.rs 2 91.39%
crates/qasm2/src/parse.rs 18 96.65%
Totals Coverage Status
Change from base Build 5601185466: -0.02%
Covered Lines: 72701
Relevant Lines: 84480

💛 - Coveralls

The remapping facilities are (except for some esoteric behaviour for
mapping registers to others in a different order) the same as for
`QuantumCircuit`, so it makes sense to unify the handling.  As part of
switching the old `DAGCircuit` classical-resource-mapping methods over
to the new general-purpose forms, this does most of the necessary work
to upgrade `substitute_node_with_dag` as well.
@jakelishman
Copy link
Member Author

Now rebased over main.

@jakelishman jakelishman removed the on hold Can not fix yet label Jul 19, 2023
Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

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

LGTM, one minor comment.

Comment on lines 34 to 37
If an ``add_register`` callable is given to the initialiser, the mapper will use it to attempt
to add new aliasing registers to the outer circuit object, if there is not already a suitable
register for the mapping available in the circuit. If this parameter is not given, the mapping
function will raise an exception of type ``exc_type`` instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we instead just leave it up to the caller to throw their own exception from the add_register callable they pass in?

It looks like we only use this once in DAGCircuit, and IMO the extra parameter (and thusly required defaulting) and docstring aren't worth it given that this is a private interface.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that sounds reasonable. Doing that marginally compromises the available error message (since you don't get the original register), but it's probably not so important. I've done a version of this in 591cbaa.

Instead, we just delegate this down to a passed-in `add_register`, if
desired.  It marginally compromises the error messages that might be
emitted, but those are paths that we're hope to reduce use of anyway.
@kevinhartman kevinhartman added this pull request to the merge queue Jul 19, 2023
Merged via the queue into Qiskit:main with commit 4a758b6 Jul 19, 2023
@jakelishman jakelishman deleted the expr/dag-compose branch July 19, 2023 21:18
to24toro pushed a commit to to24toro/qiskit-terra that referenced this pull request Aug 3, 2023
* Add `Expr` support to `DAGCircuit.compose`

The remapping facilities are (except for some esoteric behaviour for
mapping registers to others in a different order) the same as for
`QuantumCircuit`, so it makes sense to unify the handling.  As part of
switching the old `DAGCircuit` classical-resource-mapping methods over
to the new general-purpose forms, this does most of the necessary work
to upgrade `substitute_node_with_dag` as well.

* Remove `exc_type` argument from `VariableMapper`

Instead, we just delegate this down to a passed-in `add_register`, if
desired.  It marginally compromises the error messages that might be
emitted, but those are paths that we're hope to reduce use of anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Expr values to DAGCircuit.compose
5 participants