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

Add qml.workflow.construct_execution_config(qnode)(*args,**kwargs) #6901

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

andrijapau
Copy link
Contributor

@andrijapau andrijapau commented Jan 29, 2025

Context:

The execution configuration of a particular QNode instance is needed in our source code occasionally for various things (such as getting the gradient function).

Description of the Change:

This PR introduces a new helper function in the workflow module. Specifically,

  • Interface is updated in _resolve_execution_config
  • Added str dunder method for prettier printing
@qml.qnode(qml.device("default.qubit", wires=1))
def circuit(x):
    qml.RX(x, 0)
    return qml.expval(qml.Z(0))

>>> config = qml.workflow.construct_execution_config(circuit)(1)
>>> pprint.pprint(config)
ExecutionConfig(grad_on_execution=False,
                use_device_gradient=True,
                use_device_jacobian_product=False,
                gradient_method='backprop',
                gradient_keyword_arguments={},
                device_options={'max_workers': None,
                                'prng_key': None,
                                'rng': Generator(PCG64) at 0x17D5BB220},
                interface=<Interface.AUTO: 'auto'>,
                derivative_order=1,
                mcm_config=MCMConfig(mcm_method=None, postselect_mode=None),
                convert_to_numpy=True)

Benefits: Simplifies some code found in specs.py and construct_batch.py.

Possible Drawbacks: None.

[sc-83343]

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.59%. Comparing base (58d4f4f) to head (90e36cf).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6901   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files         478      479    +1     
  Lines       45295    45317   +22     
=======================================
+ Hits        45113    45135   +22     
  Misses        182      182           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andrijapau andrijapau requested a review from albi3ro January 29, 2025 19:31
@andrijapau andrijapau requested a review from albi3ro January 29, 2025 20:07
@andrijapau andrijapau marked this pull request as draft January 29, 2025 21:30
@andrijapau andrijapau marked this pull request as ready for review January 29, 2025 21:34
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ This has made me realize we should set the interface in _resolve_execution_config, but that can be a follow on.

I have a feeling this is going to be really useful.

@andrijapau andrijapau requested a review from astralcai January 30, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants