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

Remove idle wires by default when separating the circuit #594

Merged
merged 4 commits into from
May 29, 2024

Conversation

garrison
Copy link
Member

@garrison garrison commented May 18, 2024

Currently, if one has a 10-qubit circuit and only 2 qubits are used, then partition_problem will separate the input into 8 circuits that have a single unused qubit, plus one or two circuits (depending on connectivity) for the 2 qubits actually used. This changes the default to remove idle wires. It also means that the partition label of None will be treated specially (it can only be used on an idle wire).

Remaining action items

  • Elaborate on release note

@garrison garrison added enhancement New feature or request cutting QPD-based circuit cutting code labels May 18, 2024
@garrison garrison added this to the 0.8.0 milestone May 18, 2024
@garrison garrison self-assigned this May 18, 2024
@coveralls
Copy link

coveralls commented May 18, 2024

Pull Request Test Coverage Report for Build 9229938335

Details

  • 26 of 26 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 9225895876: 0.0%
Covered Lines: 2389
Relevant Lines: 2389

💛 - Coveralls

@garrison garrison requested a review from caleb-johnson May 24, 2024 21:07
@garrison garrison marked this pull request as ready for review May 24, 2024 21:07
qubit_subsets = [
subset
for subset in qubit_subsets
if not (len(subset) == 1 and next(iter(subset)) in idle_wires)
Copy link
Member Author

Choose a reason for hiding this comment

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

We have to use next(iter(subset)) here because that is the standard way to get the "first" element from a set.

"""

subcircuits: dict[Hashable, QuantumCircuit]
qubit_map: list[tuple[Hashable, int]]
qubit_map: list[tuple[Hashable, int] | tuple[None, None]]
Copy link
Member Author

@garrison garrison May 24, 2024

Choose a reason for hiding this comment

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

It turns out to be a lot easier to work with this if it's always a 2-tuple (which means you can always unpack it), which is which why I've used (None, None) instead of None.

j = circuit.find_bit(qubit).index
partition_id = qubit_map[j][0]
if partition_id is None:
raise ValueError(
Copy link
Collaborator

@caleb-johnson caleb-johnson May 29, 2024

Choose a reason for hiding this comment

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

Do you raise here because None is Hashable? Users could pass in a Sequence[None], and it would obey the Sequence[Hashable] type hint, but be an invalid input if the Nones were associated with active 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.

Do you raise here because None is technically Hashable? Users could pass in a Sequence[None], and it would obey the Sequence[Hashable] type hint, but be an invalid input?

Not quite; it's because a label of None means "this qubit should be idle," but if this code path is triggered, it's because there is an instruction that uses the qubit in the circuit (i.e., it's not actually idle).

I wonder if the error message (on the following lines) could be clarified in any way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I think it's a good message. This arises when a user passes None as a label for an active qubit, and I think that's clear here.

I guess what I was getting at is that the user passing None on an active qubit accidentally doesn't disobey the type hint, so raising a ValueError is appropriate.

Copy link
Collaborator

@caleb-johnson caleb-johnson 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 nice, thanks! 🚀

@garrison garrison merged commit df3d536 into main May 29, 2024
11 checks passed
@garrison garrison deleted the rm-idle-wires branch May 29, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cutting QPD-based circuit cutting code enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants