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 201 forks source link

Absolute value not implemented on kernel #1303

Closed Jochenwolf3 closed 5 years ago

Jochenwolf3 commented 5 years ago

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

  1. Save one of the below minimal working examples to a file
  2. 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

# packages in environment at /home/ion/anaconda3/envs/artiq-jw: # # Name Version Build Channel aiohttp 3.4.4 py35h470a237_0 conda-forge/label/main artiq 5.0.dev 1205+gitf306bcbc http://10.255.6.4/condapkg artiq-env 5.0.dev 1205+gitf306bcbc http://10.255.6.4/condapkg async-timeout 3.0.1 py_1000 conda-forge/label/main asyncserial 0.1 py_13+git340e430 m-labs/label/main attrs 19.1.0 py_0 conda-forge/label/main binutils-or1k-linux 2.30 7 m-labs/label/main blas 2.4 openblas conda-forge/label/main bscan-spi-bitstreams 0.10.0 2 m-labs/label/main bzip2 1.0.6 h14c3975_1002 conda-forge/label/main ca-certificates 2019.3.9 hecc5488_0 conda-forge/label/main certifi 2018.8.24 py35_1001 conda-forge/label/main cffi 1.11.5 py35h5e8e0c9_1 conda-forge/label/main chardet 3.0.4 py35_3 conda-forge/label/main dbus 1.13.0 h4e0c4b3_1000 conda-forge/label/main expat 2.2.5 hf484d3e_1002 conda-forge/label/main fontconfig 2.13.1 he4413a7_1000 conda-forge/label/main freetype 2.10.0 he983fc9_0 conda-forge/label/main gettext 0.19.8.1 hc5be6a0_1002 conda-forge/label/main glib 2.56.2 had28632_1001 conda-forge/label/main gst-plugins-base 1.12.5 h3865690_1000 conda-forge/label/main gstreamer 1.12.5 h0cc0488_1000 conda-forge/label/main h5py 2.8.0 py35h7eb728f_2 conda-forge/label/main hdf5 1.10.2 hc401514_3 conda-forge/label/main icu 58.2 hf484d3e_1000 conda-forge/label/main idna 2.7 py35_2 conda-forge/label/main idna_ssl 1.0.0 0 conda-forge/label/main jpeg 9c h14c3975_1001 conda-forge/label/main lab3-artiq 0.1 dev_0 levenshtein 0.12.0 py35_1 m-labs/label/main libblas 3.8.0 4_openblas conda-forge/label/main libcblas 3.8.0 4_openblas conda-forge/label/main libffi 3.2.1 he1b5a44_1006 conda-forge/label/main libgcc-ng 8.2.0 hdf63c60_1
libgfortran 3.0.0 1 conda-forge/label/main libgfortran-ng 7.3.0 hdf63c60_0
libgit2 0.24.1 7 m-labs/label/main libiconv 1.15 h516909a_1005 conda-forge/label/main liblapack 3.8.0 4_openblas conda-forge/label/main liblapacke 3.8.0 4_openblas conda-forge/label/main libopenblas 0.3.3 h5a2b251_3
libpng 1.6.36 h84994c4_1000 conda-forge/label/main libssh2 1.7.0.git 5 m-labs/label/main libstdcxx-ng 8.2.0 hdf63c60_1
libusb 1.0.20 0 m-labs/label/main libuuid 2.32.1 h14c3975_1000 conda-forge/label/main libxcb 1.13 h14c3975_1002 conda-forge/label/main libxml2 2.9.8 h143f9aa_1005 conda-forge/label/main lit 0.4.1 py_9 m-labs/label/main llvmlite-artiq 0.23.0.dev py35_5 m-labs/label/main multidict 4.4.2 py35h470a237_0 conda-forge/label/main ncurses 6.1 hf484d3e_1002 conda-forge/label/main ndscan v0.1 py35_143+gitea09610b6 http://10.255.6.4/condapkg noisyopt 0.2.2 pypi_0 pypi numpy 1.15.2 py35h99e49ec_0
numpy-base 1.15.2 py35h2f8d375_0
oitg 0.1 dev_0 openblas 0.3.5 h9ac9557_1001 conda-forge/label/main openocd 0.10.0 6 m-labs/label/main openssl 1.0.2r h14c3975_0 conda-forge/label/main outputcheck 0.4.2 py_7 m-labs/label/main oxart 0.1 dev_0 pandas 0.23.4 py35hf8a1672_0 conda-forge/label/main patsy 0.5.1 py_0 conda-forge/label/main pcre 8.41 hf484d3e_1003 conda-forge/label/main pip 18.0 py35_1001 conda-forge/label/main prettytable 0.7.2 py_2 conda-forge/label/main pthread-stubs 0.4 h14c3975_1001 conda-forge/label/main pycparser 2.19 py_0 conda-forge/label/main pygit2 0.24.0 py35_4 m-labs/label/main pyqt 5.6.0 py35h8210e8a_7 conda-forge/label/main pyqtgraph 0.10.0 py_5 conda-forge/label/main pyserial 3.4 py_2 conda-forge/label/main python 3.5.5 h5001a0f_2 conda-forge/label/main python-dateutil 2.8.0 py_0 conda-forge/label/main pythonparser 1.1 py_8 m-labs/label/main pytz 2018.9 py_0 conda-forge/label/main qt 5.6.2 hf70d934_9 conda-forge/label/main quamash 0.6.1 py_0 http://10.255.6.4/condapkg readline 7.0 hf8c457e_1001 conda-forge/label/main regex 2015.11.22 py35_1 m-labs/label/main scipy 1.1.0 py35he2b7bc3_1
setuptools 40.4.3 py35_0 conda-forge/label/main sip 4.18.1 py35hfc679d8_0 conda-forge/label/main six 1.11.0 py35_1 conda-forge/label/main sqlite 3.26.0 h67949de_1001 conda-forge/label/main statsmodels 0.9.0 py35_0 conda-forge/label/main system 5.8 2
tk 8.6.9 h84994c4_1000 conda-forge/label/main wand-client 0.1 py35_12+gite2b76f4b http://10.255.6.4/condapkg wheel 0.32.0 py35_1000 conda-forge/label/main xorg-libxau 1.0.9 h14c3975_0 conda-forge/label/main xorg-libxdmcp 1.1.3 h516909a_0 conda-forge/label/main xz 5.2.4 h14c3975_1001 conda-forge/label/main yarl 1.2.6 py35h470a237_0 conda-forge/label/main zlib 1.2.11 h14c3975_1004 conda-forge/label/main

Hardware involved: Artiq master running on Ubuntu, and a Kasli v1.1

dnadlinger commented 5 years ago

@Jochenwolf3: See https://github.com/m-labs/artiq/pull/1306.