Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e26fef5
Test that QRF leaf arrays match quantile-forest's byte for byte
anth-volk Nov 17, 2026
3c313b7
Fill the QRF leaf array in place and pin quantile-forest 1.4.2
anth-volk Nov 17, 2026
4609f81
Address round-one review of the in-place leaf array
anth-volk Nov 17, 2026
27865e5
Address round-two review: close test gaps, correct docstrings, rework…
anth-volk Nov 17, 2026
1dea2d1
Address round-three review: test the remaining mutations, tighten the…
anth-volk Nov 17, 2026
e4e940a
Address round-four review: real scikit-learn 1.9, page residency, hon…
anth-volk Nov 17, 2026
1dd8568
Address round-five review: portable tests, accurate failure notes
anth-volk Nov 17, 2026
527bc7d
Address round-six review: negative weights under scikit-learn 1.9, st…
anth-volk Nov 17, 2026
eff0781
Address round-seven review: stricter measurement result checks
anth-volk Nov 17, 2026
2197a78
Address round-eight review: one safeguard for malformed measurement r…
anth-volk Nov 17, 2026
9ec0b2c
Address round-nine review: child output encoding, strict JSON, matchi…
anth-volk Nov 17, 2026
e169058
Use _InPlaceLeafQRF wherever the library class name was not required
anth-volk Nov 18, 2026
bff48ee
Raise the fitted-model cache schema version
anth-volk Nov 18, 2026
ec291bb
Remove malformed-output checks from the QRF memory script
anth-volk Nov 18, 2026
ffe20db
Merge origin/main into qrf-leaf-array-in-place
anth-volk Nov 18, 2026
8729ab5
State that the memory script's default sizes were not measured
anth-volk Nov 18, 2026
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
5 changes: 5 additions & 0 deletions changelog.d/qrf-leaf-array-in-place.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
microcosm-fit's QRF forests build their leaf array in place. quantile-forest stores, for every tree, the training rows each leaf holds in one zero-padded int64 array (trees x nodes x outputs x width); version 1.4.2 builds one array per tree and then copies the list into the final array, which writes every padding byte and makes the whole padded array resident while both copies exist. `_fit_forest` now builds `_InPlaceLeafQRF`, a subclass that allocates the final array once and fills each tree's slice directly. The array is byte-identical to the library's, so every prediction and draw is unchanged; tests compare the two classes byte for byte on continuous, capped near-discrete, multi-output and weighted fits, and compare grid predictions and draws.

- quantile-forest is pinned to exactly 1.4.2, since the subclass replaces a private method. `_InPlaceLeafQRF` refuses any other installed release, in `fit` before growing a tree and again where its copied code runs.
- `tools/measure_qrf_leaf_memory.py` fits one synthetic forest shaped like the CPS-ORG wage fit or a capped near-discrete fit through `_fit_forest`, once with each class and each in a fresh process, and reports each fit's peak memory (the peak physical footprint on macOS, the peak resident set on Linux).
- Pickling or deep-copying a fitted forest still writes the full padded array, as before. Forests now pickle as `microcosm.fit.qrf._InPlaceLeafQRF`, and loading a forest pickled before this change raises `TypeError`; refit it instead. The fitted-model cache moves to schema version 2, so entries written before this change are cache misses. scikit-learn's validation messages for a forest (a missing value in a predictor, an invalid `max_samples_leaf`) name `_InPlaceLeafQRF`; the exception types are unchanged.
16 changes: 8 additions & 8 deletions docs/evidence/spec-engine/us-f0-coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -1642,13 +1642,13 @@
"compiler_ir.node_slices"
],
"expected": {
"map_sha256": "d756dc67535c04788e605bedb4cd6721cf715e5f5ce4be73d9b27420a61b3d50",
"protocol_sha256": "2c57cbfb9dd0f132f9b5751eb8bc303f4b7e37430cd5e0b155aac0b0b8eaa42e"
"map_sha256": "afbe93ebeb8d48294581d860aed690c168eb4c2c92461353676a794cefd22584",
"protocol_sha256": "05fb40521ffef194cec9c2fe4dfedbbfd02e64ddddfd69f1a591961b61804176"
},
"failures": [],
"observed": {
"map_sha256": "d756dc67535c04788e605bedb4cd6721cf715e5f5ce4be73d9b27420a61b3d50",
"protocol_sha256": "2c57cbfb9dd0f132f9b5751eb8bc303f4b7e37430cd5e0b155aac0b0b8eaa42e"
"map_sha256": "afbe93ebeb8d48294581d860aed690c168eb4c2c92461353676a794cefd22584",
"protocol_sha256": "05fb40521ffef194cec9c2fe4dfedbbfd02e64ddddfd69f1a591961b61804176"
},
"status": "covered"
},
Expand All @@ -1663,7 +1663,7 @@
"compiler_ir.seed_stream_map"
],
"expected": {
"implementation_sha256": "2c57cbfb9dd0f132f9b5751eb8bc303f4b7e37430cd5e0b155aac0b0b8eaa42e",
"implementation_sha256": "05fb40521ffef194cec9c2fe4dfedbbfd02e64ddddfd69f1a591961b61804176",
"protocol": "legacy-v1",
"streams": [
"build_model",
Expand All @@ -1684,7 +1684,7 @@
},
"failures": [],
"observed": {
"implementation_sha256": "2c57cbfb9dd0f132f9b5751eb8bc303f4b7e37430cd5e0b155aac0b0b8eaa42e",
"implementation_sha256": "05fb40521ffef194cec9c2fe4dfedbbfd02e64ddddfd69f1a591961b61804176",
"protocol": "legacy-v1",
"streams": [
"build_model",
Expand Down Expand Up @@ -2585,7 +2585,7 @@
"country": "us",
"schema_id": "country_spec",
"schema_version": 1,
"spec_sha256": "0088d3f69666b09e28b94bbf8b1b2f07ebf0b8a32cec6d0a8358b568a7f35ac6"
"spec_sha256": "f5eb16a0ff78a0b6622c7701f22a9f12a466e5f2729fd83c200ccc3b519c0292"
}
},
"report_schema_version": 3,
Expand All @@ -2595,7 +2595,7 @@
"country": "us",
"schema_id": "country_spec",
"schema_version": 1,
"spec_sha256": "0088d3f69666b09e28b94bbf8b1b2f07ebf0b8a32cec6d0a8358b568a7f35ac6"
"spec_sha256": "f5eb16a0ff78a0b6622c7701f22a9f12a466e5f2729fd83c200ccc3b519c0292"
},
"status": "pass"
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,10 @@
# microcosm#1641 moves both again: it rewords docstrings and a comment in
# solve and the delivery gate's docstring in ssi_take_up, which now names
# the builder's arms by flag; no draw, RNG rule, QRF target or solve changes.
"seed_map": "d756dc67535c04788e605bedb4cd6721cf715e5f5ce4be73d9b27420a61b3d50",
"seed_protocol": "2c57cbfb9dd0f132f9b5751eb8bc303f4b7e37430cd5e0b155aac0b0b8eaa42e",
# The in-place QRF leaf array in microcosm.fit.qrf moves both again: the
# forests' leaf arrays are byte-identical, and no draw changes.
"seed_map": "afbe93ebeb8d48294581d860aed690c168eb4c2c92461353676a794cefd22584",
"seed_protocol": "05fb40521ffef194cec9c2fe4dfedbbfd02e64ddddfd69f1a591961b61804176",
"source_manifest": "dc3879886d2a69f20fb982a675d7fb322c0e4017afef6471be54b0ee3cbd2af6",
"take_up": "9522ce40f7dea569312dd7a7beb474e5a5afadd2f1e10cb5876534c3ef623d35",
"tail": "565f0ceeadab69d3e96a886a00dd0305f7425fa3acde24d12ba48db2b37d5fc0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
PRIMARY_QRF_WORKER_MODULE = "microcosm.build.us_runtime.puf_qrf_worker"
PRIMARY_QRF_INTERPRETER_PLACEHOLDER = "{python_interpreter}"
APPROVED_UV_LOCK_SHA256 = (
"6a823b13f3ee70a454ebf6828631037fc0f13a9e0dc8e7624ae8dfb68e0f4b89"
"67037e0ecbd8d4eb700756371a8ba1c7637dc3b884c44ccd0126fdb757e5df88"
)
LEGACY_CAMPAIGN_UV_LOCK_SHA256 = (
"27f47e385cfa35e2644a37410d1804b361ad9aee123577551c8421547bda65ee"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def test_semantic_hash_has_golden_vector_and_surface_separation(tmp_path) -> Non
# kernels' bytes too.
# microcosm#1641's docstring and comment wording in solve and ssi_take_up
# moves it again.
# The in-place QRF leaf array moves the fit kernels' bytes again.
assert first.spec_sha256 == (
"cb9742d5089eddb8783ee1cb890206b33a35efe5ff572656dbd58a1b95ea1e28"
"30d83d44c9c004c76f49c6ff36d9eb2249f30632f00e3ff72691121100c39d1a"
)

second_root = _rich_minimal(tmp_path / "xy", note="second", store="local:b")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ def capture_equality(expected: object, actual: object) -> None:
# microcosm#1641 moves it again: docstring and comment wording in
# solve and ssi_take_up, and the calibration contract's renamed modes.
# microcosm#1585's us/gates.json row in country_package.json moves it.
"spec_sha256": "0088d3f69666b09e28b94bbf8b1b2f07ebf0b8a32cec6d0a8358b568a7f35ac6",
# The in-place QRF leaf array in microcosm.fit.qrf moves it again.
"spec_sha256": "f5eb16a0ff78a0b6622c7701f22a9f12a466e5f2729fd83c200ccc3b519c0292",
},
}

Expand Down
12 changes: 10 additions & 2 deletions packages/microcosm-fit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ doing only calibration never pulls them.

`scikit-learn` is unpinned on the upper side (`>=1.5`): the shard's test suite
passes on both 1.8 and 1.9, so it coexists in one environment with a
`scikit-learn>=1.9` consumer. This requires `quantile-forest>=1.4.2`, the first
release that tracks the sklearn-1.9 tree ABI
`scikit-learn>=1.9` consumer. That needs quantile-forest 1.4.2 or later, the
first release that tracks the sklearn-1.9 tree ABI
(zillow/quantile-forest#152, #153); older `quantile-forest` fails to import
under sklearn 1.9.

`quantile-forest` is pinned exactly (`==1.4.2`). `microcosm.fit.qrf` builds
each forest with a subclass that replaces quantile-forest's private
`BaseForestQuantileRegressor._get_y_train_leaves` with a copy of 1.4.2's that
fills the leaf array in place instead of copying a list of per-tree arrays,
and its `fit` refuses any other installed release. A scikit-learn release
that breaks quantile-forest 1.4.2 therefore needs the pin, the copied method
and `_SUPPORTED_QUANTILE_FOREST_VERSION` moved together.
18 changes: 13 additions & 5 deletions packages/microcosm-fit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ dependencies = [
"microcosm-graph>=0.1,<0.2",
# scikit-learn 1.9 removed sklearn.tree._tree.DTYPE and changed the
# sample-weight signature of the forest bootstrap helpers; quantile-forest
# 1.4.2 (2026-06-21) tracks both (zillow/quantile-forest#152, #153), so the
# floor below is the first release compatible with sklearn 1.9. No upper
# bound: this package's own sklearn usage (HistGradientBoostingClassifier,
# forest .fit() without sample_weight) is stable across 1.5-1.9.
# 1.4.2 (2026-06-21) tracks both (zillow/quantile-forest#152, #153), so it
# is the first release compatible with sklearn 1.9. No upper bound: this
# package's own sklearn usage (HistGradientBoostingClassifier, forest
# .fit() without sample_weight) is stable across 1.5-1.9. The leaf-array
# copy in microcosm.fit.qrf also calls sklearn's private bootstrap helpers,
# through quantile-forest's module, with the arguments 1.4.2 passes them
# for the installed sklearn version.
"scikit-learn>=1.5",
"quantile-forest>=1.4.2",
# Exact: microcosm.fit.qrf._InPlaceLeafQRF replaces the private
# BaseForestQuantileRegressor._get_y_train_leaves with a copy of 1.4.2's
# that fills the leaf array in place, and refuses to fit under any other
# release (_SUPPORTED_QUANTILE_FOREST_VERSION). Raise both together, after
# comparing the override with the new release's method.
"quantile-forest==1.4.2",
"numpy>=2",
"pandas>=2.3",
]
Expand Down
2 changes: 1 addition & 1 deletion packages/microcosm-fit/src/microcosm/fit/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from typing import Any

SCHEMA_VERSION = 1
SCHEMA_VERSION = 2


@dataclass(frozen=True)
Expand Down
Loading
Loading