Entry points¶
An entry point is a named computation or program that a checked module exposes
(list entry points), with a
description of its inputs.
entry_points lists them, and invoke_entry runs one in the same way for the command line, the
REPL, and Python. Posterior inference also needs an algorithm and its settings, which the caller
chooses.
entries
¶
Entry points of a checked module and one way to invoke them.
A checked module has two kinds of executable entry point: a named
computation declared with define, run by
run_named under a runtime
configuration, and a program, elaborated to a computation over the
module's canonical random and score instances and run by
sample_program with its
data and any conditioned sites. The command line, the REPL, and a Python
caller invoke either through invoke_entry,
so an entry validates its arguments, selects its providers, traces, and
fails with the same codes however it is reached.
EntryKind
¶
How an entry point is declared: with define or with program.
HostValue
¶
HostValue = bool | int | float | str | Tensor | RuntimeConstructor | tuple['HostValue', ...] | Mapping[str, 'HostValue']
A value the reference machine takes or returns: a scalar, a tensor, a family value, or a tuple or record of such values.
A family value (RuntimeConstructor) is the result of evaluating a
constructor. Functions such as deduction_item also build these values
for callers to pass to a computation that takes the family.
EntryParameter
didactic-model
¶
Bases: Model
One value parameter of an entry point.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The parameter's name.
TYPE:
|
type
|
Its type, rendered in the surface spelling.
TYPE:
|
role
|
How a program parameter is supplied (its data, an observation, a
index map, a scalar, or the program's domain);
TYPE:
|
EntryPoint
didactic-model
¶
EntryPoint(*, name: str, kind: EntryKind, parameters: tuple[EntryParameter, ...], statics: tuple[str, ...], effects: tuple[str, ...], result: str, sites: tuple[str, ...])
Bases: Model
An executable entry point of a checked module.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The entry's source name.
TYPE:
|
kind
|
Whether it is a
TYPE:
|
parameters
|
Its value parameters, in order.
TYPE:
|
statics
|
The names of the static binders its telescope takes, in order.
TYPE:
|
effects
|
The effect instances its body performs, rendered as
TYPE:
|
result
|
Its result type, rendered.
TYPE:
|
sites
|
The labels of a program's sample sites, which a run may condition on; empty for a computation.
TYPE:
|
EntryRun
didactic-model
¶
EntryRun(*, entry: EntryPoint = field(opaque=True, extras=OPAQUE_BY_VALUE), value: HeldValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY), log_joint: Tensor | None = field(opaque=True, extras=OPAQUE_BY_IDENTITY), result: ExecutionResult = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
What invoking an entry point produced.
| PARAMETER | DESCRIPTION |
|---|---|
entry
|
The entry invoked.
TYPE:
|
value
|
The value the entry returned. Numeric values are tensors and retain their autograd graphs.
TYPE:
|
log_joint
|
The log joint density a program run accumulated, as a scalar tensor
with its autograd graph, or
TYPE:
|
result
|
The underlying execution result, with its trace.
TYPE:
|
to_data
¶
Render the run as JSON-compatible data.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
The execution result's data, with the entry's kind and, for a program, the log joint. |
Source code in src/quivers/qiec/entries.py
entry_points
¶
entry_points(module: QiecModule) -> tuple[EntryPoint, ...]
Every executable entry point of a module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[EntryPoint, ...]
|
The programs and the computations, in declaration order; a computation a program elaborated to appears once, as the program, and a marginalization helper not at all. |
Source code in src/quivers/qiec/entries.py
entry_point
¶
entry_point(module: QiecModule, name: str) -> EntryPoint
One entry point of a module, by name.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
name
|
The entry's source name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EntryPoint
|
The entry. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/qiec/entries.py
invoke_entry
¶
invoke_entry(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, observer: TraceObserver | None = None, numbers: NumberDomain | None = None) -> EntryRun
Invoke an entry point.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
name
|
The entry's source name.
TYPE:
|
arguments
|
Host values for the entry's value parameters, in order. A
program's parameters may instead, or additionally, be given by
name through
TYPE:
|
data
|
A program's parameters by name: its data, observations, index maps, and scalars. A name given both positionally and here is an error.
TYPE:
|
sites
|
The values a program run conditions its sample sites on, by label; every other site is drawn. Not accepted for a computation.
TYPE:
|
static_arguments
|
Closed terms instantiating a computation's telescope, as
TYPE:
|
runtime
|
The providers a computation runs under; the core provider alone by default. A program's handlers are fixed by the run, so only the default configuration is accepted for a program.
TYPE:
|
fuel
|
A step budget for the run.
TYPE:
|
seed
|
A seed for the reference generator every draw of the run uses;
two runs seeded alike draw alike.
TYPE:
|
observer
|
A callback receiving every trace event as it is emitted.
TYPE:
|
numbers
|
The number domain of a computation's run:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EntryRun
|
The value, the log joint for a program, and the execution result. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/qiec/entries.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 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 499 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 | |
aligned_arguments
¶
aligned_arguments(module: QiecModule, name: str, arguments: Sequence[HostValue]) -> tuple[HostValue, ...]
A computation's arguments, labeled data aligned to its parameter types.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
name
|
The computation's name.
TYPE:
|
arguments
|
Its arguments, in order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[HostValue, ...]
|
Each argument for a tensor with named axes, given as labeled data, aligned to the canonical order its type fixes; others unchanged. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/qiec/entries.py
aligned_data
¶
aligned_data(module: QiecModule, name: str, data: Mapping[str, HostValue]) -> dict[str, HostValue]
A program's data by parameter, labeled data aligned to its types.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
name
|
The program's name.
TYPE:
|
data
|
Its parameters' values by name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, HostValue]
|
Each value for a tensor with named axes, given as labeled data, aligned to the canonical order its type fixes; others unchanged. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/qiec/entries.py
parse_bindings
¶
parse_bindings(items: Sequence[str]) -> dict[str, HostValue]
Read NAME=JSON bindings, as the command line and REPL take them.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
The bindings as typed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, HostValue]
|
Name to the parsed value, lists read as tuples. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an item has no |
Source code in src/quivers/qiec/entries.py
json_value
¶
Read a parsed JSON value as a host value.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The parsed JSON.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HostValue
|
The value with every list read as a tuple, which is how the runtime carries a tensor. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the value is |
Source code in src/quivers/qiec/entries.py
render_entry
¶
render_entry(entry: EntryPoint) -> str
Render an entry point as one signature line.
| PARAMETER | DESCRIPTION |
|---|---|
entry
|
The entry.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|