[BUG]qnode execution on simulators slows down with increasing commuting Hamiltonian terms
See original GitHub issueExpected behavior
With compute_grouping I would expect the following two qnodes, circuit() and circuit2(), to have similar execution time.
import pennylane as qml
from pennylane import numpy as np
import time
n_qubits = 15
H_quad = 0 * qml.PauliZ(0)
for i in range(n_qubits):
for j in range(i + 1, n_qubits):
H_quad += qml.PauliZ(i) @ qml.PauliZ(j)
H_quad.compute_grouping()
H_lin = 0 * qml.PauliZ(0)
for i in range(n_qubits):
H_lin += qml.PauliZ(i)
H_lin.compute_grouping()
dev = qml.device("lightning.qubit", wires=n_qubits, shots=1000)
@qml.qnode(dev)
def circuit():
for w in range(n_qubits):
qml.Hadamard(wires=w)
return qml.expval(H_quad)
@qml.qnode(dev)
def circuit2():
for w in range(n_qubits):
qml.Hadamard(wires=w)
return qml.expval(H_lin)
start = time.time()
circuit()
end = time.time()
print(f"qnode with quadratic terms: {end - start}s")
start = time.time()
circuit2()
end = time.time()
print(f"qnode with linear terms: {end - start}s")
Actual behavior
The qnode with quadratic terms executes significantly slower. Printed result from the code above:
qnode with quadratic terms: 0.8156991004943848s
qnode with linear terms: 0.004673004150390625s
Additional information
The observation holds for both default.qubit and lightning.qubit.
Source code
No response
Tracebacks
No response
System information
Name: PennyLane
Version: 0.22.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /home/ec2-user/anaconda3/envs/Braket/lib/python3.7/site-packages
Requires: semantic-version, autograd, appdirs, numpy, autoray, pennylane-lightning, scipy, toml, cachetools, networkx, retworkx
Required-by: PennyLane-Qchem, PennyLane-Lightning, amazon-braket-pennylane-plugin
Platform info: Linux-4.14.252-131.483.amzn1.x86_64-x86_64-with-glibc2.17
Python version: 3.7.13
Numpy version: 1.19.2
Scipy version: 1.5.2
Installed devices:
- default.gaussian (PennyLane-0.22.0)
- default.mixed (PennyLane-0.22.0)
- default.qubit (PennyLane-0.22.0)
- default.qubit.autograd (PennyLane-0.22.0)
- default.qubit.jax (PennyLane-0.22.0)
- default.qubit.tf (PennyLane-0.22.0)
- default.qubit.torch (PennyLane-0.22.0)
- lightning.qubit (PennyLane-Lightning-0.23.0)
- braket.aws.qubit (amazon-braket-pennylane-plugin-1.6.5)
- braket.local.qubit (amazon-braket-pennylane-plugin-1.6.5)
Existing GitHub issues
- I have searched existing GitHub issues to make sure the issue does not already exist.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@Jaybsoni Hi Jay. Thanks for investigating. For 1, I am even wondering if resolving this issue could improve the overall QAOA ansatz layer execution efficiency (not limited to the measurement). Keep me posted!
Hi @duanyh12,
Great suggestion! Yes, Identity operators will commute with every other observable so we shouldn’t have to worry about them in these qwc checks. I think we can actually further build on this idea to get an even better boost in performance. Here is a new feature request I have created where we can discuss how to further improve the performance