Specs¶
specs
¶
op_system.specs.
Public façade for RHS specification models and normalization.
The implementation lives in op_system._normalize. This module re-exports
the public types and functions under the stable op_system.specs namespace
for backward compatibility.
Supported RHS kinds¶
1) kind: "expr" - explicit d(state)/dt equations per state variable. 2) kind: "transitions" - diagram-style per-capita hazard transitions.
See op_system._normalize for the full implementation.
ExprRhs(state_names, equations, aliases, param_names, all_symbols, meta, state_templates=(), shaped_params=(), time_varying_params=(), aliases_ir=dict(), equations_ir=(), aliases_ir_reduce=dict(), equations_ir_reduce=(), alias_templates=())
dataclass
¶
Bases: _RhsBase
Normalized RHS for kind="expr" specs (explicit d(state)/dt equations).
Produced by :func:normalize_expr_rhs. Use :data:NormalizedRhs as the
union type when you need to accept both kinds.
ExpressionString(source)
dataclass
¶
Validated expression wrapper with cached AST and symbol names.
as_ir()
¶
Return the typed IR representation for this expression.
Returns:
| Type | Description |
|---|---|
Expr
|
Parsed typed IR tree. |
Source code in src/op_system/_symbols.py
43 44 45 46 47 48 49 | |
as_lowered_ir()
¶
Return helper-lowered typed IR for this expression.
Returns:
| Type | Description |
|---|---|
Expr
|
Typed IR tree with helper calls lowered to |
Source code in src/op_system/_symbols.py
51 52 53 54 55 56 57 | |
PinnedToken(axis, coord)
dataclass
¶
Axis token pinned to a specific coordinate.
StateTemplate(base, axes, shape, expanded_names, coord_assignments, offset)
dataclass
¶
Structural record for a state template prior to scalar expansion.
A spec like state: ["S[age, vax]"] over axes age (size 4) and
vax (size 2) produces a single StateTemplate with base="S",
axes=("age", "vax"), shape=(4, 2), and expanded_names listing the
eight scalar state names in cartesian-product order (age outer,
vax inner — matching itertools.product and the order used to expand
the flat state vector).
Non-templated entries (e.g. a bare "D" in state) are also reported
as StateTemplate records with axes=(), shape=(), and a single
expanded_names = ("D",) so consumers can iterate templates uniformly.
Attributes:
| Name | Type | Description |
|---|---|---|
base |
str
|
Compartment name without selector brackets (e.g. |
axes |
tuple[str, ...]
|
Wildcard axes in declaration order. Empty for scalar templates. |
shape |
tuple[int, ...]
|
Per-axis sizes in |
expanded_names |
tuple[str, ...]
|
Flat scalar state names, in cartesian-product order
over |
coord_assignments |
tuple[Mapping[str, str], ...]
|
For each entry in |
offset |
int
|
Index of |
TransitionsRhs(state_names, equations, aliases, param_names, all_symbols, meta, state_templates=(), shaped_params=(), time_varying_params=(), aliases_ir=dict(), equations_ir=(), aliases_ir_reduce=dict(), equations_ir_reduce=(), alias_templates=(), reactions_ir=())
dataclass
¶
Bases: _RhsBase
Normalized RHS for kind="transitions" specs (per-capita hazard diagram).
Produced by :func:normalize_transitions_rhs. Use :data:NormalizedRhs
as the union type when you need to accept both kinds.
WildcardToken(axis)
dataclass
¶
Axis token that expands over all coordinates of that axis.
normalize_expr_rhs(spec)
¶
Normalize an expression-based RHS specification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Mapping[str, Any]
|
Raw RHS specification mapping. |
required |
Returns:
| Type | Description |
|---|---|
ExprRhs
|
Backend-facing normalized RHS representation. |
Raises:
| Type | Description |
|---|---|
InvalidRhsSpecError
|
If validation fails. |
Source code in src/op_system/_normalize.py
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 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 | |
normalize_rhs(spec)
¶
Normalize a RHS specification dict into a backend-facing representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Mapping[str, Any] | None
|
Raw RHS specification mapping. |
required |
Returns:
| Type | Description |
|---|---|
NormalizedRhs
|
Backend-facing normalized RHS representation. |
Raises:
| Type | Description |
|---|---|
InvalidRhsSpecError
|
If validation fails. |
UnsupportedFeatureError
|
If validation fails. |
Source code in src/op_system/_normalize.py
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 | |
normalize_transitions_rhs(spec)
¶
Normalize a transition-based RHS specification (diagram/hazard semantics).
Returns:
| Type | Description |
|---|---|
TransitionsRhs
|
Backend-facing normalized RHS representation for the transitions kind. |
Raises:
| Type | Description |
|---|---|
InvalidRhsSpecError
|
If validation fails. |
Source code in src/op_system/_normalize.py
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 | |