Skip to content

feat: add an MLproject generated from main.py and bump the version to 0.1.5 - #10

Merged
mortenoh merged 6 commits into
mainfrom
feat/mlproject
Oct 15, 2026
Merged

mortenoh merged 6 commits into
mainfrom
feat/mlproject

Conversation

@mortenoh

@mortenoh mortenoh commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Adds an MLproject so the model runs with chapkit mlproject run and chap eval --run-config.as-chapkit, alongside the existing main.py service.

What changes

  • MLproject is generated from main.py by chapkit mlproject export (chapkit 2.4.0), so main.py stays the source of truth. make mlproject regenerates it.
  • make lint (and so CI) runs chapkit mlproject export --check. It fails when the file is stale, or when chapkit mlproject run would read it as a different service (info, config options and defaults, accepted values, commands, adapters, config layout).
  • The MLproject sets meta_data.config_format: flat, so chapkit mlproject run writes the same flat config.yml as main.py.
  • read_config() in scripts/lib.R also accepts chap-core's nested layout (options under user_option_values). chapkit before 2.4.0 ignores meta_data.config_format and writes that layout, as in chap-core installs from before chore: require chapkit 2.4.0 for --run-config.as-chapkit (CLIM-1435) dhis2-chap/chap-core#737 (which requires 2.4.0 for --run-config.as-chapkit). Without this the scripts silently fell back to defaults for every option (a config with n_samples: 100 produced 1000 samples). tools/test_lib.R covers both layouts.
  • main.py sets author_note explicitly. An MLproject without one serves the description instead, so this keeps /api/v1/info identical.
  • make test-mlproject, and a new step in CI's docker-test job, start the image with chapkit mlproject run . and run chapkit's contract test and tools/api_smoke.py (real data with geometry, checks the config reaches the scripts) against it.
  • The Dockerfile copies MLproject into /work. chapkit >=2.4.0. Version 0.1.5 (main released 0.1.4 in fix: build the adjacency graph with planar geometry and release 0.1.4 #11). README documents the MLproject route.

No environment is declared in the MLproject. The commands need R with INLA and GHRmodel, which the service image provides, and --run-config.as-chapkit refuses docker_env. Chap's own MLproject runners are not supported: they pass the config as {model_config} under another file name, which the scripts do not read.

Parity with the main.py service

/api/v1/info is identical, the OpenAPI paths are identical, and the config options have the same names, types, enums and defaults. Remaining differences, none settable from the MLproject:

  • Storage: in memory by default; chapkit mlproject run --database PATH keeps configs and trained models across restarts.
  • Registration keepalive: main.py uses 15s; pass --keepalive-interval 15 to mlproject run (export warns about this).
  • Config schema cosmetics: class title and docstring, and the prediction_periods description wording.

Verification

  • make lint: chapkit mlproject export --check passes (with the expected keepalive warning).
  • make test-unit: all checks pass, including both config layouts.
  • make test-mlproject: contract test and API smoke test pass against chapkit mlproject run in the image, which reports the flat layout. 33 rows x 100 samples.
  • make test-api against the main.py service still passes.

Follow-ups

Most were addressed in dhis2-chap/chapkit#141 (released in 2.4.0): meta_data.config_format / --config-format, --database, --keepalive-interval, --log-level, the hierarchy named after the MLproject, and chapkit mlproject export replacing this repo's own generator.

@mortenoh mortenoh changed the title feat: add an MLproject generated from main.py and bump the version to 0.1.4 feat: add an MLproject generated from main.py and bump the version to 0.1.5 Oct 15, 2026
@mortenoh
mortenoh marked this pull request as ready for review October 15, 2026 14:03
@mortenoh
mortenoh merged commit d4987bc into main Oct 15, 2026
2 checks passed
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