2
$\begingroup$

Do circuits that measure probabilities instead of expectation values benefit from parallel execution?

The Computing gradients in parallel with Amazon Braket tutorial shows how the multiple device executions required during gradient calculations can be performed in parallel on the remote Braket SV1 device. In Benchmarking circuit evaluation, a parametrized circuit which returns the expectation value of observables

import pennylane as qml
from pennylane import numpy as np

n_wires = 25

params = np.random.random(n_wires)
def circuit(params):
    for i in range(n_wires):
        qml.RX(params[i], wires=i)
    for i in range(n_wires):
        qml.CNOT(wires=[i, (i + 1) % n_wires])

    # Measure expectation value of observables
    observables = [qml.PauliZ(n_wires - 1)] + [qml.Identity(i) for i in range(n_wires - 1)]
    return qml.expval(qml.operation.Tensor(*observables))

is executed much faster in parallel on the remote SV1 than on the default.qubit device:

Execution time on remote device (seconds): 3.5898206680030853
Execution time on local device (seconds): 23.50668462700196

If you benchmark the same circuit but instead measure computational basis probabilities,

def circuit(params):
    for i in range(n_wires):
        qml.RX(params[i], wires=i)
    for i in range(n_wires):
        qml.CNOT(wires=[i, (i + 1) % n_wires])
    
    # Measure probability of each computational basis state
    return qml.probs(wires=range(n_wires))

the speed-up gained from parallel execution is lost, and the local device actually seems to greatly outperform the remote device in execution time. My suspicion is that this has to do with this measurement type requiring a value shots, while the former does not.

Can a model trained using a cost function that depends on computational basis probabilities benefit from parallel execution on a remote device? If not, is there any alternate way to speed up gradient calculations for circuits that use shots-based measurements?

$\endgroup$

1 Answer 1

0
$\begingroup$

As far as I know qml.probs should not affect batching gradients with PennyLane. Are you comparing AWS + parameter-shift to default.qubit + backprop? This could explain the discrepancy.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.