-
Notifications
You must be signed in to change notification settings - Fork 122
FE-1429: Run trial replicates through the shared experiment runtime #9358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kube
merged 15 commits into
main
from
cf/fe-1429-run-trial-replicates-through-the-shared-experiment-backend
Sep 3, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e3b476e
FE-1340: Add an experimental WebGPU compute backend for experiments
kube a64c00c
FE-1340: Apply the house prose style to the docs it adds
kube ff7ba4a
FE-1340: Draw the GPU pipeline as a diagram
kube 2da475b
FE-1340: Fail the experiment when the GPU device is lost
kube 50443f0
FE-1340: Point WebGPU doc comments at the moved performance page
kube fa40db9
FE-1340: Complete the drawer test's context fixtures
kube 960fd75
FE-1340: Point the subpath exports at the emitted declaration files
kube c58e2f4
FE-1340: Shorten the changesets
kube b3e3917
FE-1340: Run the browser-safe entries check from the build script
kube 8999670
FE-1429: Host the Monte Carlo worker protocol on any thread runtime
kube 90c4567
FE-1429: Run trial replicates in parallel through the experiment runtime
kube 9dbcea6
FE-1429: Document the thread hosts and draw the worker factory
kube 55d307b
FE-1429: Let each host state its own parallelism
kube f75d8b9
FE-1429: Shorten the changesets
kube f123fc0
FE-1429: Keep worker hosts honest about cancellation and run lists
kube File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@hashintel/petrinaut-core": patch | ||
| "@hashintel/petrinaut-cli": patch | ||
| --- | ||
|
|
||
| Optimization trials run their seeded replicates in parallel as one sharded experiment. The Monte Carlo worker protocol attaches to any thread runtime, and the CLI's `--threads <n>` bounds the workers, defaulting to one per core minus one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@hashintel/petrinaut-core": patch | ||
| "@hashintel/petrinaut": patch | ||
| --- | ||
|
|
||
| Add an experimental WebGPU compute backend for experiments, chosen per experiment behind a user setting. It runs the net's lowered HIR on the device, declines nets it cannot run so they fall back to the CPU, and agrees with the CPU in distribution rather than seed for seed. A Compilation panel, also behind a setting, shows what the compiler made of each condition, kernel and equation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
libs/@hashintel/petrinaut-cli/src/runtime/node-simulation-worker.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * Spawning simulation workers under Node. | ||
| * | ||
| * The core's experiment runtime asks for a {@link WorkerFactory} and speaks a | ||
| * structural `WorkerLike` — `postMessage`, `addEventListener` receiving a | ||
| * `{ data }` envelope, `terminate` — so Node's `worker_threads.Worker`, which | ||
| * emits bare values through `.on("message", ...)`, is adapted here. | ||
| * | ||
| * The worker entry is a sibling bundle of `cli.js`, so it exists when the CLI | ||
| * runs from its build output. Running from source (`tsx src/cli.ts`) has no | ||
| * such file: the factory then falls back to the in-process worker, which runs | ||
| * the same protocol on the calling thread, and says so once on stderr so a | ||
| * sequential dev run is never mistaken for a parallel one. | ||
| */ | ||
| import { existsSync } from "node:fs"; | ||
| import { Worker } from "node:worker_threads"; | ||
|
|
||
| import { createInProcessMonteCarloWorker } from "@hashintel/petrinaut-core/workers/monte-carlo"; | ||
|
|
||
| import type { WorkerFactory } from "@hashintel/petrinaut-core"; | ||
|
|
||
| const workerEntryUrl = new URL("./simulation-worker.js", import.meta.url); | ||
|
|
||
| let warnedAboutFallback = false; | ||
|
|
||
| export function createNodeSimulationWorkerFactory(options?: { | ||
| /** Overrides the entry bundle, e.g. for tests. */ | ||
| entryUrl?: URL; | ||
| errorOutput?: { write: (chunk: string) => void }; | ||
| }): WorkerFactory { | ||
| const entryUrl = options?.entryUrl ?? workerEntryUrl; | ||
|
|
||
| if (!existsSync(entryUrl)) { | ||
| if (!warnedAboutFallback) { | ||
| warnedAboutFallback = true; | ||
| options?.errorOutput?.write( | ||
| `Simulation worker bundle not found at ${entryUrl.pathname}; runs execute in-process\n`, | ||
| ); | ||
| } | ||
| return createInProcessMonteCarloWorker; | ||
| } | ||
|
|
||
| return () => { | ||
| // The worker stays referenced: the trial that asked for it disposes the | ||
| // experiment in a `finally`, which terminates every worker, so the process | ||
| // neither exits before a reply is written nor outlives the request. | ||
| const worker = new Worker(entryUrl); | ||
|
|
||
| return { | ||
| postMessage: (message) => { | ||
| worker.postMessage(message); | ||
| }, | ||
| addEventListener: (_type, listener) => { | ||
| worker.on("message", (data: unknown) => { | ||
| listener({ data }); | ||
| }); | ||
| }, | ||
| terminate: () => { | ||
| void worker.terminate(); | ||
| }, | ||
| }; | ||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.