Open cvjjm opened 11 months ago
Thanks for opening the issue @cvjjm . Which device are you using?
Calling split_non_commuting
is the responsibility of the device.
Our new default qubit, accessible from master as qml.device('default.qubit')
and accessible on the latest release as qml.devices.experimental.DefaultQubit()
, can simultaneously handle any number of commuting and non-commuting measurements and does not call split_non_commuting
.
If you are using your own device, you can override Device.batch_transform
to avoid calling split_non_commuting
. If you are using a different device, you may be able to inherit from it and override the Device.batch_transform
method as well.
class ModifiedDevice(OtherDevice):
def batch_transform(self, circuit: QuantumTape):
def null_postprocessing(results):
return results[0]
return (circuit, ) null_postprocessing
Ups,... due to a glitch in my environment setup the above trace was taken with a very old PL 0.25.1... The timings look better with 0.29.1 (which is the highest version currently compatible with my code) but still, I think it would be very useful to expose the device_batch_transform
kwarg that execute()
already has via the qnode interface in a similar way as max_expansion
is also accessible from the qnode level.
If solving the problem with inheritance doesn't work, I can also recommend using composition and a device wrapper:
class SkipBatchTransformDevice:
def __new__(cls, device):
cls_type = type("SkipBatchTransformDevice", (SkipBatchTransformDevice, device.__class__, ), device.__dict__)
return object.__new__(cls_type)
def __init__(self, device):
self._device = device
def __getattr__(self, name):
return getattr(self._device, name)
def batch_transform(self, circuit):
def null_postprocesssing(results):
return results[0]
return (circuit, ),null_postprocesssing
no_batch_transform_device = SkipBatchTransformDevice(original_device)
@cvjjm are you hoping to do this for a specific device?
the workaround proposed by @albi3ro should do the trick, but I just think it would be really useful (not just for me) if one could switch of the batch_transform of the device on the qnode level in the same way as one can currently already control other aspects of "compilation" such as the expansion_strategy
. The device_batch_transform
kwarg of execute already exists. It should be essentially a one line fix to expose this feature via qml.qnode()
and simply pass the value on when the Qnode calls execute().
It should be essentially a one line fix to expose this feature via qml.qnode() and simply pass the value on when the Qnode calls execute().
Yes agreed. Our worry is that odd behaviour might occur by allowing users to disable the device's batch transform. But perhaps this is ok for power users who know what they are doing!
Feature details
When measuring many observables that I as the user know are jointly measurable (such as a whole bunch of tensor products of
PauliZ
operators) PL sill tries to split and group those observables. This can easily take an order of magnitude more time than the actual simulation of the circuit on the device as the following instrument trace shows.Please add a kwarg to
qml.qnode()
that lets me switch off the automatic splitting and grouping. If a users specifies this but provides incompatible observable, then PL should simply raise an exception.Implementation
No response
How important would you say this feature is?
3: Very important! Blocking work.
Additional information
No response