Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an error or warning in qml.compile if basis_set contains operations instead of strings. #6132

Open
dwierichs opened this issue Aug 23, 2024 · 4 comments
Labels
enhancement ✨ New feature or request good first issue Good for newcomers

Comments

@dwierichs
Copy link
Contributor

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

@dwierichs dwierichs added the enhancement ✨ New feature or request label Aug 23, 2024
@albi3ro
Copy link
Contributor

albi3ro commented Aug 23, 2024

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.

@dwierichs
Copy link
Contributor Author

Haha, yes, this works, too, of course 🚀

@dwierichs dwierichs added the good first issue Good for newcomers label Aug 23, 2024
@AnuravModak
Copy link
Contributor

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!

@albi3ro
Copy link
Contributor

albi3ro commented Aug 23, 2024

@AnuravModak Yes this issue is open for external contributions.

It will involve updating this function here:

def stop_at(obj):

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants