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

JIT errors do not change Variable values #195

Merged
merged 4 commits into from
May 1, 2022

Conversation

chaoming0625
Copy link
Collaborator

Previously, errors occured in JIT function will change value contents of all variables.

>>> import brainpy.math as bm
>>>
>>> a = bm.Variable(bm.zeros(1))
>>> a = bm.zeros(1)
>>> @bm.jit
>>> def f():
>>>    a.value += 1
>>>    b.value += 1
>>> f()
brainpy.errors.MathError: JaxArray created outside of the jit function cannot be updated in JIT mode. You should mark it as brainpy.math.Variable instead.
>>> a
Variable(Traced<ShapedArray(float32[1])>with<DynamicJaxprTrace(level=0/1)>)

Now, the content will keep the same. For example,

>>> import brainpy.math as bm
>>>
>>> a = bm.Variable(bm.zeros(1))
>>> a = bm.zeros(1)
>>> @bm.jit
>>> def f():
>>>    a.value += 1
>>>    b.value += 1
>>> f()
brainpy.errors.MathError: JaxArray created outside of the jit function cannot be updated in JIT mode. You should mark it as brainpy.math.Variable instead.
>>> a
Variable([0.], dtype=float32)

@chaoming0625 chaoming0625 merged commit a7e03c1 into brainpy:master May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant