Skip to content

Return more info about circuit separation during partitioning#304

Open
caleb-johnson wants to merge 11 commits intomainfrom
cut-info
Open

Return more info about circuit separation during partitioning#304
caleb-johnson wants to merge 11 commits intomainfrom
cut-info

Conversation

@caleb-johnson
Copy link
Copy Markdown
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
bases = []
i = 0
for inst in qpd_circuit.data:
if isinstance(inst.operation, SingleQubitQPDGate):
Copy link
Copy Markdown
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

subcircuits, cuts, subobservables = partition_problem(
circuit=circuit, partition_labels="AABB", observables=observables
)
bases = [cut_info.basis for cut_info in cuts]
Copy link
Copy Markdown
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
Copy Markdown

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 requested a review from garrison July 3, 2023 23:17
@caleb-johnson caleb-johnson marked this pull request as ready for review July 3, 2023 23:19
@caleb-johnson
Copy link
Copy Markdown
Collaborator Author

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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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