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

NoiseAdaptiveLayout to consider inconsistencies in backend #10859

Merged
merged 9 commits into from
Oct 17, 2023

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Sep 18, 2023

Fixes #7677

The pass NoiseAdaptiveLayout now takes a CouplingMap as an optional argument. This is used by the plugin to control on configuration/properties inconsistency, like in the case of FakeMelbourne

@1ucian0 1ucian0 requested a review from a team as a code owner September 18, 2023 20:43
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link

Pull Request Test Coverage Report for Build 6227804167

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.008%) to 87.284%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 91.41%
qiskit/pulse/library/waveform.py 3 93.75%
Totals Coverage Status
Change from base Build 6209701566: 0.008%
Covered Lines: 74192
Relevant Lines: 85001

💛 - Coveralls

@1ucian0 1ucian0 added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Sep 19, 2023
@1ucian0 1ucian0 added this to the 0.45.0 milestone Sep 19, 2023
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

At a high level this looks fine to me. Just a couple small inline comments about some implementation details.

"""NoiseAdaptiveLayout initializer.

Args:
backend_prop (Union[BackendProperties, Target]): backend properties object
coupling_map (CouplingMap): Optional. To filter the backend_prop qubits/gates.
Copy link
Member

Choose a reason for hiding this comment

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

I would add a note here that this argument is ignored if backend_prop is a Target object and this is only needed to deal with inconsistencies in BackendProperties objects.

Copy link
Member Author

@1ucian0 1ucian0 Oct 16, 2023

Choose a reason for hiding this comment

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

Extending it in 29bc007

# inconsistency internally). For the non-target path, this is a possible solution.
# See https://github.com/Qiskit/qiskit/issues/7677
self.backend_prop.gates = filter(
lambda ginfo: ginfo.gate == "cx"
Copy link
Member

Choose a reason for hiding this comment

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

What about backends that use different entangling gates besides cx?

Copy link
Member Author

@1ucian0 1ucian0 Oct 16, 2023

Choose a reason for hiding this comment

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

i think the pass is already cx-specific

. But it is easy to fix by just removing that condition, in 6d9c214

# See https://github.com/Qiskit/qiskit/issues/7677
self.backend_prop.gates = filter(
lambda ginfo: ginfo.gate == "cx"
and tuple(ginfo.qubits) in coupling_map.graph.edge_list(),
Copy link
Member

Choose a reason for hiding this comment

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

For performance it might make sense to collect the edge_list into a set(). Event though edge_list() returns a rust container it's a sequence type based on a rust Vec, so there is an O(n^2) overhead here because we're iterating over all edges for each edge in the backend.

Copy link
Member Author

@1ucian0 1ucian0 Oct 16, 2023

Choose a reason for hiding this comment

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

Good call! easy optimization 1e52ac8

and tuple(ginfo.qubits) in coupling_map.graph.edge_list(),
backend_prop.gates,
)
self.backend_prop.qubits = backend_prop.qubits[
Copy link
Member

Choose a reason for hiding this comment

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

Does this modify the BackendProperties object for other passes that are using it, do we need a copy here before modifying? For the default preset pass managers, I don't think it really matters because the only things after this that access the backend properties are potentially VF2PostLayout, Optimize1qGatesDecomposition, and UnitarySynthesis (I might have missed one from memory) and those only look up error rates in the properties.

Copy link
Member Author

@1ucian0 1ucian0 Oct 16, 2023

Choose a reason for hiding this comment

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

Good point. I made the copy only under this condition, so I dont penalize the most general case. Done in 1a375df


result = transpile(qc, backend, layout_method="noise_adaptive", optimization_level=level)

self.assertIsInstance(result, QuantumCircuit)
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to assert anything about the properties of the output circuit, like number of qubits?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. I did the same with test_no_coupling_map in this very same file in 960c20c

mtreinish
mtreinish previously approved these changes Oct 16, 2023
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the updates

@mtreinish mtreinish added this pull request to the merge queue Oct 16, 2023
Merged via the queue into Qiskit:main with commit 458ad13 Oct 17, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NoiseAdaptiveLayout cannot handle inconsistent properties/configuration (like in FakeMelbourne)
4 participants