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

feat(dataset): dataset as config pilot code #47

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ repos:
- id: mypy
args: [--no-strict-optional, --ignore-missing-imports]
files: ^(hamilflow/|tests/)
additional_dependencies: [types-PyYAML]
- repo: https://github.com/ambv/black
rev: 24.4.2
hooks:
Expand Down
11 changes: 11 additions & 0 deletions datasets/miminal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 0.1.0
models:
brownian_motion:
definition:
system:
sigma: 1
delta_t: 1
initial_condition:
x0: 0
args:
n_steps: 100
39 changes: 39 additions & 0 deletions hamilflow/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
from pathlib import Path

import click

from hamilflow.dataset.config import Dispatcher, read_yaml


@click.group(invoke_without_command=True)
@click.pass_context
def hamilflow(ctx):
if ctx.invoked_subcommand is None:
click.echo("Hello {}".format(os.environ.get("USER", "")))
click.echo(
"Welcome to HamilFlow. Use `hamilflow --help` to find all the commands."
)
else:
click.echo("Loading Service: %s" % ctx.invoked_subcommand)


@hamilflow.command()
@click.argument("path", type=click.Path(exists=True, path_type=Path), required=True)
def generate(path: Path):
"""Generate dataset based on an input config file.

:param path: location of the config file.
"""

click.secho(f"Reading config from: {path}")

config = read_yaml(path)
dispatcher = Dispatcher()

for model_name, model_config in config["models"].items():
click.secho(model_config)
model = dispatcher[model_name](**model_config["definition"])
data = model(**model_config["args"])

# ... # save data or load into a data container.
Empty file added hamilflow/dataset/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions hamilflow/dataset/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Any

import yaml

from hamilflow.models.brownian_motion import BrownianMotion


@dataclass
class Dispatcher:
brownian_motion = BrownianMotion

def __getitem__(self, item: str) -> Any:
return getattr(self, item)


def read_yaml(path: Path) -> dict:
return yaml.safe_load(path.read_text())
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pydantic = "^2.6.1"
loguru = "^0.7.2"
matplotlib = "^3.8.3"
scipy = "^1.12.0"
click = "^8.1.7"


[tool.poetry.group.test.dependencies]
Expand All @@ -38,6 +39,8 @@ plotly = "^5.19.0"
[tool.poetry.group.dev.dependencies]
commitizen = "*"

[tool.poetry.scripts]
hamilflow = "hamilflow.cli:hamilflow"

[tool.commitizen]
name = "cz_conventional_commits"
Expand Down
Loading