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

Return more info about circuit separation during partitioning #304

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

caleb-johnson
Copy link
Collaborator

@caleb-johnson caleb-johnson commented Jul 3, 2023

This is the first step toward supporting an easier interface for updating parameters associated with cut gates.

In the current cutting partitioning workflow, users are returned a dictionary of subcircuits as well as the bases associated with each unique cut. Instead of only returning the bases, we should return which gates in which subcircuits each of the bases are associated with.

Once this information is available from partition_problem, implementing functions for manipulating the QPD gates in circuits will be more straightforward.

I have also (hopefully) improved the type hinting. Only the functions which require the keys be sorted call for str | int in their type hints, and the others just expect Hashable.

This is currently implemented as a breaking change, as the PartitionedCuttingProblem.bases field is now the cuts field. Users should access the bases via the new field. Maybe we'd rather deprecate the old field. I don't really think it's necessary but am open to it

@caleb-johnson caleb-johnson marked this pull request as draft July 3, 2023 22:39
@@ -221,14 +229,28 @@ def partition_problem(
bases = []
i = 0
for inst in qpd_circuit.data:
if isinstance(inst.operation, SingleQubitQPDGate):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We probably want to support these for wire cutting, but they are not well-handled as of this PR, so this ValueError is appropriate. We can remove it for the wire cutting PR, if necessary

circuit=circuit, partition_labels="AABB", observables=observables
)
bases = [cut_info.basis for cut_info in cuts]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This PR is a breaking change, users now need to get each basis from the CutInfo object

@github-actions
Copy link

github-actions bot commented Jul 3, 2023

Pull Request Test Coverage Report for Build 5467281062

  • 19 of 19 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 90.139%

Totals Coverage Status
Change from base Build 5433896893: 0.1%
Covered Lines: 2395
Relevant Lines: 2657

💛 - Coveralls

@caleb-johnson caleb-johnson marked this pull request as ready for review July 3, 2023 23:19
@caleb-johnson
Copy link
Collaborator Author

@garrison any comment on breaking change vs deprecating the old field?

@@ -72,7 +72,7 @@ def reconstruct_expectation_values(
for label, subobservable in observables.items():
if any(obs.phase != 0 for obs in subobservable):
raise ValueError("An input observable has a phase not equal to 1.")
subobservables_by_subsystem = observables
subobservables_by_subsystem = observables # type: ignore
Copy link
Collaborator Author

@caleb-johnson caleb-johnson Jul 4, 2023

Choose a reason for hiding this comment

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

I believe this is a false positive from mypy. The variable is a dict[Hashable, Any], and the expression is a dict[str | int, Any]. I believe the expression type lies in a subset of the variable type, which should be fine.

Copy link
Member

@garrison garrison Jul 5, 2023

Choose a reason for hiding this comment

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

https://mypy.readthedocs.io/en/stable/generics.html#variance-of-generic-types explains why dict is considered an invariant type rather than a covariant type. But yes, I think ignoring this type check makes the most sense for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cool, since this is technically correct, this means we have "correct" type hints with respect to Hashable and str | int. All the functions correctly indicate what functionality they expect

@garrison garrison added the cutting QPD-based circuit cutting code label Jul 5, 2023
@caleb-johnson caleb-johnson added the on hold Let's wait for something before merging label Jul 10, 2023
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 on hold Let's wait for something before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants