On kernel, there is no convenient way of getting the absolute value of a number.
Issue Details
Steps to Reproduce
Save one of the below minimal working examples to a file
Run it via the artiq dashboard.
A. Minimal working example for abs():
from artiq.experiment import *
class Test(EnvExperiment):
def build(self):
self.setattr_device("core")
@kernel
def run(self):
print(abs(-1))
B. Minimal working example for numpy.absolute():
import numpy as np
from artiq.experiment import *
class Test(EnvExperiment):
def build(self):
self.setattr_device("core")
@kernel
def run(self):
print(np.absolute(-1))
C. Workaround:
from artiq.experiment import *
class Test(EnvExperiment):
def build(self):
self.setattr_device("core")
@kernel
def run(self):
print(self.abs(-1))
@kernel
def abs(self, x):
return x if x > 0 else -x
Expected Behavior
For all three of the above examples to print 1. At least one out of abs() and numpy.absolute() to be implemented.
Actual (undesired) Behavior
A. Running example A yields:
root:While compiling /home/ion/scratch/jw/comet_repository/absolute_value_on_kernel.py
/home/ion/scratch/jw/comet_repository/absolute_value_on_kernel.py:15:15-15:18: fatal: name 'abs' is not bound to anything
print(abs(-1))
^^^
B. Running example B yields:
root:While compiling /home/ion/scratch/jw/comet_repository/absolute_value_on_kernel.py
/home/ion/scratch/jw/comet_repository/absolute_value_on_kernel.py:16:15-16:26: error: cannot call this expression of type <instance numpy.ufunc {
objectid: numpy.int32
}>
print(np.absolute(-1))
^^^^^^^^^^^
C. Running example C yields:
print:1
Your System
Operating System: Linux version 4.15.0-46-generic (buildd@lgw01-amd64-038) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019
ARTIQ version: ARTIQ v5.0.dev+1205.gf306bcbc
Version of the gateware and runtime loaded in the core device:
Bug Report
One-Line Summary
On kernel, there is no convenient way of getting the absolute value of a number.
Issue Details
Steps to Reproduce
A. Minimal working example for abs():
B. Minimal working example for numpy.absolute():
C. Workaround:
Expected Behavior
For all three of the above examples to print 1. At least one out of abs() and numpy.absolute() to be implemented.
Actual (undesired) Behavior
A. Running example A yields:
B. Running example B yields:
C. Running example C yields:
Your System
Operating System:
Linux version 4.15.0-46-generic (buildd@lgw01-amd64-038) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019
ARTIQ version:
ARTIQ v5.0.dev+1205.gf306bcbc
Version of the gateware and runtime loaded in the core device:
Output of
conda list
:Hardware involved: Artiq master running on Ubuntu, and a Kasli v1.1