-
Notifications
You must be signed in to change notification settings - Fork 586
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
Generate all configurations for a fragment tape #2169
Generate all configurations for a fragment tape #2169
Conversation
…ithub.com:PennyLaneAI/pennylane into sc-13390-a-user-can-convert-a-tape-to-an-accurate
…stateprep conversion logic
…ithub.com:PennyLaneAI/pennylane into sc-13390-a-user-can-convert-a-tape-to-an-accurate
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
n_measurements = len(measurements) | ||
if n_measurements > 1: | ||
raise ValueError( | ||
"The circuit cutting workflow only supports circuits with a single output " | ||
"measurement" | ||
) | ||
if n_measurements == 0: | ||
return [expval(g) for g in group] | ||
|
||
measurement = measurements[0] | ||
|
||
if measurement.return_type is not Expectation: | ||
raise ValueError( | ||
"The circuit cutting workflow only supports circuits with expectation " | ||
"value measurements" | ||
) | ||
|
||
obs = measurement.obs | ||
|
||
return [expval(obs @ g) for g in group] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anthayes92 - this is a simplified version of what we had before. I recall some of the complexity of the prototype implementation came from a potential bug in PennyLane where the order of observables composing a tensor product resulted in different results. I propose that, for now, we keep the simple version above and see if the potential bug surfaces as we add some integration tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the addition and the explanation! This sounds like a sensible approach to me. Is this bug known and was there an issue raised for the bug?
The above seems to work well with the current unit tests 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this bug known and was there an issue raised for the bug?
Trying to remember back - I wasn't sure exactly what was going on, and it could have been a bug in PL or in the prototype implementation. But yes I wouldn't say it's a well defined bug at this stage, and there isn't an issue. I'm sure we'll find it though when we get to the integration tests.
…github.com:PennyLaneAI/pennylane into sc-13396-a-user-can-generate-all-configurations-of
…github.com:XanaduAI/pennylane into sc-13396-a-user-can-generate-all-configurations-of
pennylane/transforms/qcut.py
Outdated
) -> List[MeasurementProcess]: | ||
"""Pairs each observable in ``group`` with the fixed circuit ``measurements``. | ||
|
||
Only a single fixed measurement of an expectation value is currently supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a "fixed" circuit measurement, fixed as opposed to... ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as in the measurements of the original circuit, rather than the product of Pauli terms
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @anthayes92, looks great - approved! I left a few suggestions.
pennylane/transforms/qcut.py
Outdated
) -> List[MeasurementProcess]: | ||
"""Pairs each observable in ``group`` with the fixed circuit ``measurements``. | ||
|
||
Only a single fixed measurement of an expectation value is currently supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as in the measurements of the original circuit, rather than the product of Pauli terms
n_meas = len(measure_nodes) | ||
if n_meas >= 1: | ||
measure_combinations = qml.grouping.partition_pauli_group(len(measure_nodes)) | ||
else: | ||
measure_combinations = [[""]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update this when we merge in #2192
tests/transforms/test_qcut.py
Outdated
Tests that a circuit with multiple MeasureNodes on a single wire gives | ||
the correct measurements after expansion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The circuit below doesn't have multiple MeasureNodes
on the same wire 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good point, this is a fragment that results from multiple WireCuts on a single wire, will adjust this docstring.
tests/transforms/test_qcut.py
Outdated
Tests that a circuit with multiple MeasureNodes on a single wire gives | ||
the correct preparation after expansion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe update, it's mentioning MeasureNodes
here
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Context:
In the circuit cutting pipeline, once the graph representing the circuit has been partitioned into subgraphs and the subgraphs have been converted to tapes representing circuit fragments, it is necessary to implement the physical measurements and state preparations that will allow us to execute the individual fragments and recombine the output. This is achieved here through use of the Paul basis.
Description of the Change:
A method has been added to expand a fragment tape into a tape for each configuration.
Benefits:
Facilitates the circuit cutting compiler.
Possible Drawbacks:
Only supports expectation values and Pauli basis.