Repository for reproducing the experiments for the MIRA manuscript.
src/contains the core implementation, run entrypoints, evaluations, and structured data/output folders.
From the repository root (for example .../MIRA/, not the parent directory):
git clone https://github.com/Dyke-F/MIRA.git
cd MIRARun setup only from MIRA/:
python3.12 -m venv src/.venv
source src/.venv/bin/activate
python -m pip install -U pip uv
uv pip install -e ./srcCreate src/.env (for example by copying src/.env.example) and filling in all environment variables.
Use this sequence before running any step scripts/notebooks:
src/README.md- Confirms package installation context (
uv pip install -e ./src).
- Confirms package installation context (
src/dataset/README.md- Required before
src/dataset/make_dataset.pyorsrc/dataset/make_admission_datasets.py. - Explains required MIMIC path environment variables.
- Required before
src/notebooks/README.md- Required before notebook-based preprocessing (
extract_pancreatic_cancer_info.ipynb,build_procedure_db.ipynb).
- Required before notebook-based preprocessing (
src/backend/README.md- Required before starting local HAPI FHIR and running code that posts FHIR resources.
src/raw/README.mdandsrc/resources/README.md- Explain what data folders/files are expected to be empty vs generated.
src/runs/README.md- Required before simulation notebooks in
src/runs/.
- Required before simulation notebooks in
src/evaluations/README.md- Required before evaluation notebooks/scripts in
src/evaluations/.
- Required before evaluation notebooks/scripts in
- Optional maintenance only:
src/MimicEnums/README.mdsrc/codes/README.md
src/
├── runs/ # run entrypoints (python + notebooks)
├── evaluations/ # evaluation notebooks/scripts
├── dataset/ # dataset preparation logic
├── backend/ # FHIR backend integration
├── MimicEnums/ # enums used by tools/evaluation typing
├── tools.py ... # core agent/tool code
├── paths.py # central canonical paths
├── resources/ # stable input assets used by runs/tools
├── notebooks/ # non-entrypoint utility notebooks
└── raw/ # generated/runtime data (evaluable outputs, qdrant, archives)
From the repository root (MIRA/) unless a linked README says otherwise.
Before each step, read the linked sub-README first.
Canonical package order for end-to-end reproduction:
src/dataset -> src/notebooks (pancreatic context) -> src/backend + Qdrant -> src/notebooks (procedure DB) -> src/runs -> src/evaluations.
src/MimicEnums and src/codes regeneration are optional maintenance steps and are not required for standard runs.
- Build diagnosis datasets (read first:
src/dataset/README.md)
uv run --project src python src/dataset/make_dataset.pyThis populates src/raw/derived/diagnosis_datasets/ (or MIRA_DIAGNOSIS_DATASETS_DIR if overridden).
Optional (only for optional-admission experiments):
uv run --project src python src/dataset/make_admission_datasets.pyThis requires edited Excel inputs under src/raw/inputs/optional_admission/pneumonia/**/*.xlsx and src/raw/inputs/optional_admission/pe/**/*.xlsx.
Useful env options for script runs:
# only run selected diagnoses (comma-separated)
export MIRA_DATASET_DIAGNOSES="appendicitis,pancreatitis"
# optional cap on number of diagnoses
export MIRA_MAX_DIAGNOSES=1
# optional per-diagnosis admission subset (fast smoke tests)
export MIRA_MAX_HADM_IDS_PER_DIAGNOSIS=20
# overwrite handling for existing dataset folders:
# ask (default) | yes | no
export MIRA_OVERWRITE_DATASETS=askImportant:
- If
MIRA_OVERWRITE_DATASETS=askand a diagnosis dataset already exists, the script waits for terminal input:Dataset exists at ... Overwrite? (y/n): - You must type
yand press Enter to continue that diagnosis. If you typen, that diagnosis is skipped. - For unattended full runs, use
export MIRA_OVERWRITE_DATASETS=yes.
For full extraction across all diagnoses, clear subset envs:
unset MIRA_DATASET_DIAGNOSES
unset MIRA_MAX_HADM_IDS_PER_DIAGNOSIS
unset MIRA_MAX_DIAGNOSES
uv run --project src python src/dataset/make_dataset.py- Prepare pancreatic cancer context resource (required when running pancreatic cancer cases; read first:
src/notebooks/README.md)
Requires OPENAI_API_KEY and diagnosis datasets from Step 1.
# open and run all cells
src/notebooks/extract_pancreatic_cancer_info.ipynbThis notebook writes directly to src/resources/pancreatic_cancer_info.json.
- (Optional) Regenerate MIMIC enums/code maps (read first:
src/MimicEnums/README.mdandsrc/codes/README.md)
Not required for standard runs. The generated enums are already versioned under src/MimicEnums/.
Use src/MimicEnums/make_enums_and_code_maps.py only when intentionally refreshing enum/code-map artifacts.
Medication code-map regeneration is separate and optional; see src/codes/README.md.
- Start local FHIR backend (read first:
src/backend/README.md)
docker compose -f src/backend/hapi-fhir-server/docker-compose.yml up -d- Start Qdrant (local; read first:
src/notebooks/README.mdandsrc/raw/README.md)
docker run -p 6333:6333 -p 6334:6334 \
-v "$(pwd)/src/raw/runtime/qdrant/main:/qdrant/storage:z" \
-e QDRANT__TELEMETRY_DISABLED=true \
qdrant/qdrant- Build procedure vector DB (read first:
src/notebooks/README.md)
Run this after Step 5 so Qdrant is available.
# open and run all cells
src/notebooks/build_procedure_db.ipynb- Run simulations (read first:
src/runs/README.md)
- Baseline:
src/runs/run_simulation.ipynb(usessrc/runs/run.py) - Bias:
src/runs/run_simulation_bias.ipynb(usessrc/runs/run.py+src/runs/run_with_sex_bias.py) - Optional admission experiments:
src/runs/run_simulation_optional_admission.ipynb(usessrc/runs/run_optional_admission.py) - Optional leakage/adversarial analysis:
src/runs/run_leakage_and_adversarial.ipynb(uses existing simulation outputs) - Before running each notebook, review its first parameter cells (
DATASET_NAMES, sample-size settings, selectedhadm_ids).- Experimetns can be ressource-intensive and take long, so some notebooks contain
breakorrun_cell=Falsecommands that need to be removed/set to True beforefull runscan be done. - Open run notebooks from
src/runs/so local imports resolve as written.
- Experimetns can be ressource-intensive and take long, so some notebooks contain
Run outputs are written under src/raw/evaluable_outputs/.
- Run evaluations (read first:
src/evaluations/README.md)
Follow src/evaluations/README.md:
evaluations_MIRA.ipynbfor evaluating the MIRA agent.evaluations_HUMANS.ipynbonly if human baseline outputs are available.
src/backend/README.mdsrc/codes/README.mdsrc/dataset/README.mdsrc/MimicEnums/README.mdsrc/notebooks/README.mdsrc/raw/README.mdsrc/resources/README.mdsrc/runs/README.mdsrc/evaluations/README.md