Parallel lattice loading - #187
Draft
ChristopherMayes wants to merge 2 commits into
Draft
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a reusable primitive for initializing multiple
SubprocessTaoinstances concurrently, and rewires thepytao-constraintstool to use it.Each
SubprocessTaoowns a private pipe, subprocess, FIFO, and shared-memory segment, andpytao.errorsusescontextvarsrather than global state. Nothing is shared between instances and no code path callsos.chdir, so initialization can be driven from a thread pool: the threads only block on I/O with independent child processes.New public API
pytao.parallel_subprocess_taos(startups, *, jobs=None)— context manager acceptingTaoStartupobjects or plain dicts of init arguments.pytao.TaoInitResult— per-item outcome (startup,tao,error,elapsed_time,ok).pytao.subproc.resolve_job_count()/MAX_AUTO_JOBS— job-count policy, defaulting to CPU count capped at 8.Results are streamed as a bounded-prefetch pipeline rather than materialized as a list. Up to
jobsinstances are initialized ahead of the consumer, and each is closed as soon as the consumer advances past it. This caps live subprocesses atjobsregardless of how many startups are supplied, while still overlapping caller work on one instance with initialization of the next.Initialization failures are captured per item rather than raised, so one bad lattice does not prevent the rest from loading. Everything still open is closed when the block exits, including on early
breakor an exception in the body.Note that
res.taois closed once the loop advances and must not be retained.Constraints tool
pytao-constraintsgains-j/--jobs N. Lattice loading previously ran sequentially; it now loads in parallel by default._run_latticewas split so that the loader owns process lifetime and_observe_latticeonly evaluates observables against an already-initialized instance.Output is unchanged aside from the loading header, which reports the job count when greater than one. Lattices are reported in configuration order and observations are byte-identical to a sequential run — ordering now falls out of the streaming design rather than requiring a post-hoc re-sort.
Measured on a 9-lattice configuration: 3.27 s at
-j 1, 1.28 s at-j 4, 0.56 s at-j 9.Tests
Eight tests for the loader in
test_subproc.pycovering serial/parallel parity, dict andTaoStartupinputs, ordering, isolated initialization failure, the live-subprocess bound, and cleanup on both exception and early break. Three tests intest_run.pycovering job-count resolution and parallel/serial equivalence of observations and constraint results.Notes for review
master, so the diff currently includes that commit. It will shrink once FIX: pytao should not specify Tao's default #186 lands.reference_results.jsonis regenerated here: FIX: pytao should not specify Tao's default #186 changes thehook_init_filedefault toNone, which appears in the recorded startup for each lattice. As merged, FIX: pytao should not specify Tao's default #186 does not include this regeneration, sotest_cli_reference_resultsfails on that commit standalone.THIS MATCHES TO MULTIPLE COMMAND LINE ARGUMENTSerror. A length guard inmake_tao_initwould be worthwhile.Drafted with Claude via GitHub Copilot in VS Code; all changes reviewed and tested locally.