Generalize `CricuitGraph.iterate_parametrized_layers` regarding commuting gates.
See original GitHub issueFeature details
Currently, CircuitGraph.iterate_parametrized_layers will generate the layers such that no gates within a parametrized layer use any same qubit. Instead, one could consider commuting parametrized operations to belong to the same layer, for example in
def circuit(x, y):
qml.IsingXX(x, wires=[0, 1])
qml.IsingXX(x, wires=[1, 2])
qml.IsingYY(y, wires=[0, 1])
qml.IsingYY(y, wires=[1, 2])
the current functionality will produce four layers, whereas I suggest to consider the two IsingXX and the two IsingYY to belong to the same layer, respectively.
As far as I can tell, the only use of iterate_parametrized_layers currently is in metric_tensor, for which this change is intended, because it reduces the number of circuits while increasing the subset of tensor entries that can be computed, using the covariance matrix based method.
This cost reduction propagates through to the new Hadamard-test based metric tensor, because it computes the block diagonal using the covariance approach.
Implementation
This is non-trivial to do if we want to support all gates optimally, I think.
How important would you say this feature is?
1: Not important. Would be nice to have.
Additional information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
This really makes me cringe 😬 but: #295 introduced the
CircuitGraph(including the layer iteration algorithm), the metric tensor, the QNG optimizer, and theOperator.generatorattribute… all at once 😬 😬I have a feeling it was added for something else prior to the metric tensor 😆 But I can’t recall what.