Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
907acf4
feat(benchmarks): add the 94-fault model of spec 007 and an implement…
lachlangrose Nov 27, 2026
d979cff
docs(spec): add plan and tasks for 007-native-fault-kernel
lachlangrose Nov 27, 2026
cceb9b5
feat(fault): add wave 1 of spec 007: fault module stubs, red tests, S…
lachlangrose Nov 27, 2026
61b72cd
docs(spec): record the wave 1 review of spec 007
lachlangrose Nov 27, 2026
2c719e1
feat(fault): compute the restore order once and port the grid, profil…
lachlangrose Nov 27, 2026
7216f64
fix(fault): correct review findings of wave 2
lachlangrose Nov 27, 2026
599890b
docs(spec): record the cutter chain and region rules of the native ke…
lachlangrose Nov 27, 2026
9bddcc3
feat(fault): restore points natively and add the native benchmark switch
lachlangrose Nov 27, 2026
c9a6b54
docs(spec): record the wave 3 review of spec 007
lachlangrose Nov 27, 2026
66af722
feat(fault): share the restoration of a cut frame and bind the fault …
lachlangrose Nov 27, 2026
60139c0
docs(spec): record the wave 4 review of spec 007
lachlangrose Nov 27, 2026
6d92907
test(fault): add native parity and safety tests, the gradient binding…
lachlangrose Nov 27, 2026
3ee2290
docs(spec): record the wave 5 review of spec 007
lachlangrose Nov 27, 2026
1fb6918
feat(fault): use the native fault kernel for supported features
lachlangrose Nov 27, 2026
dcad71c
docs(spec): record the wave 6 review of spec 007
lachlangrose Nov 27, 2026
fb85400
test(fault): measure the native restoration and add the native field …
lachlangrose Nov 27, 2026
afe0f59
fix(test): correct review findings of wave 7
lachlangrose Nov 27, 2026
2d44bda
docs(spec): record the wave 7 review of spec 007
lachlangrose Nov 27, 2026
23134f8
feat(fault): evaluate supported feature values and gradients natively
lachlangrose Nov 27, 2026
d12101b
docs(spec): record the wave 8 review of spec 007
lachlangrose Nov 27, 2026
f8a612e
docs(spec): record stage S2 and the stage S3 measurements of spec 007
lachlangrose Nov 27, 2026
567ec36
docs(spec): make the last task of spec 007 need T036
lachlangrose Nov 27, 2026
f03510d
docs(spec): record the wave 9 review of spec 007
lachlangrose Nov 27, 2026
fb1875a
fix(benchmarks): let the 94-fault benchmark run with the native path;…
lachlangrose Nov 27, 2026
3d6cc26
docs(spec): record the wave 10 review of spec 007
lachlangrose Nov 27, 2026
3260064
docs(spec): record SC-006 and stage S4 of spec 007
lachlangrose Nov 27, 2026
4e4359c
style(fault): format _native_faults.py and record the end review of s…
lachlangrose Nov 27, 2026
9f41453
docs(spec): plan and tasks for stage S5, package loop-model-core
lachlangrose Nov 27, 2026
51e45ca
refactor(fault): move the native fault kernel into the new package lo…
lachlangrose Nov 27, 2026
6c501f4
docs(spec): record the wave 12 review of spec 007
lachlangrose Nov 27, 2026
d666ae6
build(fault): use loop-model-core from LoopStructural, CI and release
lachlangrose Nov 27, 2026
f89026e
docs(spec): record the wave 13 review of spec 007
lachlangrose Nov 27, 2026
02e8cb4
fix(fault): treat a negative thread count as all cores and send fault…
lachlangrose Nov 27, 2026
a95d2e7
docs(spec): record the wave 14 review of spec 007
lachlangrose Nov 27, 2026
2f2a06e
docs(roadmap): record stage S5 of spec 007, package loop-model-core
lachlangrose Nov 27, 2026
5c7a673
docs(spec): record the wave 15 review of spec 007
lachlangrose Nov 27, 2026
1c6cbcd
docs(spec): record the final checks of stage S5 of spec 007
lachlangrose Nov 27, 2026
0f35f75
docs(spec): record the stage S5 end review of spec 007
lachlangrose Nov 27, 2026
e6543a9
docs(spec): check the native path on the 94-fault model
lachlangrose Nov 27, 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
8 changes: 8 additions & 0 deletions .dev-tools/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
"format": "cargo fmt --check",
"lint": "cargo clippy --all-targets -- -D warnings"
}
},
"packages/loop_model_core": {
"commands": {
"check": "cargo check --all-targets",
"test": "cargo test --release",
"format": "cargo fmt --check",
"lint": "cargo clippy --all-targets -- -D warnings"
}
}
}
}
Expand Down
127 changes: 127 additions & 0 deletions .github/workflows/model-core-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: "Native model wheels"

# Build the wheels and the sdist of loop-model-core.
# pypi.yml calls this workflow and then publishes the files.
# A pull request that changes the crate also runs it, so a broken wheel
# build shows before a release.
#
# The crate uses abi3-py39, so one wheel for each platform works with all
# Python versions from 3.9.

on:
workflow_call:
pull_request:
branches:
- master
paths:
- 'packages/loop_model_core/**'
- '.github/workflows/model-core-wheels.yml'
workflow_dispatch:

permissions:
contents: read

env:
MANIFEST: packages/loop_model_core/Cargo.toml

jobs:
wheels:
name: Wheel ${{ matrix.platform.name }}
runs-on: ${{ matrix.platform.runner }}
strategy:
fail-fast: false
matrix:
platform:
- { name: linux-x86_64, runner: ubuntu-latest, target: x86_64, smoke: true }
- { name: linux-aarch64, runner: ubuntu-24.04-arm, target: aarch64, smoke: true }
- { name: macos-arm64, runner: macos-latest, target: aarch64, smoke: true }
# Cross-compiled on the arm64 runner, so it is not run here.
- { name: macos-x86_64, runner: macos-latest, target: x86_64, smoke: false }
- { name: windows-x86_64, runner: windows-latest, target: x64, smoke: true }
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
# On Linux the build runs in a manylinux container.
- name: Build the wheel
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
manylinux: auto
args: --release --out dist --manifest-path ${{ env.MANIFEST }}
- name: Install the wheel and restore points across a fault
if: matrix.platform.smoke
shell: bash
run: |
python -m pip install numpy
python -m pip install --no-index --find-links dist loop-model-core
python - <<'EOF'
import numpy as np
import loop_model_core as core

i, j, k = np.meshgrid(np.arange(21.0), np.arange(21.0), np.arange(21.0), indexing="ij")
x = i.ravel(order="F")
y = j.ravel(order="F")
z = k.ravel(order="F")


def grid(values):
return {
"origin": [0.0, 0.0, 0.0],
"nsteps": [21, 21, 21],
"step_vector": [1.0, 1.0, 1.0],
"local_origin": None,
"local_rotation": None,
"values": np.asarray(values, dtype=np.float64),
}


spec = {
"version": 1,
"block": {"side_epsilon": 1e-9, "extension": "smooth", "exact": 0.25, "limit": 0.5, "step": 1e-3},
"faults": [
{
"name": "f",
"displacement": 10.0,
"steps": 10,
"frame": [grid(x - 10), grid(y), grid(z)],
"cutters": [],
"regions": [[], [], []],
"profile": {"scale": 1.0, "gx": {"kind": "ones"}, "gy": {"kind": "ones"}, "gz": {"kind": "ones"}},
}
],
}
chain = core.FaultChain(spec)
out = chain.restore(
np.array([[5.0, 5.0, 5.0], [12.0, 4.0, 8.0]]),
np.array([0], dtype=np.int64),
False,
np.array([2], dtype=np.int8),
np.array([False]),
0,
)
assert np.allclose(out, [[5, 15, 5], [12, 14, 8]], rtol=0, atol=1e-12), out
print("fault kernel restore ok")
EOF
- uses: actions/upload-artifact@v4
with:
name: model-core-wheel-${{ matrix.platform.name }}
path: dist/*.whl
if-no-files-found: error

sdist:
name: Sdist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build the sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path ${{ env.MANIFEST }}
- uses: actions/upload-artifact@v4
with:
name: model-core-sdist
path: dist/*.tar.gz
if-no-files-found: error
28 changes: 26 additions & 2 deletions .github/workflows/native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ on:
- master
paths:
- 'packages/loop_interpolation_core/**'
- 'packages/loop_model_core/**'
- 'packages/loop_interpolation/src/loop_interpolation/_native.py'
- 'LoopStructural/modelling/features/_native_faults.py'
- 'LoopStructural/utils/_fault_block.py'
- '.github/workflows/native.yml'
pull_request:
branches:
- master
paths:
- 'packages/loop_interpolation_core/**'
- 'packages/loop_model_core/**'
- 'packages/loop_interpolation/src/loop_interpolation/_native.py'
- 'LoopStructural/modelling/features/_native_faults.py'
- 'LoopStructural/utils/_fault_block.py'
- '.github/workflows/native.yml'
workflow_dispatch:

Expand All @@ -26,6 +32,7 @@ permissions:
env:
CARGO_TERM_COLOR: always
MANIFEST: packages/loop_interpolation_core/Cargo.toml
MODEL_MANIFEST: packages/loop_model_core/Cargo.toml

jobs:
# Format, lint and test the crate with all feature sets.
Expand All @@ -44,7 +51,8 @@ jobs:
~/.cargo/registry
~/.cargo/git
packages/loop_interpolation_core/target
key: rust-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }}
packages/loop_model_core/target
key: rust-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock', 'packages/loop_model_core/Cargo.lock') }}
restore-keys: rust-${{ runner.os }}-
- name: Format
run: cargo fmt --manifest-path "$MANIFEST" --check
Expand All @@ -61,6 +69,18 @@ jobs:
run: cargo test --manifest-path "$MANIFEST" --release
- name: Test, parallel
run: cargo test --manifest-path "$MANIFEST" --release --features parallel
- name: Model core format
run: cargo fmt --manifest-path "$MODEL_MANIFEST" --check
- name: Model core clippy, no features
run: cargo clippy --manifest-path "$MODEL_MANIFEST" --all-targets -- -D warnings
- name: Model core clippy, parallel
run: cargo clippy --manifest-path "$MODEL_MANIFEST" --all-targets --features parallel -- -D warnings
- name: Model core clippy, python
run: cargo clippy --manifest-path "$MODEL_MANIFEST" --all-targets --features python -- -D warnings
- name: Model core test, no features
run: cargo test --manifest-path "$MODEL_MANIFEST" --release
- name: Model core test, parallel
run: cargo test --manifest-path "$MODEL_MANIFEST" --release --features parallel

# Build the Python wheel and run the Python tests with the native core installed.
wheel:
Expand All @@ -81,7 +101,8 @@ jobs:
~/.cargo/registry
~/.cargo/git
packages/loop_interpolation_core/target
key: wheel-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }}
packages/loop_model_core/target
key: wheel-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock', 'packages/loop_model_core/Cargo.lock') }}
restore-keys: wheel-${{ runner.os }}-
# maturin develop needs a virtual environment.
# The Linux and macOS folder is bin. The Windows folder is Scripts.
Expand All @@ -95,6 +116,9 @@ jobs:
python -m pip install -e packages/loop_common -e packages/loop_interpolation
maturin develop --release -m packages/loop_interpolation_core/Cargo.toml
python -m pytest packages/loop_interpolation/tests -q
maturin develop --release -m packages/loop_model_core/Cargo.toml
python -m pip install -e .
python -m pytest tests/fault_evaluation -q

# Build the WebAssembly package, check its size and run the browser tests.
wasm:
Expand Down
32 changes: 28 additions & 4 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ permissions:
contents: read

jobs:
# loop-interpolation-core is the Rust core behind the optional extra
# loop-interpolation[native]. It has compiled wheels, so it is built by
# core-wheels.yml and not by the sdist matrix below. No other package
# waits for it: a failed core upload does not stop their release.
# loop-interpolation-core (the solver behind loop-interpolation[native])
# and loop-model-core (the fault kernel) are Rust cores with compiled
# wheels, so they are built by core-wheels.yml and model-core-wheels.yml
# and not by the sdist matrix below. No other package waits for them: a
# failed core upload does not stop their release.
build_core:
name: Build loop-interpolation-core
uses: ./.github/workflows/core-wheels.yml
Expand All @@ -33,6 +34,29 @@ jobs:
skip-existing: true
verbose: true

build_model_core:
name: Build loop-model-core
uses: ./.github/workflows/model-core-wheels.yml

# Trusted publishing (OIDC): no password. PyPI must list this repository
# and the workflow file pypi.yml as a trusted publisher of the project loop-model-core.
upload_model_core_to_pypi:
name: Upload loop-model-core to PyPI
needs: ["build_model_core"]
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: model-core-*
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
verbose: true

# loop_common/loop_interpolation/loopstructural_visualisation are
# workspace-local deps of LoopStructural (see [tool.uv.sources] in
# pyproject.toml) — loop_common/loop_interpolation are runtime deps,
Expand Down
12 changes: 12 additions & 0 deletions .release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"packages/loop_common",
"packages/loop_interpolation",
"packages/loop_interpolation_core",
"packages/loop_model_core",
"packages/map2loop",
"packages/loop_link",
"packages/loopstructural_visualisation"
Expand All @@ -34,6 +35,17 @@
}
]
},
"packages/loop_model_core": {
"release-type": "python",
"component": "loop-model-core",
"extra-files": [
{
"type": "toml",
"path": "Cargo.toml",
"jsonpath": "$.package.version"
}
]
},
"packages/map2loop": {
"release-type": "python",
"component": "map2loop"
Expand Down
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"packages/loop_common": "0.2.0",
"packages/loop_interpolation": "0.3.0",
"packages/loop_interpolation_core": "0.1.0",
"packages/loop_model_core": "0.0.0",
"packages/map2loop": "3.5.1",
"packages/loopstructural_visualisation": "0.2.2",
"packages/loop_link": "0.1.0"
Expand Down
10 changes: 10 additions & 0 deletions LoopStructural/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

"""

from __future__ import annotations

import logging
from dataclasses import dataclass
from logging.config import dictConfig
Expand Down Expand Up @@ -59,6 +61,12 @@ class LoopStructuralConfig:
----------
nelements : int, optional
The default number of elements to use in interpolation, by default 10_000
native_faults : bool, optional
Turns the native fault kernel on (True) or off (False). If None, the
environment variable ``LOOPSTRUCTURAL_NATIVE_FAULTS`` decides.
native_threads : int, optional
The number of threads for the native fault kernel. If None, the kernel
uses its default (0).

Examples
--------
Expand All @@ -68,6 +76,8 @@ class LoopStructuralConfig:
"""

nelements: int = 10_000
native_faults: bool | None = None
native_threads: int | None = None

from .geometry import BoundingBox
from .interpolators import InterpolatorBuilder
Expand Down
12 changes: 12 additions & 0 deletions LoopStructural/modelling/features/_base_geological_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,24 @@ def _apply_faults(
"""

if self.faults_enabled:
from . import _native_faults

native = _native_faults.restore(
self,
evaluation_points,
reverse=reverse,
block=block,
restored_through=restored_through,
)
if native is not None:
return native
evaluation_points = restore_through(
evaluation_points,
self.faults,
reverse=reverse,
block=block,
restored_through=restored_through,
owner=self,
)
return evaluation_points

Expand Down
14 changes: 12 additions & 2 deletions LoopStructural/modelling/features/_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ def _fault_state(fault: BaseFeature) -> Hashable:
)


def _restore_direct(feature: BaseFeature, points: np.ndarray, reverse: bool) -> np.ndarray:
"""Restore points with the native kernel if it can, else with the Python path."""
from . import _native_faults

native = _native_faults.restore(feature, points, reverse=reverse)
if native is not None:
return native
return restore_through(points, feature.faults, reverse=reverse, owner=feature)


class EvaluationContext:
"""Storage for the restorations of one evaluation scope.

Expand Down Expand Up @@ -133,7 +143,7 @@ def restore(
if points.dtype.hasobject:
# An array of Python objects has no bytes to compare. Restore it without
# sharing, as the legacy path does (apply_to_points makes it float).
return restore_through(points, faults, reverse=reverse)
return _restore_direct(feature, points, reverse)
digest = _digest(points)
# The scope key holds the faults only. Features with the same ordered faults share
# one restoration inside the scope. The model does not change inside one scope.
Expand All @@ -156,7 +166,7 @@ def restore(
self._batches.pop(slot, None)
self._depth += 1
try:
restored = np.asarray(restore_through(points, faults, reverse=reverse))
restored = np.asarray(_restore_direct(feature, points, reverse))
finally:
self._depth -= 1
if restored is points or np.shares_memory(restored, points):
Expand Down
Loading
Loading