Incremental compilation and caching¶
quivers.incremental keeps a project's caches in one persistent directory and runs compilation
and fitting against it: the store holds content-addressed artifacts with a size limit,
the query engine memoizes compiler stages with red-green invalidation, the
module build checks a module graph incrementally, the fit cache reuses
fits and runs, source identity hashes source text, and the
migration gate checks that migrations preserve core hashes. The semantics is
stated in Content identity.
incremental
¶
Incremental compilation, persistent caches, and fit caching.
Three layers share one project cache directory:
ArtifactStore: a persistent, size-limited, content-addressed store,.qvr/cacheat the project root;QueryEngine: memoized compiler queries with red-green invalidation and early cutoff, optionally persisted in the store;FitCache: fits and runs keyed by content hashes, so a refactor that leaves the checked core unchanged reuses an earlier fit.
Every key that depends on the engine includes
engine_identity.
CORPUS_ROOTS
module-attribute
¶
CORPUS_ROOTS: tuple[str, ...] = ('docs/examples/source', 'docs/examples/qiec', 'docs/tutorials/qvr/source', 'tests/benchmarks/models', 'tests/transpile/fixtures', 'regression.qvr')
The .qvr corpus the gate runs over, relative to the repository root.
CACHE_DIRECTORY_VARIABLE
module-attribute
¶
The environment variable that overrides the cache directory.
DEFAULT_MAX_BYTES
module-attribute
¶
The byte limit of a store that has not been given one: 2 GiB.
CACHE_FORMAT
module-attribute
¶
The layout version of the store directory; a store of another layout is a sibling directory, never read.
PROJECT_MARKERS
module-attribute
¶
The entries whose presence marks a directory as a project root, in the order a search checks them in each directory.
ExternalValue
¶
ExternalValue = None | bool | int | float | str | Tensor | Model | ArrayLike | Sequence[ExternalValue] | Mapping[str, ExternalValue]
A value supplied to a fit or run from outside the program: a datum, a site value, a static argument, or a configuration record.
FitKind
¶
What a key addresses: a Model.fit
result or an invoke_entry run.
HopStatus
¶
What the gate found for one hop and one file:
preserved: the hop rewrote the file and every core hash survived;identical: the hop left the bytes unchanged;changed: the hop rewrote the file and some core hash changed, which fails the gate;rejected: the file is not valid source at the hop's revision, or the migrated text does not check atHEAD, so the hop is not tested on it;semantic: the hop declares that it may change meaning.
QueryAction
¶
What the engine did for one query key:
input: an input took a value with a new fingerprint;execute: a query ran and its result changed (or was new);cutoff: a query ran and its result kept its fingerprint, so it was backdated and its dependents stay valid;green: a query was verified without running;load: a query's result was reused from the persistent store after its recorded dependencies were verified, without running.
ArrayLike
¶
Bases: Protocol
A value that exposes an array view, such as a NumPy array.
CachedRun
didactic-model
¶
CachedRun(*, key: str, hit: bool, payload: JsonValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: ValueModel
A run's result, as qvr run --json prints it.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The digest of the run's key.
TYPE:
|
hit
|
Whether the payload came from the store.
TYPE:
|
payload
|
The run's mutable JSON data, compared by identity.
TYPE:
|
FitCache
¶
FitCache(store: ArtifactStore, *, engine: str | None = None, factories: Mapping[str, ArtifactFactory] | None = None)
A content-addressed cache of fits and runs in an artifact store.
| PARAMETER | DESCRIPTION |
|---|---|
store
|
Where artifacts persist.
TYPE:
|
engine
|
The engine identity digest;
TYPE:
|
factories
|
Explicit contracts for configuration values the fitted artifact format
does not know, passed to
TYPE:
|
Source code in src/quivers/incremental/fits.py
for_project
classmethod
¶
for_project(start: Path | None = None) -> FitCache
The cache of the project a path belongs to.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
A path inside the project; the working directory when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FitCache
|
A cache in the project's artifact store. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If no project root is found. |
Source code in src/quivers/incremental/fits.py
fit_key
¶
fit_key(model: Model, data: Mapping[str, ExternalValue], *, method: InferenceMethod[ModelFit], parameters: Mapping[str, ExternalValue] | None = None, input: Tensor | None = None, seed: int = 0, sample_prior: PriorMode = 'no', num_prior_samples: int = 100, prior_seed: int = 1, snapshot_policy: SnapshotPolicy = 'clone') -> FitKey
The key of a Model.fit call.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The checked model.
TYPE:
|
data
|
The external data.
TYPE:
|
method
|
The inference method.
TYPE:
|
parameters
|
Static specialization arguments.
TYPE:
|
input
|
The domain input.
TYPE:
|
seed
|
The compilation seed.
TYPE:
|
sample_prior
|
The prior-sampling mode.
TYPE:
|
num_prior_samples
|
The prior draw budget.
TYPE:
|
prior_seed
|
The prior stream's seed.
TYPE:
|
snapshot_policy
|
The refit-data ownership.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FitKey
|
The key. |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the model uses a custom family catalog, a datum or the method has no portable contract, the method declares no seed, or a datum names no parameter of the entry. |
ValueError
|
If labeled data does not match the axes of its parameter's type. |
Source code in src/quivers/incremental/fits.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
fit
¶
fit(model: Model, data: Mapping[str, ExternalValue], *, method: InferenceMethod[ModelFit], parameters: Mapping[str, ExternalValue] | None = None, input: Tensor | None = None, seed: int = 0, sample_prior: PriorMode = 'no', num_prior_samples: int = 100, prior_seed: int = 1, snapshot_policy: SnapshotPolicy = 'clone') -> ModelFit
Fit a model, reusing a stored fit with the same key.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The checked model.
TYPE:
|
data
|
The external data.
TYPE:
|
method
|
The inference method.
TYPE:
|
parameters
|
Static specialization arguments.
TYPE:
|
input
|
The domain input.
TYPE:
|
seed
|
The compilation seed.
TYPE:
|
sample_prior
|
The prior-sampling mode.
TYPE:
|
num_prior_samples
|
The prior draw budget.
TYPE:
|
prior_seed
|
The prior stream's seed.
TYPE:
|
snapshot_policy
|
The refit-data ownership.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModelFit
|
On a hit, the stored fit reloaded exactly as |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the fit has no content identity, or the method does not return
a |
StoreError
|
If the stored artifact is corrupt. |
Source code in src/quivers/incremental/fits.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
run_key
¶
run_key(module: QiecModule, name: str, arguments: Sequence[HostValue] = (), *, data: Mapping[str, HostValue] | None = None, sites: Mapping[str, HostValue] | None = None, static_arguments: Sequence[str] = (), runtime: RuntimeConfiguration | None = None, fuel: int | None = None, seed: int | None = None, numbers: NumberDomain | None = None) -> FitKey
The key of an invoke_entry run.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
name
|
The entry's name: a program or a computation.
TYPE:
|
arguments
|
Positional value arguments.
TYPE:
|
data
|
A program's parameters by name.
TYPE:
|
sites
|
Conditioned sites by label.
TYPE:
|
static_arguments
|
TYPE:
|
runtime
|
The runtime providers.
TYPE:
|
fuel
|
The step budget.
TYPE:
|
seed
|
The reference generator's seed.
TYPE:
|
numbers
|
The number domain the reference machine computes in; the default floating domain when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FitKey
|
The key. |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the run has no seed, uses programmatic providers, names a datum or site the entry does not have, or passes a value with no portable contract. |
KeyError
|
If the module has no entry or computation of that name. |
ExecutionFailure
|
With code |
Source code in src/quivers/incremental/fits.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
run
¶
run(module: QiecModule, name: str, arguments: Sequence[HostValue] = (), *, data: Mapping[str, HostValue] | None = None, sites: Mapping[str, HostValue] | None = None, static_arguments: Sequence[str] = (), runtime: RuntimeConfiguration | None = None, fuel: int | None = None, seed: int | None = None, numbers: NumberDomain | None = None) -> CachedRun
Invoke an entry, reusing a stored run with the same key.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
name
|
The entry's name.
TYPE:
|
arguments
|
Positional value arguments.
TYPE:
|
data
|
A program's parameters by name.
TYPE:
|
sites
|
Conditioned sites by label.
TYPE:
|
static_arguments
|
TYPE:
|
runtime
|
The runtime providers.
TYPE:
|
fuel
|
The step budget.
TYPE:
|
seed
|
The reference generator's seed; required.
TYPE:
|
numbers
|
The number domain the reference machine computes in; the default floating domain when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CachedRun
|
The run's JSON payload, from the store on a hit. |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the run has no content identity. |
ExecutionFailure
|
If the run fails. |
StoreError
|
If the stored payload is corrupt. |
Source code in src/quivers/incremental/fits.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
FitCacheError
¶
Bases: ValueError
A fit or run has no content identity, so it cannot be cached.
FitCacheEvent
didactic-model
¶
FitCacheEvent(*, kind: FitKind, key: str, hit: bool)
Bases: Model
One lookup of a cache.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
A fit or a run.
TYPE:
|
key
|
The key's digest.
TYPE:
|
hit
|
Whether the stored artifact was returned.
TYPE:
|
FitKey
didactic-model
¶
FitKey(*, kind: FitKind, entry: str, companions: str, source: str, names: tuple[str, ...], data: tuple[KeyedDigest, ...], fixed_sites: tuple[KeyedDigest, ...], configuration: str, seeds: tuple[int, ...], engine: str)
Bases: Model
Everything that determines a fit or run, as digests.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
A fit or a run.
TYPE:
|
entry
|
The content hash of the entry point.
TYPE:
|
companions
|
The digest of the checked interpretation bindings the entry runs with, in the module's content context.
TYPE:
|
source
|
For a fit, the digest of the program source's modules
(
TYPE:
|
names
|
The entry's observable names, in ordinal order.
TYPE:
|
data
|
Each supplied parameter's position with the digest of its value.
TYPE:
|
fixed_sites
|
Each conditioned site's ordinal among
TYPE:
|
configuration
|
The digest of the inference method and the options of the fit or run.
TYPE:
|
seeds
|
The seeds.
TYPE:
|
engine
|
The digest of the engine identity.
TYPE:
|
digest
¶
The store key of the fit or run.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of every component. |
Source code in src/quivers/incremental/fits.py
KeyedDigest
didactic-model
¶
Bases: Model
The digest of one value at one position of a key.
| PARAMETER | DESCRIPTION |
|---|---|
position
|
A parameter position or a site ordinal.
TYPE:
|
digest
|
The value's digest.
TYPE:
|
IdentityError
¶
Bases: ValueError
A source cannot be identified: it does not parse or does not check.
ProgramIdentity
didactic-model
¶
ProgramIdentity(*, core: ModuleHashes, statements: tuple[StatementHash, ...], source: SourceHash, digest: str)
Bases: Model
Every identity of one checked source.
| PARAMETER | DESCRIPTION |
|---|---|
core
|
The core hashes of its checked declarations.
TYPE:
|
statements
|
The source hash of each top-level statement, in source order.
TYPE:
|
source
|
The hash of the exact bytes.
TYPE:
|
digest
|
The digest of the core module digest and the multiset of statement hashes under the grammar commit: what a fit of this program is keyed by.
TYPE:
|
SourceHash
didactic-model
¶
Bases: Model
The hash of a source's exact bytes.
| PARAMETER | DESCRIPTION |
|---|---|
grammar
|
The panproto schema commit of the grammar the source is written in.
TYPE:
|
digest
|
The BLAKE3 digest of the bytes.
TYPE:
|
StatementHash
didactic-model
¶
Bases: Model
The alpha-normalized source hash of one top-level statement.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
The statement's grammar kind (
TYPE:
|
names
|
The names it declares, in order (metadata).
TYPE:
|
hash
|
Its source hash: the component hash when no other statement refers
back to it, else
TYPE:
|
GateHop
didactic-model
¶
GateHop(*, source: str, target: str, feature: str = '', migrate: Callable[[bytes], bytes] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), semantic: str = '')
Bases: ValueModel
One migration step the gate checks.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The revision the step starts at.
TYPE:
|
target
|
The revision the hop under test ends at.
TYPE:
|
feature
|
The release-hop feature applied alone, or empty for a whole hop.
TYPE:
|
migrate
|
The rewrite from the hop's source revision all the way to
TYPE:
|
semantic
|
Why the step may change meaning, or empty for a syntactic step.
TYPE:
|
label
property
¶
The step's name in reports.
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
HopOutcome
didactic-model
¶
HopOutcome(*, hop: str, file: str, status: HopStatus, detail: str = '')
Bases: Model
The gate's finding for one step and one file.
| PARAMETER | DESCRIPTION |
|---|---|
hop
|
The step's label.
TYPE:
|
file
|
The file.
TYPE:
|
status
|
What was found.
TYPE:
|
detail
|
The reason for a rejection, the semantic declaration, or the core hashes that appeared and disappeared.
TYPE:
|
InvarianceReport
didactic-model
¶
InvarianceReport(*, files: tuple[str, ...] = (), unchecked: tuple[str, ...] = (), outcomes: tuple[HopOutcome, ...] = ())
Bases: Model
Everything the gate found.
| PARAMETER | DESCRIPTION |
|---|---|
files
|
The corpus files that check at
TYPE:
|
unchecked
|
The corpus files that do not check at
TYPE:
|
outcomes
|
One outcome per step and usable file.
TYPE:
|
failures
property
¶
failures: tuple[HopOutcome, ...]
The outcomes that fail the gate.
| RETURNS | DESCRIPTION |
|---|---|
tuple[HopOutcome, ...]
|
Every |
ok
property
¶
Whether every syntactic step preserved every core hash.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when no outcome is |
summary_lines
¶
A human-readable report.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
One line per step with its counts, then one per failure. |
Source code in src/quivers/incremental/migration_gate.py
ImportEdges
didactic-model
¶
ImportEdges(*, imports: tuple[ResolvedImport, ...] = ())
Bases: Model
The resolved imports of one module.
| PARAMETER | DESCRIPTION |
|---|---|
imports
|
Each import with the module it names.
TYPE:
|
ModuleBuild
¶
ModuleBuild(loader: ModuleLoader, *, store: ArtifactStore | None = None)
Incremental compilation of the module graphs a loader provides.
| PARAMETER | DESCRIPTION |
|---|---|
loader
|
Finds a module's source by its path.
TYPE:
|
store
|
Where elaborations persist across processes, or None to keep them in memory.
TYPE:
|
Source code in src/quivers/incremental/pipeline.py
load
¶
Set the source of a module and of everything it imports.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module's dotted path.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
If a module is not found or is provided by two roots. |
Source code in src/quivers/incremental/pipeline.py
reload
¶
Read a module's source again, as after an edit.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module's dotted path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether its source changed. |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
If the module is no longer found. |
Source code in src/quivers/incremental/pipeline.py
executed
¶
The keys a query ran for, in order.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
The query name.
TYPE:
|
since
|
Skip the first
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The keys of its |
Source code in src/quivers/incremental/pipeline.py
Specialization
didactic-model
¶
Specialization(*, computation: str, arguments: tuple[StaticArgument, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), type: ComputationType = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
A computation instantiated at closed static arguments.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The computation's name.
TYPE:
|
arguments
|
The checked static arguments, in telescope order.
TYPE:
|
type
|
The computation's type with its telescope instantiated.
TYPE:
|
Input
¶
Input(engine: QueryEngine, name: str, fingerprint: Callable[[V], str])
Bases: QueryTable
A table of values set from outside the engine.
| PARAMETER | DESCRIPTION |
|---|---|
engine
|
The owning engine.
TYPE:
|
name
|
The input's name.
TYPE:
|
fingerprint
|
The digest of a value; a value with the old digest is no change.
TYPE:
|
Source code in src/quivers/incremental/queries.py
set
¶
Set one key's value.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key.
TYPE:
|
value
|
The new value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether the value changed: a value with the old fingerprint starts no new revision and invalidates nothing. |
Source code in src/quivers/incremental/queries.py
keys
¶
Every key that has a value.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The keys, sorted. |
get
¶
Read one key, recording the read as a dependency.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
V
|
The value. |
| RAISES | DESCRIPTION |
|---|---|
QueryError
|
If the key has never been set. |
Source code in src/quivers/incremental/queries.py
refresh
¶
An input is always current.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[int, str]
|
The revision the value was set at and its fingerprint. |
| RAISES | DESCRIPTION |
|---|---|
QueryError
|
If the key has never been set. |
Source code in src/quivers/incremental/queries.py
Query
¶
Query(engine: QueryEngine, name: str, compute: Callable[[str], V], fingerprint: Callable[[V], str], codec: QueryCodec[V] | None)
Bases: QueryTable
A memoized function of a key.
| PARAMETER | DESCRIPTION |
|---|---|
engine
|
The owning engine.
TYPE:
|
name
|
The query's name.
TYPE:
|
compute
|
The function. It reads inputs and queries through their
TYPE:
|
fingerprint
|
The digest of a result. Two results with one fingerprint are interchangeable for every reader, so the fingerprint must cover everything a reader of the result can observe.
TYPE:
|
codec
|
How results persist in the engine's store, or None to keep them in memory only.
TYPE:
|
Source code in src/quivers/incremental/queries.py
get
¶
Answer the query, recording the read as a dependency.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
V
|
The current result. |
| RAISES | DESCRIPTION |
|---|---|
QueryError
|
If answering it needs its own answer, or reads an unset input. |
Source code in src/quivers/incremental/queries.py
fingerprint
¶
The fingerprint of the current result.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest, computing the result if needed (without recording a dependency). |
Source code in src/quivers/incremental/queries.py
refresh
¶
Bring one key up to date.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[int, str]
|
The revision its result last changed at and its fingerprint. |
Source code in src/quivers/incremental/queries.py
QueryCodec
¶
How a query's results are written to and read from the store.
| PARAMETER | DESCRIPTION |
|---|---|
encode
|
Serialize a result.
TYPE:
|
decode
|
Read a serialized result back.
TYPE:
|
version
|
The codec's format version. It is part of every stored record's address, so a change of format never reads an old record.
TYPE:
|
Source code in src/quivers/incremental/queries.py
QueryEngine
¶
QueryEngine(*, store: ArtifactStore | None = None, namespace: str = 'qvr')
The tables, revision, active frames, and log of one incremental build.
| PARAMETER | DESCRIPTION |
|---|---|
store
|
Where queries with a codec persist their results, or None to keep everything in memory.
TYPE:
|
namespace
|
Separates this engine's persisted records from those of engines built with other query definitions (another engine version, say).
TYPE:
|
Source code in src/quivers/incremental/queries.py
log
instance-attribute
¶
log: list[QueryEvent] = []
Every step the engine has taken, in order: each input set, each
query run, cut off, or reused, and each result loaded from the
store, with its key (see QueryEvent).
input
¶
input(name: str, fingerprint: Callable[[V], str]) -> Input[V]
Declare an input table.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Its name.
TYPE:
|
fingerprint
|
The digest of a value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Input[V]
|
The table. |
| RAISES | DESCRIPTION |
|---|---|
QueryError
|
If the name is taken. |
Source code in src/quivers/incremental/queries.py
query
¶
query(name: str, compute: Callable[[str], V], fingerprint: Callable[[V], str], *, codec: QueryCodec[V] | None = None) -> Query[V]
Declare a query.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Its name.
TYPE:
|
compute
|
The function of a key.
TYPE:
|
fingerprint
|
The digest of a result.
TYPE:
|
codec
|
How results persist, or None for memory only.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Query[V]
|
The query. |
| RAISES | DESCRIPTION |
|---|---|
QueryError
|
If the name is taken. |
Source code in src/quivers/incremental/queries.py
table
¶
table(name: str) -> QueryTable
A table by name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QueryTable
|
The table. |
| RAISES | DESCRIPTION |
|---|---|
QueryError
|
If there is no such table, which happens when a persisted record names a query this engine does not define. |
Source code in src/quivers/incremental/queries.py
advance
¶
record
¶
record(action: QueryAction, query: str, key: str) -> None
Append a step to the log.
| PARAMETER | DESCRIPTION |
|---|---|
action
|
What happened.
TYPE:
|
query
|
The table.
TYPE:
|
key
|
The key.
TYPE:
|
Source code in src/quivers/incremental/queries.py
read
¶
read(table: QueryTable, key: str) -> None
Record a read as a dependency of the running query, if any.
| PARAMETER | DESCRIPTION |
|---|---|
table
|
The table read.
TYPE:
|
key
|
The key read.
TYPE:
|
Source code in src/quivers/incremental/queries.py
run
¶
run(table: QueryTable, key: str, compute: Callable[[], V]) -> tuple[V, tuple[tuple[QueryTable, str], ...]]
Run a query body, collecting what it reads.
| PARAMETER | DESCRIPTION |
|---|---|
table
|
The query.
TYPE:
|
key
|
Its key.
TYPE:
|
compute
|
The body.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[V, tuple[tuple[QueryTable, str], ...]]
|
The result and its dependencies in reading order. |
| RAISES | DESCRIPTION |
|---|---|
QueryError
|
If the query is already running, which is a dependency cycle. |
Source code in src/quivers/incremental/queries.py
events
¶
events(action: QueryAction | None = None, *, since: int = 0) -> tuple[QueryEvent, ...]
The logged steps, optionally of one action and from one point.
| PARAMETER | DESCRIPTION |
|---|---|
action
|
Only steps of this action, or all when None.
TYPE:
|
since
|
Skip the first
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[QueryEvent, ...]
|
The steps in order. |
Source code in src/quivers/incremental/queries.py
QueryError
¶
Bases: RuntimeError
A query cannot be answered: an unset input or a dependency cycle.
QueryEvent
didactic-model
¶
QueryEvent(*, revision: int, action: QueryAction, query: str, key: str)
Bases: Model
One step of the engine.
| PARAMETER | DESCRIPTION |
|---|---|
revision
|
The engine revision the step happened at.
TYPE:
|
action
|
What the engine did.
TYPE:
|
query
|
The query or input name.
TYPE:
|
key
|
The key within it.
TYPE:
|
QueryTable
¶
QueryTable(engine: QueryEngine, name: str)
Bases: ABC
An input or query table of an engine.
| PARAMETER | DESCRIPTION |
|---|---|
engine
|
The owning engine.
TYPE:
|
name
|
The table's name, unique in the engine.
TYPE:
|
Source code in src/quivers/incremental/queries.py
refresh
abstractmethod
¶
Bring one key up to date.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[int, str]
|
The revision its value last changed at and its fingerprint. |
Source code in src/quivers/incremental/queries.py
ArtifactStore
¶
A content-addressed artifact store rooted at one directory.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The store directory. It is created on the first write.
TYPE:
|
Source code in src/quivers/incremental/store.py
max_bytes
property
¶
The store's byte limit.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The limit recorded in the store's configuration, or
|
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the configuration file is not a valid limit record. |
for_project
classmethod
¶
for_project(start: Path | None = None) -> ArtifactStore
The store of the project a path belongs to.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
A path inside the project; the working directory when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ArtifactStore
|
The store at |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If no project root is found and no override is set. |
Source code in src/quivers/incremental/store.py
set_max_bytes
¶
set_max_bytes(limit: int) -> tuple[StoreEntry, ...]
Set the store's byte limit and evict down to it.
| PARAMETER | DESCRIPTION |
|---|---|
limit
|
The new limit in bytes; must be positive.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[StoreEntry, ...]
|
The entries evicted to fit the new limit. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the limit is not positive. |
Source code in src/quivers/incremental/store.py
get
¶
Read an entry's payload and mark it used.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace.
TYPE:
|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bytes or None
|
The payload, or None when the store has no such entry. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the address is malformed, or the payload does not match the digest recorded with it. A corrupt entry is reported, never served and never silently replaced. |
Source code in src/quivers/incremental/store.py
payload_path
¶
The verified payload file of an entry, marked used.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace.
TYPE:
|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path or None
|
The payload file, for a reader that needs a path rather than bytes, or None when the store has no such entry. The file must be read, not modified. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the address is malformed or the payload does not match its recorded digest. |
Source code in src/quivers/incremental/store.py
staging_path
¶
A fresh file path inside the store for writing an artifact.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
A short name for the file, used as its prefix.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
A path in the store's staging directory that does not exist yet. Staging lives with the store, on the project's disk, so an artifact is never written to a temporary directory. |
Source code in src/quivers/incremental/store.py
put
¶
put(namespace: str, key: str, payload: bytes, *, label: str = '') -> StoreEntry
Write an entry, then evict down to the byte limit.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace.
TYPE:
|
key
|
The key.
TYPE:
|
payload
|
The artifact.
TYPE:
|
label
|
A description shown by
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StoreEntry
|
The written entry. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the address is malformed or the payload alone exceeds the store's limit. |
Source code in src/quivers/incremental/store.py
entries
¶
entries(namespace: str | None = None) -> tuple[StoreEntry, ...]
Every entry, most recently used first.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
Only this namespace, or every namespace when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[StoreEntry, ...]
|
The entries. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the namespace is malformed or an entry's metadata is corrupt. |
Source code in src/quivers/incremental/store.py
remove
¶
Delete one entry.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace.
TYPE:
|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether the entry existed. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the address is malformed. |
Source code in src/quivers/incremental/store.py
clear
¶
Delete every entry, or every entry of one namespace.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace to clear, or None for the whole store.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
How many entries were deleted. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the namespace is malformed. |
Source code in src/quivers/incremental/store.py
prune
¶
prune(*, max_bytes: int | None = None, older_than: float | None = None, keep: tuple[str, str] | None = None) -> tuple[StoreEntry, ...]
Evict entries by age and then by size.
| PARAMETER | DESCRIPTION |
|---|---|
max_bytes
|
Evict least recently used entries until the store holds at most this many bytes; the store's limit when None.
TYPE:
|
older_than
|
First evict every entry not used for this many seconds; nothing is evicted by age when None.
TYPE:
|
keep
|
The namespace and key of one entry never to evict, the one just written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[StoreEntry, ...]
|
The evicted entries. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If an entry's metadata is corrupt. |
Source code in src/quivers/incremental/store.py
usage
¶
usage() -> StoreUsage
How much the store holds.
| RETURNS | DESCRIPTION |
|---|---|
StoreUsage
|
Entry counts and byte totals, overall and per namespace. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If an entry's metadata is corrupt. |
Source code in src/quivers/incremental/store.py
StoreEntry
didactic-model
¶
StoreEntry(*, namespace: str, key: str, size: int, digest: str, created: float, accessed: float, label: str = '')
Bases: Model
One cached artifact.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The kind of artifact (
TYPE:
|
key
|
The digest of everything that determines the artifact.
TYPE:
|
size
|
The payload's size in bytes.
TYPE:
|
digest
|
The BLAKE3 digest of the payload, checked on every read.
TYPE:
|
created
|
When the entry was written, in seconds since the epoch.
TYPE:
|
accessed
|
When the entry was last written or read, in seconds since the epoch.
TYPE:
|
label
|
A human-readable description of what the entry holds.
TYPE:
|
StoreError
¶
Bases: RuntimeError
The store cannot honor a request: a bad key, a corrupt entry, a limit.
StoreUsage
didactic-model
¶
StoreUsage(*, root: str, entries: int, size: int, max_bytes: int, namespaces: tuple[NamespaceUsage, ...] = ())
Bases: Model
How much a store holds.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The store directory.
TYPE:
|
entries
|
The number of entries.
TYPE:
|
size
|
Their total payload size in bytes.
TYPE:
|
max_bytes
|
The store's byte limit.
TYPE:
|
namespaces
|
Each namespace's usage, sorted by name.
TYPE:
|
NamespaceUsage
didactic-model
¶
Bases: Model
How much one namespace of a store holds.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace.
TYPE:
|
entries
|
Its number of entries.
TYPE:
|
size
|
Their total payload size in bytes.
TYPE:
|
engine_identity
¶
The digest of the engine that computes cached artifacts.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of the quivers version, the kernel ABI, the content-hash format, the torch version, the Python implementation and version, and the operating system and machine. An artifact computed under any other engine is not reused, since checked modules and floating-point results may differ. |
Source code in src/quivers/incremental/engine.py
program_source_digest
¶
program_source_digest(source: ProgramSource) -> str
The digest that identifies a model's program source.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The root module and the modules it imports.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of each module's path with the alpha-normalized statement
digest of its text ( |
Source code in src/quivers/incremental/fits.py
value_digest
¶
value_digest(value: ExternalValue | InferenceMethod[ModelFit], factories: Mapping[str, ArtifactFactory] | None = None) -> str
The digest of one external value.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A datum, a site value, a configuration record, or an inference method: anything the fitted artifact format has a portable contract for.
TYPE:
|
factories
|
Explicit contracts for values the format does not know.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of the value's portable encoding. |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the value has no portable contract, so no stored fit could have been computed from it. |
Source code in src/quivers/incremental/fits.py
check_source
¶
check_source(source: bytes, *, module_name: str, file_path: str, roots: tuple[str | Path, ...] = ()) -> QiecModule
Interpret and check a source, with its imports, down to its QIEC module.
The source is the root of a module graph (quivers.dsl.modules): its
imports are found in the standard library and below roots, and the
flat program is what is checked and hashed.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The source.
TYPE:
|
module_name
|
The name stable identities derive from (metadata of every hash).
TYPE:
|
file_path
|
The path diagnostics name.
TYPE:
|
roots
|
Directories the source's imported module paths are relative to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecModule
|
The checked module. |
| RAISES | DESCRIPTION |
|---|---|
IdentityError
|
If the source does not parse, its module graph does not load or resolve, its QIEC lowering reports a diagnostic (located in the module it comes from), or a program was not elaborated. A module that failed to check has no meaning to hash, and a module missing a program would hash as if the program were absent. |
Source code in src/quivers/incremental/identity.py
head_grammar
¶
The panproto schema commit of the grammar this checkout parses.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The commit pinned for |
identify
¶
identify(source: str | bytes, *, module_name: str, file_path: str = '<source>', grammar: str | None = None, roots: tuple[str | Path, ...] = ()) -> ProgramIdentity
Every identity of one source file.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The source text.
TYPE:
|
module_name
|
The module name stable identities derive from.
TYPE:
|
file_path
|
The path diagnostics name.
TYPE:
|
grammar
|
The schema commit of the grammar the source is written in;
TYPE:
|
roots
|
Directories the source's imported module paths are relative to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ProgramIdentity
|
Its core hashes, statement source hashes, and source hash. |
| RAISES | DESCRIPTION |
|---|---|
IdentityError
|
If the source does not parse or check. |
Source code in src/quivers/incremental/identity.py
source_hash
¶
source_hash(source: bytes, *, grammar: str) -> SourceHash
The hash of a source's exact bytes.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The bytes.
TYPE:
|
grammar
|
The schema commit of the grammar they are written in.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SourceHash
|
The grammar commit with the BLAKE3 digest of the bytes. |
Source code in src/quivers/incremental/identity.py
statement_hashes
¶
statement_hashes(source: bytes, tree: _Tree, names: FileNames) -> tuple[StatementHash, ...]
The alpha-normalized source hash of every top-level statement.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The file's bytes.
TYPE:
|
tree
|
Its parse tree.
TYPE:
|
names
|
Its name analysis.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[StatementHash, ...]
|
One hash per statement, in source order. A statement's hash covers the hashes of the statements it refers to, so it changes when they do; statements that refer to one another are hashed as one component. |
| RAISES | DESCRIPTION |
|---|---|
IdentityError
|
If a reference cannot be resolved. |
Source code in src/quivers/incremental/identity.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
statements_digest
¶
statements_digest(source: str | bytes, *, file_path: str = '<source>', grammar: str | None = None) -> str
The digest of a source's statement hashes, without checking it.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The source text.
TYPE:
|
file_path
|
The path diagnostics name.
TYPE:
|
grammar
|
The schema commit of the grammar the source is written in;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of the grammar commit and the multiset of the statements' alpha-normalized source hashes: invariant under renaming, reordering, comments, and formatting, and changed by any other edit to any statement. |
| RAISES | DESCRIPTION |
|---|---|
IdentityError
|
If the source does not parse. |
Source code in src/quivers/incremental/identity.py
check_migration_invariance
¶
check_migration_invariance(files: Sequence[Path], *, hops: Sequence[GateHop] | None = None) -> InvarianceReport
Run the gate over corpus files.
| PARAMETER | DESCRIPTION |
|---|---|
files
|
The corpus files, written in the
TYPE:
|
hops
|
The steps to check;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
InvarianceReport
|
Every outcome; |
Source code in src/quivers/incremental/migration_gate.py
corpus_files
¶
Every .qvr file under some roots.
| PARAMETER | DESCRIPTION |
|---|---|
roots
|
Files and directories.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Path, ...]
|
The files, each directory's sorted. |
Source code in src/quivers/incremental/migration_gate.py
default_hops
¶
default_hops(*, chain: Sequence[str] = CHAIN, migrators: Mapping[tuple[str, str], Callable[[bytes], bytes]] = MIGRATORS, semantic: Mapping[tuple[str, str], str] = SEMANTIC_HOPS) -> tuple[GateHop, ...]
The steps the gate checks for a migration chain.
| PARAMETER | DESCRIPTION |
|---|---|
chain
|
The revisions, oldest first,
TYPE:
|
migrators
|
The hop of each adjacent pair.
TYPE:
|
semantic
|
The hops that declare they may change meaning.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[GateHop, ...]
|
One step per hop, migrating from the hop's source revision to
|
Source code in src/quivers/incremental/migration_gate.py
specialization_key
¶
The specialize key of a computation at static arguments.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The root module's path.
TYPE:
|
computation
|
The computation's name.
TYPE:
|
statics
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
A key that names the same specialization however the assignments are ordered. |
Source code in src/quivers/incremental/pipeline.py
bytes_fingerprint
¶
The fingerprint of a byte string.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The bytes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Their BLAKE3 digest. |
Source code in src/quivers/incremental/queries.py
default_cache_directory
¶
The cache directory of the project a path belongs to.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
A path inside the project; the working directory when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
|
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the variable is unset and no project root is found. |
Source code in src/quivers/incremental/store.py
find_project_root
¶
The root of the project a path belongs to.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
A file or directory inside the project.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
The nearest directory, from |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If no directory from |