Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node parser fails to recognize renamed ts inputs #261

Open
AdamGlustein opened this issue May 29, 2024 · 3 comments
Open

Node parser fails to recognize renamed ts inputs #261

AdamGlustein opened this issue May 29, 2024 · 3 comments
Labels
type: bug Concrete, reproducible bugs

Comments

@AdamGlustein
Copy link
Collaborator

AdamGlustein commented May 29, 2024

Describe the bug

Baskets in csp are not iterable, but should be.

To Reproduce

This code will raise an error:

import csp
from csp import ts

@csp.node
def n(values: [ts[int]]):
    for val in values:
        if csp.ticked(val):
            pass
 
>> CspParseError: unrecognized input 'val'

This code will not:

import csp
from csp import ts

@csp.node
def n(values: [ts[int]]):
    for i in range(len(values)):
        if csp.ticked(values[i]):
            pass

Similarly for dictbaskets:

import csp
from csp import ts

@csp.node
def n(values: {str: ts[int]}):
    for key, val in values.items():
        if csp.ticked(val):
            pass

>> CspParseError: unrecognized input 'val'
import csp
from csp import ts

@csp.node
def n(values: {str: ts[int]}):
    for key, val in values.items():
        if csp.ticked(values[key]):
            pass

Expected behavior

Both of the snippets given above (for list/dictbaskets) should be equivalent.

Error Message

Runtime Environment

0.0.4
3.8.12 (default, Apr 7 2022, 17:33:24)
[GCC 11.2.0]
linux

Additional context

@AdamGlustein AdamGlustein added the type: bug Concrete, reproducible bugs label May 29, 2024
@AdamGlustein AdamGlustein changed the title Make baskets iterable Node parser fails to recognize renamed ts inputs Jul 12, 2024
@AdamGlustein
Copy link
Collaborator Author

The real issue is that the node parser is failing to recognize a time-series if its renamed. This code snippet will also fail for the exact same reason:

@csp.node
def n(x: ts[int]):
    y = x
    if csp.ticked(y):
        pass

@robambalu
Copy link
Collaborator

Thats right, because ts inputs have this sort of duality. They can act as ts inputs ( which can be passed to csp.xxx() methods ), or they can be accessed as the current value ( ie x + y )
when iterating there, its accessing by value and then cant be passed to csp methods

@AdamGlustein
Copy link
Collaborator Author

AdamGlustein commented Jul 12, 2024

We can maintain the duality of an input type and value during iteration so that for val in values works the exact same as for i in range(len(values)). We just need to ast parse the loop properly and update the input map.

I think it's feasible to implement, but maybe I'm missing some of the complexity. The error message here is pretty cryptic too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Concrete, reproducible bugs
Projects
None yet
Development

No branches or pull requests

2 participants