Skip to content

Store separate is-a and part-of closures in the weekly ENVO, UBERON and PO loads - #1704

Open
turbomam wants to merge 3 commits into
mainfrom
1563-ontology-closure-all
Open

turbomam wants to merge 3 commits into
mainfrom
1563-ontology-closure-all

Conversation

@turbomam

@turbomam turbomam commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

On this branch, I gave the load_ontology op a closure setting and set it to all in the weekly ENVO, UBERON and PO schedules. Each load then stores a term's "is a kind of" ancestors and its "is part of" ancestors as separate predicates in ontology_relation_set, beside the mixed set it stores now. nmdc-server's ENVO ingest reads only the mixed set (https://github.com/microbiomedata/nmdc-server/blob/e8ab95276c5c4c46354e48090048de2240e45a37/nmdc_server/ingest/envo.py#L80), so the Data Portal doesn't change. The separate sets let people ask "is a kind of" questions directly, and give the portal what it needs if we decide its filters should stop following "is part of".

Details

ontology-loader 0.5.0, already pinned on main, can write three ancestor predicates:

  • entailed_isa_partof_closure follows both rdfs:subClassOf and BFO:0000050 (part of). It is the only one stored now.
  • entailed_isa_closure follows only rdfs:subClassOf.
  • entailed_partof_closure follows BFO:0000050, and also the rdfs:subClassOf steps above the whole. Rhizosphere (ENVO:00005801) is part of soil (ENVO:00001998), and soil is a kind of environmental material (ENVO:00010483), so rhizosphere is listed as part of environmental material.

The op's closure setting defaults to combined, which writes only entailed_isa_partof_closure, so a job that doesn't set it behaves as before. all writes all three.

Relation rows with all, counted on 2026-11-24 with ontology-loader's own code against the semantic-sql builds (https://semanticsql.berkeleybop.io) cached on my machine:

  • ENVO: 37,309 to 76,714
  • PO: 22,175 to 46,514
  • UBERON: 501,459 to 1,055,559

nmdc-server's ingest copies every relation into its Postgres ontology_relation table, so that table grows the same way. I haven't timed a weekly UBERON load with all. If it runs too long, UBERON's schedule can go back to combined, though the rows already written would need deleting by hand.

Related issue(s)

Part of #1563, which stays open for NCBITaxon.

This stores the two closures microbiomedata/nmdc-schema#2943 asks for. It needs no schema change.

Whether the portal should use them is microbiomedata/nmdc-server#2449.

After this merges, the pure "is a kind of" query in #1432 should become a find command on entailed_isa_closure through /queries:run, instead of a $graphLookup. I haven't tried that on ontology_relation_set.

My draft #1562 adds its own closure field. I'd rebase it onto this PR once this one merges.

Related subsystem(s)

  • Runtime API (except the Minter)
  • Minter
  • Dagster
  • Project documentation (in the docs directory)
  • Translators (metadata ingest pipelines)
  • MongoDB migrations
  • Other

Testing

  • I tested these changes (explain below)
  • I did not test these changes

I tested these changes on 2026-11-24 with uv on my machine, not the Docker test stack:

  • tests/test_ops/test_load_ontology.py: both mocked tests pass, and both fail with main's nmdc_runtime/site/ops/ontology.py.
  • Dagster's validate_run_config accepts all three schedule configs, each resolving to closure: all.
  • The op with closure: all loaded ENVO into a throwaway database on a local MongoDB in 4 seconds: 4,366 classes and 76,714 relations, matching the ENVO count above.

I didn't run make test or load UBERON or PO with all.

Documentation

  • I have not checked for relevant documentation yet (e.g. in the docs directory)
  • I have updated all relevant documentation so it will remain accurate
  • Other (explain below)

Nothing in docs/ mentions closure or load_ontology.

Maintainability

  • Every Python function I defined includes a docstring (test functions are exempt from this)
  • Every Python function parameter I introduced includes a type hint (e.g. study_id: str)
  • All "to do" or "fix me" Python comments I added begin with either # TODO or # FIXME
  • I used black to format all the Python files I created/modified
  • The PR title is in the imperative mood (e.g. "Do X") and not the declarative mood (e.g. "Does X" or "Did X")

The changed files in nmdc_runtime/ pass black --check. tests/test_ops/test_load_ontology.py wasn't black-formatted on main, and I left it that way to keep the diff small.

Summary by CodeRabbit

  • New Features
    • Ontology loading now supports choosing a closure option, with “combined” selected by default. This allows different closure settings to be used where needed.
    • Weekly ENVO, Uberon, and PO ontology loads now use the “all” closure option, while other ontology loads retain the default unless configured otherwise.

The load_ontology op gains a closure option, passed through to ontology-loader. It defaults to combined, the only closure nmdc-server reads. The three weekly schedules set it to all, so the isa and partof closures are stored alongside combined.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Ontology closure configuration

Layer / File(s) Summary
Load op closure handling
nmdc_runtime/site/ops/ontology.py, tests/test_ops/test_load_ontology.py
The op reads and logs the configured closure, then passes it to OntologyLoaderController. Tests check the combined default and that all is passed through unchanged.
Weekly schedule closure settings
nmdc_runtime/site/repository.py
The ENVO, Uberon, and PO schedules set closure to all.

Possibly related issues

  • microbiomedata/nmdc-runtime#1515 asks for the ontology-loader controller API update, including its closure control, and confirmation of ENVO, Uberon, and PO loads. This PR adds the closure setting and updates those schedules.
  • microbiomedata/nmdc-runtime#1563 asks for per-ontology closure choices in schedule configuration. This PR adds choices for ENVO, Uberon, and PO; it does not cover the NCBITaxon decision.

Change: Feature

Merge Risk: Minimal · up to b795d

The change adds an optional closure setting that defaults to the existing behavior and enables separate is-a and part-of relations in the weekly ENVO, UBERON and PO loads. The pinned loader version supports the setting, so there is no concrete merge-blocking risk. The weekly UBERON load with the larger relation set has not been timed, which is worth watching after merge.

Security architecture risk: Low · up to f436a

The weekly loads are configured to retain the relationships used by existing filters while adding two new sets. The main risk is that a custom run can now select a mode that omits relationships those filters need. Reverting the schedule setting also does not, by itself, demonstrate that previously written data will be removed.

Retained concerns

  • Low · reliability · inferred: A caller already allowed to configure and launch the ontology job can now select a documented mode that omits the mixed closure. If that run replaces the existing mixed relations in the shared dataset, downstream environment filters can lose required ancestor data. The default and all three shipped schedules select modes that include the mixed closure; controller replacement behavior was not verified.
Security review details

Trust Boundaries and Controls

  • observed — The weekly jobs supply fixed values. Custom job configuration is the input boundary for other values, and the op passes those values to the controller using the existing Mongo resource. The source comparison does not establish who can supply custom configuration in the deployed scheduler.

Hardening Proposals

  • proposed — For jobs that publish to the shared dataset, validate the closure mode before invoking the writer and allow only modes that retain the mixed closure. Verify rollback in both MongoDB and the downstream ingest, and document any cleanup needed to restore the previous relation set.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b1f2e37-7a4d-4bb0-9c26-49161bd0b140
Commits

Reviewing files that changed from the base of the PR and between f436af6 and b795d58.

Files selected for processing: 1

  • nmdc_runtime/site/ops/ontology.py
Files skipped from review as they are similar to previous changes: 1

  • nmdc_runtime/site/ops/ontology.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@eecavanna

Copy link
Copy Markdown
Collaborator

The diff looks fine to me, but I don't know what "closure" means in this context.

Comment thread nmdc_runtime/site/ops/ontology.py Outdated
"output_directory": Field(Noneable(str), default_value=None, is_required=False),
"generate_reports": Field(bool, default_value=True, is_required=False),
# Which ancestor closures ontology-loader stores in ontology_relation_set:
# "combined" (is_a plus part of), "isa", "partof", "all" (all three) or "none".

@eecavanna eecavanna Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"combined" (is_a plus part of) ...

I don't understand why is_a is spelled with an underscore here, but part of is not. 🤷

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that was inconsistent. Fixed in b795d58

Copilot AI balanced review requested due to automatic review settings November 30, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The weekly UBERON load roughly doubles to 1.06M relations via per-item upserts, with unmeasured runtime and resource demands requiring human review of production worker capacity and the weekly load window.

No open issues 🎉

What changed in this PR

Adds configurable ancestor closures to the Runtime’s Dagster ontology loader, enabling separate is-a and part-of queries while preserving the combined closure used by the Data Portal.

Changes:

  • Adds a closure setting that defaults to combined for backward compatibility.
  • Configures weekly ENVO, UBERON, and PO loads to store all three closures.
  • Updates mocked tests to check the default and explicit all setting.
File Description
tests/​test_ops/​test_load_ontology.py Checks default and explicit closure forwarding.
nmdc_runtime/​site/​repository.py Sets the three weekly ontology loads to closure: all.
nmdc_runtime/​site/​ops/​ontology.py Defines, logs, and forwards the closure setting to the loader.

Review effort: Balanced

@turbomam

Copy link
Copy Markdown
Member Author

@eecavanna A closure is the set of a term's ancestors. Before this PR, the weekly loads stored one closure, combined, that mixes is-a and part-of ancestors. This PR also stores isa, which holds is-a ancestors only, and partof, which holds part-of ancestors.

This branch has not been deployed

No deployments
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.

3 participants