Skip to content

Commit

Permalink
Feat/cli (#6)
Browse files Browse the repository at this point in the history
* feat: add model subcommands

* typo

* docs: update readme
  • Loading branch information
jung235 authored Oct 18, 2023
1 parent 1e3f986 commit 75b0116
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pydiffuser is a numerical simulation framework for nonequilibrium statistical ph

This package mainly aims:
- to share code to implement a numerical simulation on physical models written in various forms of [stochastic differential equations](https://en.wikipedia.org/wiki/Stochastic_differential_equation).
- to revisit recent research highlights in non-equilibrium statistical physics.
- to revisit recent research highlights in nonequilibrium statistical physics.
- to reduce the repeated code on time-series data analysis, e.g., statistical analysis of [single-particle trajectory](https://en.wikipedia.org/wiki/Single-particle_trajectory) for [SPT](https://en.wikipedia.org/wiki/Single-particle_tracking) experiments.
- to provide the skeleton of stochastic modeling for anyone interested in stochastic processes.

Expand Down Expand Up @@ -75,7 +75,7 @@ It is obtained by `matplotlib.pyplot.plot(tracer.position_x1, tracer.position_x2
List all stochastic models supported by Pydiffuser.

```console
$ pydiffuser list
$ pydiffuser model list
NAME MODEL CONFIG DIMENSION
abp ActiveBrownianParticle ActiveBrownianParticleConfig 2d
aoup ActiveOUParticle ActiveOUParticleConfig 1d, 2d, 3d
Expand Down
12 changes: 3 additions & 9 deletions pydiffuser/_cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import click

from pydiffuser._cli.cli_utils import get_model_info
from pydiffuser._cli.cli_utils import add_model_subcommands


def create():
@click.group()
@click.version_option()
def pydiffuser_cli():
"""Pydiffuser CLI"""
"""Pydiffuser CLI."""

@pydiffuser_cli.command()
def list():
"""List all models defined in Pydiffuser."""

info = get_model_info()
for name, model, config, dimension in info:
click.echo(f"{name:16}{model:32}{config:32}{dimension:16}")
add_model_subcommands(pydiffuser_cli)

return pydiffuser_cli

Expand Down
16 changes: 16 additions & 0 deletions pydiffuser/_cli/cli_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import click

from pydiffuser.models import CONFIG_REGISTRY, MODEL_REGISTRY


Expand All @@ -17,3 +19,17 @@ def get_model_info():
for k, dim in dims.items()
]
return info


def add_model_subcommands(cli: click.Group) -> None:
@cli.group(name="model")
def model_cli():
"""Subcommands related to model."""

@model_cli.command()
def list():
"""List all models defined in Pydiffuser."""

info = get_model_info() # type: ignore[no-untyped-call]
for name, model, config, dimension in info:
click.echo(f"{name:16}{model:32}{config:32}{dimension:16}")
2 changes: 1 addition & 1 deletion pydiffuser/mech/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def register(potential: Any) -> Any:
def decorator() -> Any:
if not isinstance(potential, PjitFunction):
raise RuntimeError(
"Potential must be transformed via 'jax.jit' to register"
"Potential must be transformed via `jax.jit` to register"
)
FIELD_REGISTRY[f"{potential.__name__}"] = potential
return potential
Expand Down

0 comments on commit 75b0116

Please sign in to comment.