m-labs / artiq

A leading-edge control system for quantum information experiments
https://m-labs.hk/artiq
GNU Lesser General Public License v3.0
434 stars 200 forks source link

compiler: arguments with default value not working in delay_mu #2219

Open fsagbuya opened 1 year ago

fsagbuya commented 1 year ago

Bug Report

One-Line Summary

Error when passing argument (in this case with a type hint) with default value in delay_mu, also occur in simple arguments without the type hint.

Issue Details

Steps to Reproduce

  1. Run the sample code in dashboard or artiq_compile:
    
    from artiq.experiment import *

class DelayTest(EnvExperiment): """delay_mu test with default arg value"""

def build(self):
    self.setattr_device("core")

@kernel
def run(self):
    self.core.reset()
    self.delay_test()

@kernel
def delay_test(self, duration: TInt64 = 10):
    delay_mu(duration)

### Expected Behavior

Will successfully compile/run. Current workaround requires running the method in a separate manner.

Sample:
```python
    @kernel
    def run(self):
        self.core.reset()
        self.delay_test(10)

    @kernel
    def delay_test(self, duration: TInt64):
        delay_mu(duration)

Actual (undesired) Behavior

Returns an error log:

Traceback (most recent call last):
  File "/nix/store/vmk6vpqlcdr5qhrdq18qjliszi5zjwjh-python3.10-artiq-8.8463+e90cd31.beta/bin/.artiq_compile-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/frontend/artiq_compile.py", line 67, in main
    core.compile(exp.run, [exp_inst], {},
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/coredevice/core.py", line 110, in compile
    module = Module(stitcher,
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/compiler/module.py", line 75, in __init__
    iodelay_estimator.visit_fixpoint(src.typedtree)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/compiler/transforms/iodelay_estimator.py", line 83, in visit_fixpoint
    self.visit(node)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 41, in visit
    return self._visit_one(obj)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 32, in _visit_one
    return getattr(self, visit_attr)(node)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/compiler/transforms/iodelay_estimator.py", line 91, in visit_ModuleT
    self.visit(stmt)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 41, in visit
    return self._visit_one(obj)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 32, in _visit_one
    return getattr(self, visit_attr)(node)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/compiler/transforms/iodelay_estimator.py", line 143, in visit_FunctionDefT
    self.visit_function(node.args, body, node.signature_type.find(), node.loc)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/compiler/transforms/iodelay_estimator.py", line 102, in visit_function
    self.visit(body)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 39, in visit
    return [self.visit(elt) for elt in obj]
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 39, in <listcomp>
    return [self.visit(elt) for elt in obj]
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 41, in visit
    return self._visit_one(obj)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 34, in _visit_one
    return self.generic_visit(node)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 27, in generic_visit
    self.visit(getattr(node, field_name))
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 41, in visit
    return self._visit_one(obj)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/pythonparser/algorithm.py", line 32, in _visit_one
    return getattr(self, visit_attr)(node)
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/compiler/transforms/iodelay_estimator.py", line 314, in visit_CallT
    node.arg_exprs = {
  File "/nix/store/b8a1f7j5l7c4qqcj2z0712n5f520ffiq-python3-3.10.12-env/lib/python3.10/site-packages/artiq/compiler/transforms/iodelay_estimator.py", line 315, in <dictcomp>
    arg: self.evaluate(args[arg], abort=abort,
KeyError: 'duration'

Your System (omit irrelevant parts)

dnadlinger commented 1 year ago

We should just strip out any remaining special handling of delays from the compiler; this has long been unused. delay_mu should just be handled the same as any other runtime intrinsic.