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

Improve readability when printing an ExecutionConfig #7007

Open
andrijapau opened this issue Feb 25, 2025 · 0 comments
Open

Improve readability when printing an ExecutionConfig #7007

andrijapau opened this issue Feb 25, 2025 · 0 comments
Labels
enhancement ✨ New feature or request good first issue Good for newcomers

Comments

@andrijapau
Copy link
Contributor

Feature details

Currently we have,

@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, resolve=False)(1)
>>> print(config)
ExecutionConfig(grad_on_execution=False, use_device_gradient=None, use_device_jacobian_product=False, gradient_method='best', gradient_keyword_arguments={}, device_options={}, interface=<Interface.JAX: 'jax'>, derivative_order=1, mcm_config=MCMConfig(mcm_method=None, postselect_mode=None), convert_to_numpy=True)

This is very hard to read and could lead to debug errors. It would be great to mimic the output we get if we use an external library like pprint. So, something like this,

>>> pprint.pprint(config)
ExecutionConfig(grad_on_execution=None,
                use_device_gradient=None,
                use_device_jacobian_product=False,
                gradient_method='best',
                gradient_keyword_arguments={},
                device_options={},
                interface=<Interface.AUTO: 'auto'>,
                derivative_order=1,
                mcm_config=MCMConfig(mcm_method=None, postselect_mode=None),
                convert_to_numpy=True)

Very easy to read! 🥰

Implementation

A custom __str__ dunder method would need to be added to the ExecutionConfig class (found here). External libraries like pprint can be used to assist in the formatting of the string.

E.g. something like this should work.

class ExecutionConfig(...):
    ...
    def __str__(self):
        return pprint.pformat(self)

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

Please note that some of our tests rely on parsing the string representation of the execution configuration to ensure correct behaviour. This feature will most likely involve modifying some tests to account for the new visualization.

@andrijapau andrijapau added enhancement ✨ New feature or request good first issue Good for newcomers labels Feb 25, 2025
@andrijapau andrijapau changed the title Improve readability when printing ExecutionConfig Improve readability when printing an ExecutionConfig Feb 25, 2025
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

1 participant