diff --git a/nac3artiq/demo/module_support.py b/nac3artiq/demo/module_support.py new file mode 100644 index 00000000..a863b380 --- /dev/null +++ b/nac3artiq/demo/module_support.py @@ -0,0 +1,29 @@ +from min_artiq import * +import tests.string_attribute_issue337 as issue337 +import tests.support_class_attr_issue102 as issue102 +import tests.global_variables as global_variables + +@nac3 +class TestModuleSupport: + core: KernelInvariant[Core] + + def __init__(self): + self.core = Core() + + @kernel + def run(self): + # Accessing classes + issue337.Demo().run() + obj = issue102.Demo() + obj.attr3 = 3 + + # Calling functions + global_variables.inc_X() + global_variables.display_X() + + # Updating global variables + global_variables.X = 9 + global_variables.display_X() + +if __name__ == "__main__": + TestModuleSupport().run() \ No newline at end of file diff --git a/nac3artiq/demo/tests/global_variables.py b/nac3artiq/demo/tests/global_variables.py new file mode 100644 index 00000000..ac0e0cf0 --- /dev/null +++ b/nac3artiq/demo/tests/global_variables.py @@ -0,0 +1,14 @@ +from min_artiq import * +from numpy import int32 + +X: Kernel[int32] = 1 + +@rpc +def display_X(): + print_int32(X) + +@kernel +def inc_X(): + global X + X += 1 + diff --git a/nac3artiq/demo/string_attribute_issue337.py b/nac3artiq/demo/tests/string_attribute_issue337.py similarity index 57% rename from nac3artiq/demo/string_attribute_issue337.py rename to nac3artiq/demo/tests/string_attribute_issue337.py index 9749462a..c0b36ed6 100644 --- a/nac3artiq/demo/string_attribute_issue337.py +++ b/nac3artiq/demo/tests/string_attribute_issue337.py @@ -1,16 +1,13 @@ from min_artiq import * from numpy import int32 - @nac3 class Demo: - core: KernelInvariant[Core] - attr1: KernelInvariant[str] - attr2: KernelInvariant[int32] - + attr1: Kernel[str] + attr2: Kernel[int32] + @kernel def __init__(self): - self.core = Core() self.attr2 = 32 self.attr1 = "SAMPLE" @@ -19,6 +16,3 @@ class Demo: print_int32(self.attr2) self.attr1 - -if __name__ == "__main__": - Demo().run() diff --git a/nac3artiq/demo/support_class_attr_issue102.py b/nac3artiq/demo/tests/support_class_attr_issue102.py similarity index 99% rename from nac3artiq/demo/support_class_attr_issue102.py rename to nac3artiq/demo/tests/support_class_attr_issue102.py index 1b931444..0482e3f1 100644 --- a/nac3artiq/demo/support_class_attr_issue102.py +++ b/nac3artiq/demo/tests/support_class_attr_issue102.py @@ -1,7 +1,6 @@ from min_artiq import * from numpy import int32 - @nac3 class Demo: attr1: KernelInvariant[int32] = 2 @@ -12,7 +11,6 @@ class Demo: def __init__(self): self.attr3 = 8 - @nac3 class NAC3Devices: core: KernelInvariant[Core] @@ -35,6 +33,5 @@ class NAC3Devices: NAC3Devices.attr4 # Attributes accessible for classes without __init__ - if __name__ == "__main__": NAC3Devices().run()