pennylane
pennylane copied to clipboard
Raise an error or warning in `qml.compile` if `basis_set` contains operations instead of strings.
Feature details
As the title suggests: qml.compile takes an argument basis_set, which is expected to be a sequence of operation names, i.e. strings.
If a user passes a sequence of PennyLane operator types, no error is raised but the basis set becomes equivalent to [].
It would be nice to raise a warning, or even an error, if users pass non-empty sequences that contain operators instead of operator names.
Implementation
Straightforward.
How important would you say this feature is?
1: Not important. Would be nice to have.
Additional information
No response
Or we could update the stopping condition to:
class_types = tuple(o for o in basis_set if isinstance(o, type)
class_names = set(o for o in basis_set if isinstance(o, str))
def stopping_condition(obj):
return obj.name in class_names or isinstance(obj, class_types)
Why raise an error when we can just support the operation types?
I think we could even turn this into a good first issue.
Haha, yes, this works, too, of course :rocket:
Hi @albi3ro and @dwierichs , if this is available for external contributors and want contribution on this, do let me know! Will be happy to take this up!
@AnuravModak Yes this issue is open for external contributions.
It will involve updating this function here:
https://github.com/PennyLaneAI/pennylane/blob/2f9631b1ce61217665f0beaefd5b83a76b9c2688/pennylane/transforms/compile.py#L185
to accept types specified in basis_set in addition to string based names. The docstring and type hints will also need to be updated.
We may still want to consider an error if basis_set contains anything that is not a string or an Operator subclass.