qua-platform / quam

The Quantum Abstract Machine (QuAM) is a comprehensive framework designed to abstract and manage quantum programming environments, providing robust tools for configuring and running quantum operations effectively. It is built over the QUA programming language, offering an organized structure for handling complex quantum components and operations.
http://qua-platform.github.io/quam/
BSD 3-Clause "New" or "Revised" License
8 stars 3 forks source link

References to properties error handling #82

Open JacobHast opened 1 day ago

JacobHast commented 1 day ago

If a quam component attribute is a reference to a property and this property throws an error, the error is ignored and the property instead returns the string reference. Is this intended behaviour? I my experience it makes it hard to debug custom components - if the attribute throws an error I think I would always like to see this error and have the program halt, rather than continuing with the string.

from quam import quam_dataclass, QuamRoot, QuamComponent

@quam_dataclass
class Root(QuamRoot):
    pass

@quam_dataclass
class Component(QuamComponent):
    x: int = "#./prop"

    @property
    def prop(self):
        assert 1 == 2
        return 42

root = Root()
root.component = Component()

print(root.component.x) # prints '#./prop'
print(root.component.prop) # raises AssertionError
nulinspiratie commented 1 day ago

Yes this is actually intended behaviour, and I agree it's not ideal. Originally it raised an error, but this resulted in several other issues:

As a result, I've opted to turn it into a warning instead. Do you see the warning? If not, it may be that you logging package needs to stop filtering out the warnings.

Turning it back into an error would be a breaking change, and could lead to the code of others suddenly not working anymore. Maybe a good in-between solution is to have a global flag that specifies whether it returns an error or warning? I would like it to be warning by default to avoid breaking changes

JacobHast commented 1 day ago

I see. I don't get warnings, not even when running the above example in a fresh kernel, so I'm not sure if I'm filtering out warnings, at least not intended. It would be nice to have the option to turn on errors - of course since I currently don't see the warnings I don't know if I'm in the group of people for which everything would stop working, but it would be good to find out. Alternatively, would this be fixable by adding some kind of quam decorator to properties such that, when everything is "booting up", errors are not thrown, but once the machine is construct errors can be thrown?

nulinspiratie commented 17 hours ago

Both could work, bit since the decorator would still be a breaking change, I propose we handle this by adding a flag to specify whether it'll raise an error.

We can also look separately at why you aren't receiving a warning. I can also raise the log status from warning to error.

I'm planning to allow quam to have an optional config file. We can then easily add this as a flag