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

List support for coupling map in pass manager #11063

Merged
merged 5 commits into from
Oct 20, 2023

Conversation

SimonR99
Copy link
Contributor

Summary

Fixes #10920

Details and comments

The preset pass manager previously only allowed the user to provide a coupling map as an object, not as a list. Since the creation of a coupling map is typically a straightforward process, it makes sense to allow users to directly input the list into the preset pass manager generator. This is what this PR is about.

Example :
pm = generate_preset_pass_manager(basis_gates = ['cz', 'sx', 'rz'], coupling_map =[[0,1], [1,2]], optimization_level=3)

@SimonR99 SimonR99 requested a review from a team as a code owner October 20, 2023 04:00
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Oct 20, 2023
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Qiskit/terra-core

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.

Thanks for this! Please could you also add a "feature" release note (reno new --edit preset-passmanager-coupling-map) with a line saying that generate_preset_pass_manager now accepts anything that can be coerced to CouplingMap?

Comment on lines 217 to 223
if (
coupling_map
and isinstance(coupling_map, list)
and all(isinstance(sublist, list) for sublist in coupling_map)
):
coupling_map = CouplingMap(coupling_map)

Copy link
Member

Choose a reason for hiding this comment

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

we can probably do

Suggested change
if (
coupling_map
and isinstance(coupling_map, list)
and all(isinstance(sublist, list) for sublist in coupling_map)
):
coupling_map = CouplingMap(coupling_map)
if coupling is not None and not isinstance(coupling_map, CouplingMap):
coupling_map = CouplingMap(coupling_map)

because the CouplingMap constructor will already have to validate its input, which would just be duplicated and liable to get out-of-sync with this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks!

Comment on lines 1469 to 1472

# Convert the transpiled circuits to DAGs to compare the states
dag_list = circuit_to_dag(transpiled_circuit_list)
dag_object = circuit_to_dag(transpiled_circuit_object)
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but we don't really need to bother with the conversion; we can assertEqual(transpiled_circuit_list, transpiled_circuit_object) and it'll work just as well (and give a better error message on failure).

Copy link
Contributor Author

@SimonR99 SimonR99 Oct 20, 2023

Choose a reason for hiding this comment

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

Good, I made the change. I thought it would be good practice since the pass manager doesn't consistently produce the same result. However, this shouldn't be a problem for the test circuit.

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.

Oh, the not-the-same output is most likely because we've not set seed_transpiler in the generate_preset_pass_manager - good spot on that. If you set that to the same value, they should always come out the same. The QuantumCircuit equality check actually just delegates to the DAGCircuit one internally, so they're the same, but we have a special hook in QiskitTestCase to make it so that assertEqual draws the circuits in the error message if they both come in as QuantumCircuit.

I think you've ended up with two release notes files here - could you clear out the extra one (-b4f2f0ed...)? Other than that, this is ready to go thanks.

@SimonR99
Copy link
Contributor Author

Thanks for the guidance and clarification!

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.

Thanks for the quick changes! I pushed a little fix up to the release note to add Sphinx cross-references to various objects, and to highlight that the allowed formats are more legacy-related.

@jakelishman jakelishman changed the title List support for coupling map in pass manager (#10920) List support for coupling map in pass manager Oct 20, 2023
@jakelishman jakelishman added this pull request to the merge queue Oct 20, 2023
@jakelishman jakelishman added this to the 1.0.0pre1 milestone Oct 20, 2023
Merged via the queue into Qiskit:main with commit 828f654 Oct 20, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

using the preset pass managers
3 participants