Skip to content

glass.jax.Generator.__key isn't thread safe #1017

@paddyroddy

Description

@paddyroddy

Describe the Bug

This won't be an issue most of the time, but I think strictly speaking we should replace it with

@property
def __key(self) -> AnyArray:
    """Return next key for sampling while updating internal state."""
    with self.lock:
        self.key, key = jax.random.split(self.key)
        key.block_until_ready()
    return key

without this in calls like loc + scale * jax.random.normal(self.__key, _size(size), dtype) the key state might advance before the random number is generated.

To Reproduce

import glass
...

Expected Behaviour

No response

Actual Behaviour

No response

Version In Use

2025.4.dev117+gc61a78dad.d20260127

Additional Context

- Python version:
- Operating system:

Metadata

Metadata

Labels

array-apiWork is related to the Array APIbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions