Skip to main content

MEDS Random Task Sampler

Python 3.11+ License: MIT

Model-independent generation of query-based task rows from MEDS datasets.

The package provides two separate workflows, one command each:

Command Samples
meds-sample-random-tasks random (code, duration) specifications paired with random patient contexts
meds-generate-task-grid explicit code x duration grids at sampled patient prediction times

These names describe how rows are sampled, not how a downstream model must use them. For example, either output could be used for training, validation, benchmarking, probing, or analysis.

Both workflows follow payalchandak/EveryQuery@9bd85a1. The package owns the shared task schema, code-source resolution, future-occurrence labeling, death and censoring semantics, deterministic seeds, and atomic output writes. It does not depend on a model framework. Configuration is Hydra, confined to the command layer: the sampling core takes plain Python values and never sees a Hydra or OmegaConf object.

Random task samples

meds-sample-random-tasks \
	data_dir=/path/to/MEDS \
	out_dir=/path/to/random_tasks \
	split=train \
	sampling.num_queries=1024 \
	sampling.min_prediction_times_per_subject=50

Output is partitioned under random_tasks/{split}/*.parquet; restartable intermediate artifacts use the sibling random_tasks_artifacts/{split}/ directory. Machine-readable summary statistics are written to random_tasks_artifacts/{split}/_summary.json.

sampling.query_codes defaults to ${data_dir}, which resolves the full vocabulary from {data_dir}/metadata/codes.parquet. Point it at an explicit list, a codes.parquet, or a YAML file to sample from a narrower universe. sampling=smoke swaps in a tiny draw for checking a pipeline end to end.

Dense task grids

meds-generate-task-grid \
	data_dir=/path/to/MEDS \
	out_dir=/path/to/task_grid \
	split=held_out \
	'grid.query_codes=[CODE_A,CODE_B]' \
	'grid.durations=[30,90,180,365,731]'

Grid rows are written to task_grid/{split}/{shard}.parquet. Optional unique prediction times use the sibling task_grid_unique/ root and per-shard summaries use task_grid_summary/. Nullable/censored labels are retained by default; use grid=everyquery_eval (or grid.censored_rows=drop) to reproduce current EveryQuery evaluation output.

Every shard of the split is built in sorted order. To fan the work out across jobs instead, name one shard per invocation with input_shard=0, or sweep them in one command:

meds-generate-task-grid --multirun input_shard=0,1,2 data_dir=/path/to/MEDS out_dir=/path/to/task_grid

Configuration

Every setting lives in a YAML file under src/meds_random_task_sampler/configs/ and can be overridden on the command line. --help prints the fully composed config and the available config groups; --cfg job prints just the config a run would use, without running it.

Key Meaning
data_dir MEDS dataset root (required)
out_dir final-output root (required); sibling roots derive their names from it
split which MEDS split to read
seed seeds every draw; the query and context axes reproduce independently
overwrite redo work whose output already exists instead of skipping it
log_dir where Hydra writes its run log and resolved-config snapshot; never a data root
input_shard dense grid only: build one named shard instead of all of them
sampling.* the RandomTaskSamplerConfig fields — options: default, smoke
grid.* the TaskGridGeneratorConfig fields — options: default, everyquery_eval

Each config group holds exactly the fields of its dataclass, so a key that drifts from the dataclass fails at the command boundary rather than deep in a stage. To keep site-specific defaults outside the package, copy the config directory and compose against it with --config-dir /path/to/my_configs.

Python API

The commands are a thin shell over the public API, which takes ordinary Python values:

from meds_random_task_sampler import RandomTaskSamplerConfig, sample_random_tasks

result = sample_random_tasks(
    data_dir="/path/to/MEDS",
    output_dir="/path/to/random_tasks",
    split="train",
    config=RandomTaskSamplerConfig(
        num_queries=1024,
        num_contexts_per_query=1,
        min_prediction_times_per_subject=50,
        query_codes="/path/to/MEDS",
    ),
)

generate_task_grid / generate_task_grids and TaskGridGeneratorConfig are the dense-grid equivalents.

See DESIGN.md for the behavioral contract and planned EveryQuery adapter boundary.

Development

uv sync --group dev
uv run pytest -v
uv run pre-commit run --all-files

This repository retains the McDermottHealthAI/MHAL-template project structure.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meds_random_task_sampler-0.2.0.tar.gz (147.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

meds_random_task_sampler-0.2.0-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file meds_random_task_sampler-0.2.0.tar.gz.

File metadata

  • Download URL: meds_random_task_sampler-0.2.0.tar.gz
  • Upload date:
  • Size: 147.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for meds_random_task_sampler-0.2.0.tar.gz
Algorithm Hash digest
SHA256 59e3a51d8afca9918fa8eef405cdfc338a269fd6a45c2247b7c9ec301153abe6
MD5 64da782b2bb0a5224b544302218de781
BLAKE2b-256 2dfd0bf745e0b3425edb7dae6521f6117c764309cf863ccf9679afe863d6f23e

See more details on using hashes here.

Provenance

The following attestation bundles were made for meds_random_task_sampler-0.2.0.tar.gz:

Publisher: python-build.yaml on florian6973/meds-random-task-sampler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file meds_random_task_sampler-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for meds_random_task_sampler-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fb0980e273566251fc872abfa3a7be6169d8e1ab6986c58562bd833999057b2
MD5 80294a1d714ee9cd2744efc7b48cc75a
BLAKE2b-256 3e61cb56aa68bd20e5b292947510bf9bea3cd19b10d4d59ca254461c1b1a4df5

See more details on using hashes here.

Provenance

The following attestation bundles were made for meds_random_task_sampler-0.2.0-py3-none-any.whl:

Publisher: python-build.yaml on florian6973/meds-random-task-sampler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page