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

Generate all configurations for a fragment tape #2169

Merged
merged 123 commits into from
Feb 18, 2022

Conversation

anthayes92
Copy link
Contributor

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.

anthayes92 and others added 30 commits January 17, 2022 15:25
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Comment on lines +385 to +404
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]
Copy link
Contributor

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.

Copy link
Contributor Author

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 👌

Copy link
Contributor

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.

) -> List[MeasurementProcess]:
"""Pairs each observable in ``group`` with the fixed circuit ``measurements``.

Only a single fixed measurement of an expectation value is currently supported.
Copy link
Contributor Author

@anthayes92 anthayes92 Feb 17, 2022

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... ?

Copy link
Contributor

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

anthayes92 and others added 2 commits February 17, 2022 09:38
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
@anthayes92 anthayes92 marked this pull request as ready for review February 17, 2022 15:41
Copy link
Contributor

@trbromley trbromley left a 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.

) -> List[MeasurementProcess]:
"""Pairs each observable in ``group`` with the fixed circuit ``measurements``.

Only a single fixed measurement of an expectation value is currently supported.
Copy link
Contributor

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

pennylane/transforms/qcut.py Outdated Show resolved Hide resolved
pennylane/transforms/qcut.py Outdated Show resolved Hide resolved
pennylane/transforms/qcut.py Outdated Show resolved Hide resolved
pennylane/transforms/qcut.py Outdated Show resolved Hide resolved
pennylane/transforms/qcut.py Outdated Show resolved Hide resolved
Comment on lines +496 to +500
n_meas = len(measure_nodes)
if n_meas >= 1:
measure_combinations = qml.grouping.partition_pauli_group(len(measure_nodes))
else:
measure_combinations = [[""]]
Copy link
Contributor

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

Comment on lines 1100 to 1101
Tests that a circuit with multiple MeasureNodes on a single wire gives
the correct measurements after expansion
Copy link
Contributor

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 🤔

Copy link
Contributor Author

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 Show resolved Hide resolved
Comment on lines 1174 to 1175
Tests that a circuit with multiple MeasureNodes on a single wire gives
the correct preparation after expansion
Copy link
Contributor

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

anthayes92 and others added 2 commits February 18, 2022 09:10
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
@anthayes92 anthayes92 merged commit e1b15d2 into master Feb 18, 2022
@anthayes92 anthayes92 deleted the sc-13396-a-user-can-generate-all-configurations-of branch February 18, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants