Skip to content

Revert import jax.random as jr in jv and career to spelled-out jax.random #986

Description

@jstac

PRs #984 (jv) and #985 (career) both introduced

import jax.random as jr

and use jr.* throughout. These should be reverted to the spelled-out jax.random.* form.

Why

The manual specifies the spelled-out form. manual/styleguide/jax.md (Randomness section) gives:

key = jax.random.key(1234)
shocks = jax.random.normal(key, (100,))

with no alias. The jr alias was in the manual at one point and was deliberately removed in QuantEcon.manual#76, "Refactor JAX random example".

The alias is nonstandard. np and jnp are community conventions a reader arrives already knowing. jr is not — it is local to these two files. A reader who meets jr.split several hundred lines below the import has to scroll back to the top of the lecture to work out what it means. Our lectures are read linearly and often in fragments, so an alias that only pays off for the author is a net cost to the reader.

Affected call sites

lectures/jv.md — import at line 48, uses at 210, 485, 490.

lectures/career.md — import at line 60, uses at 399, 409, 415, 423, 427, 491, 503, 508, 519.

These are the only two files in the repo using the alias.

Related

QuantEcon/action-style-guide rule qe-jax-006 still shows import jax.random as jr together with jr.PRNGKey(42) as its recommended example. That is stale relative to the manual on two counts: the alias, and PRNGKey, which the manual now tells us to replace with jax.random.key. Worth fixing at the source so the checker stops recommending it in other lecture repos.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions