np.float64 attribute from host crashes compiler, broken error message #90

Closed
opened 2021-11-10 21:17:42 +08:00 by sb10q · 7 comments

Sometimes code using numpy ends up with a numpy.float64 type instead of float. If such a value is used as a KernelInvariant, nac3 breaks.

Repro:

from numpy import float64
from min_artiq import *

@nac3
class Demo:
    core: KernelInvariant[Core]
    foo: KernelInvariant[float]

    def __init__(self):
        self.core = Core()
        self.foo = float64(2.3)

    @kernel
    def run(self):
        pass


if __name__ == "__main__":
    Demo().run()

results in:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "unknown identifier base (use before def?) at line 2 column 5"', nac3artiq/src/lib.rs:378:44
Sometimes code using numpy ends up with a ``numpy.float64`` type instead of ``float``. If such a value is used as a KernelInvariant, nac3 breaks. Repro: ```python from numpy import float64 from min_artiq import * @nac3 class Demo: core: KernelInvariant[Core] foo: KernelInvariant[float] def __init__(self): self.core = Core() self.foo = float64(2.3) @kernel def run(self): pass if __name__ == "__main__": Demo().run() ``` results in: ``` thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "unknown identifier base (use before def?) at line 2 column 5"', nac3artiq/src/lib.rs:378:44 ```
sb10q changed title from np.float64 KernelInvariant crashes compiler, broken error message to np.float64 attribute from host crashes compiler, broken error message 2021-11-10 21:18:05 +08:00
Poster
Owner

Does not need to be KernelInvariant, foo: float causes the same behavior.

Does not need to be ``KernelInvariant``, ``foo: float`` causes the same behavior.

I guess this is because symbol resolver fails to resolve the type, it should break as this is not intended, we can support float64. The error message is interesting though.

I guess this is because symbol resolver fails to resolve the type, it should break as this is not intended, we can support float64. The error message is interesting though.
Poster
Owner

I wouldn't introduce a float64 type and its associated complexity... I propose:

  1. investigating the funny error message, which may point to some latent bug in the compiler.
  2. simply converting those host float64 objects to float when they arrive inside NAC3.
  3. investigating what happens when incorrect/unsupported types are passed in those values, and making sure we have a good error message.
I wouldn't introduce a ``float64`` type and its associated complexity... I propose: 1. investigating the funny error message, which may point to some latent bug in the compiler. 2. simply converting those host ``float64`` objects to ``float`` when they arrive inside NAC3. 3. investigating what happens when incorrect/unsupported types are passed in those values, and making sure we have a good error message.

I wouldn't introduce a float64 type and its associated complexity... I propose:

  1. investigating the funny error message, which may point to some latent bug in the compiler.
  2. simply converting those host float64 objects to float when they arrive inside NAC3.

Actually floats are now f64, I mean we can convert numpy float64 into our float.

> I wouldn't introduce a ``float64`` type and its associated complexity... I propose: > 1. investigating the funny error message, which may point to some latent bug in the compiler. > 2. simply converting those host ``float64`` objects to ``float`` when they arrive inside NAC3. Actually floats are now f64, I mean we can convert numpy float64 into our float.
Collaborator

I think I have encountered the error message before, but not clear how to solve that in a good way for now, since we synthesize the starting point..

It is because we cannot get the type of base in our synthesized starting point of the code (symbol resolver cannot confirm that numpy.float is compatible with float at here when getting the type of base)

I think I have encountered the error message before, but not clear how to solve that in a good way for now, since we synthesize the starting point.. It is because we cannot get the type of `base` in our synthesized starting point of the code (symbol resolver cannot confirm that `numpy.float` is compatible with float at [here](https://git.m-labs.hk/M-Labs/nac3/src/branch/master/nac3artiq/src/symbol_resolver.rs#L147) when getting the type of `base`)

I think I have encountered the error message before, but not clear how to solve that in a good way for now, since we synthesize the starting point..

It is because we cannot get the type of base in our synthesized starting point of the code (symbol resolver cannot confirm that numpy.float is compatible with float at here when getting the type of base)

we can fix this simply by returning an error when we cannot get the value of base.

> I think I have encountered the error message before, but not clear how to solve that in a good way for now, since we synthesize the starting point.. > > It is because we cannot get the type of `base` in our synthesized starting point of the code (symbol resolver cannot confirm that `numpy.float` is compatible with float at [here](https://git.m-labs.hk/M-Labs/nac3/src/branch/master/nac3artiq/src/symbol_resolver.rs#L147) when getting the type of `base`) we can fix this simply by returning an error when we cannot get the value of `base`.
Poster
Owner

The error message is okay now.

nac3artiq.CompileError: type error inside object launching kernel: error when getting type of field `foo` (<class 'numpy.float64'> is not supported in nac3 (did you forgot to put @nac3 annotation?))

We should simply treat the special case of np.float64 as float I guess.

The error message is okay now. ``` nac3artiq.CompileError: type error inside object launching kernel: error when getting type of field `foo` (<class 'numpy.float64'> is not supported in nac3 (did you forgot to put @nac3 annotation?)) ``` We should simply treat the special case of ``np.float64`` as ``float`` I guess.
sb10q added this to the Alpha milestone 2022-04-12 09:43:11 +08:00
sb10q closed this issue 2022-04-12 10:34:38 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#90
There is no content yet.