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
Compiler doesn't parse @PREFIX.kernel (kernel decorator with path) #1162
Comments
I agree. The star imports are bad. In terms of recommendations I would go for |
@jordens the point is that the compiler can't recognize any sort of prefix, so even with your suggestion, the ARTIQ compiler would throw an error. However, I haven't tested it with that specific combination. |
Side note: when this is fixed, should change documentation to remove all examples of |
Yes. None of this works right now because of the compiler. My point is not about the compiler but about the recommended style. I didn't want to sidetrack this issue. |
That can be fixed quite easily, I just forgot about |
The compiler should be fixed, but I don't see much of a problem with the star imports. |
@sbourdeauducq https://stackoverflow.com/a/2386740
Sum total of both of these is that when I'm trying to read other people's code, or write my own code based on others, it feels better to know exactly where other code is coming from instead of just "magic." |
@whitequark note that it fails with |
Same problem. Right now the |
ping. out of my expertise. |
I agree with @drewrisinger. Explicit dependencies make ARTIQ Python code easier to understand. It would be nice to support those who don't want to use |
ping @whitequark |
For now, import |
@whitequark What is holding this? |
@sbourdeauducq I wasn't sure how to implement this best, but I just came up with a solution to that. |
@whitequark Any update? |
A hacky solution, not sure if it works for all circumstances: --- a/artiq/compiler/transforms/inferencer.py
+++ b/artiq/compiler/transforms/inferencer.py
@@ -6,6 +6,7 @@ from collections import OrderedDict
from pythonparser import algorithm, diagnostic, ast
from .. import asttyped, types, builtins
from .typedtree_printer import TypedtreePrinter
+from artiq.experiment import kernel
def is_nested_empty_list(node):
@@ -1662,7 +1663,13 @@ class Inferencer(algorithm.Visitor):
def visit_FunctionDefT(self, node):
for index, decorator in enumerate(node.decorator_list):
- if types.is_builtin(decorator.type, "kernel") or \
+ def eval_attr(attr):
+ if isinstance(attr.value, asttyped.QuoteT):
+ return getattr(attr.value.value, attr.attr)
+ return getattr(eval_attr(attr.value), attr.attr)
+ if isinstance(decorator, asttyped.AttributeT):
+ decorator = eval_attr(decorator)
+ if id(decorator) == id(kernel) or types.is_builtin(decorator.type, "kernel") or \
isinstance(decorator, asttyped.CallT) and \
types.is_builtin(decorator.func.type, "kernel"):
continue At least works for the following cases: import artiq.experiment as exp
class Test(exp.EnvExperiment):
def build(self):
self.setattr_device("core")
@exp.kernel
def run(self):
pass and import artiq
class Test(artiq.experiment.EnvExperiment):
def build(self):
self.setattr_device("core")
@artiq.experiment.kernel
def run(self):
pass |
Thanks @pca006132, I honestly got to the point where I forgot about this b/c I was just doing |
@sbourdeauducq the following experiment run on the current master gives me an error import artiq.experiment as exp
class Test(exp.EnvExperiment):
def build(self):
self.setattr_device("core")
@exp.kernel
def run(self):
pass
|
Supporting special decorators not simply called as |
Description
ARTIQ compiler doesn't recognize
@PREFIX.kernel
decorator.Replicating
Instead of using
from artiq.experiments import *
, useimport artiq.language.core
. Then decorate function with@artiq.language.core.kernel
.Sample Code
I would like to use following, because per PEP20, Explicit is better than implicit. Also, because it avoids cluttering the namespace and speeds imports.
Sample based on LED tutorial:
Behavior
Expected Behavior
ARTIQ compiler should compile the function for the core device as it would any other function with
@kernel
Actual Behavior
ARTIQ throws CompileError (when run in separate
pytest
config), or standard error with above sample &artiq_run
. Seems to be issue withartiq/artiq/compiler/transforms/inferencer.py
Lines 1292 to 1302 in 0fef2af
Tested also with
import artiq.language.core; @artiq.language.core.kernel
, and produced same result.Log Message/Traceback
With artiq_run:
error: decorators are not supported @artiq_lang_core.kernel
.Full traceback
The text was updated successfully, but these errors were encountered: