Dimensions (guardrail_calculus.dimensions)
Concrete temporal values and the symbolic conditional, built on the kernel's dimensional protocols.
dimensions
Concrete temporal/dimensional values and the symbolic conditional.
Time and duration dimensionality is separated from the rest of the public DSL
surface. This module builds on the import-safe guardrail_kernel package; it does
not import the public guardrail_calculus package itself.
NodeT
module-attribute
NodeT = TypeVar('NodeT')
UTime
module-attribute
UTime = TypeVar('UTime', bound=TimeLike)
TDuration
module-attribute
TDuration = TypeVar('TDuration', bound=DurationLike)
MinutesBound
module-attribute
MinutesBound = int | TypeForm[int]
MinutesT
module-attribute
MinutesT = TypeVar('MinutesT', bound=MinutesBound)
CondT
module-attribute
CondT = TypeVar('CondT', bound=BoolLike)
ThenT
module-attribute
ThenT = TypeVar('ThenT')
ElseT
module-attribute
ElseT = TypeVar('ElseT')
t
module-attribute
t = ClockLiteralFactory()
Duration
dataclass
Bases: _SymbolicEquality, DimensionIdentity[Literal['Duration']]
A span of minutes (the duration dimension).
Arithmetic operations on Duration produce DurationExpr or TimeExpr.
Attributes:
| Name | Type | Description |
|---|---|---|
minutes |
int
|
The raw integer minute span. |
Source code in src/guardrail_calculus/dimensions.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
minutes
instance-attribute
minutes
minutes_
class-attribute
instance-attribute
minutes_ = minutes_
hours
class-attribute
instance-attribute
hours = hours
hm
class-attribute
instance-attribute
hm = hm
label
property
label
ClockTimeHmConstructor
Bases: Protocol
Source code in src/guardrail_calculus/dimensions.py
142 143 | |
ClockTime
dataclass
Bases: _SymbolicEquality, DimensionIdentity[Literal['Instant']], Generic[MinutesT]
A concrete clock instant, stored as minutes-of-day (the time dimension).
The minute count is kept in the type parameter (ClockTime[Literal[545]])
so a literal departure time survives into the static witness.
Attributes:
| Name | Type | Description |
|---|---|---|
minutes |
MinutesT
|
The minutes of day. |
Source code in src/guardrail_calculus/dimensions.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
minutes
instance-attribute
minutes
hm
class-attribute
hm = hm
label
property
label
minutes_as_int
minutes_as_int()
Source code in src/guardrail_calculus/dimensions.py
166 167 168 | |
from_hhmm
classmethod
from_hhmm(param)
Source code in src/guardrail_calculus/dimensions.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
ClockLiteralFactory
A factory class allowing t[1730] syntax to build literal ClockTimes.
Source code in src/guardrail_calculus/dimensions.py
238 239 240 241 242 243 244 245 246 247 | |
TimePoint
dataclass
Bases: DimensionIdentity[Literal['Instant']], TimeComparableMixin
A symbolic time instant referenced by path, e.g. drew.departure.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
The path descriptor to the symbolic time instant. |
Source code in src/guardrail_calculus/dimensions.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
path
instance-attribute
path
label
property
label
BoundTimePoint
dataclass
Bases: DimensionIdentity[Literal['Instant']], TimeComparableMixin
Time observable of the current subject block.
Runtime binding rewrites _.departure inside field blake=subject(...) into blake.departure.
Example
blake = subject().given(_.departure == drew.departure - Duration.hours(1))
Attributes:
| Name | Type | Description |
|---|---|---|
observable |
str
|
The name of the field on the current subject. |
Source code in src/guardrail_calculus/dimensions.py
311 312 313 314 315 316 317 318 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 | |
observable
instance-attribute
observable
label
property
label
bind
bind(subject_name)
Source code in src/guardrail_calculus/dimensions.py
336 337 | |
SubjectRefProtocol
Bases: Protocol
Protocol for classes that act as references to a subject with a departure time.
Source code in src/guardrail_calculus/dimensions.py
359 360 361 362 363 | |
departure
property
departure
SubjectRef
dataclass
A reference to another subject in the puzzle.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
The path to the referenced subject. |
Source code in src/guardrail_calculus/dimensions.py
366 367 368 369 370 371 372 373 374 375 376 377 | |
path
instance-attribute
path
departure
property
departure
DurationExpr
dataclass
Bases: _ExprNode[NodeT], _ScalarMul, DimensionIdentity[Literal['Duration']], DurationComparableMixin
A composite duration expression (e.g. the result of time - time).
Attributes:
| Name | Type | Description |
|---|---|---|
node |
NodeT
|
The underlying provenance node. |
label |
str
|
The expression label. |
Source code in src/guardrail_calculus/dimensions.py
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 | |
node
instance-attribute
node
label
instance-attribute
label
TimeExpr
dataclass
Bases: _ExprNode[NodeT], DimensionIdentity[Literal['Instant']], TimeComparableMixin
A composite time expression (e.g. the result of time + duration).
Attributes:
| Name | Type | Description |
|---|---|---|
node |
NodeT
|
The underlying provenance node. |
label |
str
|
The expression label. |
Source code in src/guardrail_calculus/dimensions.py
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 | |
node
instance-attribute
node
label
instance-attribute
label
DimensionExpr
dataclass
Bases: _ExprNode[NodeT], _ScalarMul, DimensionIdentity[Any], _ComparableRuntime
A generic composite dimension expression (e.g. for user-defined dimensions).
Attributes:
| Name | Type | Description |
|---|---|---|
node |
NodeT
|
The underlying provenance node. |
label |
str
|
The expression label. |
unit |
str | None
|
Optional unit string. |
Source code in src/guardrail_calculus/dimensions.py
596 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 | |
node
instance-attribute
node
label
instance-attribute
label
unit
class-attribute
instance-attribute
unit = None
IfTime
dataclass
Bases: _IfNode[CondT, ThenT, ElseT], DimensionIdentity[Literal['Instant']]
Symbolic if/then/else conditional returning an instant.
Source code in src/guardrail_calculus/dimensions.py
654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
IfDuration
dataclass
Bases: _IfNode[CondT, ThenT, ElseT], DimensionIdentity[Literal['Duration']]
Symbolic if/then/else conditional returning a duration.
Source code in src/guardrail_calculus/dimensions.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
IfBool
dataclass
Bases: _IfNode[CondT, ThenT, ElseT]
Symbolic if/then/else conditional returning a boolean.
Source code in src/guardrail_calculus/dimensions.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
IfDimensionExpr
dataclass
Bases: _IfNode[CondT, ThenT, ElseT], DimensionIdentity[Any]
Symbolic if/then/else conditional returning a generic dimension expression.
Source code in src/guardrail_calculus/dimensions.py
702 703 704 705 706 707 708 709 710 711 712 713 | |
time_at
time_at(hour, minute=0)
Helper to construct a ClockTime instance at HH:MM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hour
|
int
|
The hour (0-23). |
required |
minute
|
int
|
The minute (0-59). |
0
|
Returns:
| Type | Description |
|---|---|
ClockTime[int]
|
The constructed ClockTime instance. |
Source code in src/guardrail_calculus/dimensions.py
225 226 227 228 229 230 231 232 233 234 235 | |
fmt_time
fmt_time(minutes)
Format minutes of day into HH:MM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minutes
|
int
|
The minutes. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted string. |
Source code in src/guardrail_calculus/dimensions.py
254 255 256 257 258 259 260 261 262 263 264 | |
add_duration_to_time_or_not_implemented
add_duration_to_time_or_not_implemented(
left, right, node_factory
)
Internal helper to dispatch time + duration operations, or return NotImplemented.
Source code in src/guardrail_calculus/dimensions.py
385 386 387 388 389 390 391 392 393 394 395 | |
duration_binary_or_not_implemented
duration_binary_or_not_implemented(
left, right, node_factory
)
Internal helper to dispatch duration operations, or return NotImplemented.
Source code in src/guardrail_calculus/dimensions.py
398 399 400 401 402 403 404 405 406 407 | |
z3_if
z3_if(
condition: CondT, then_: ThenT, else_: ElseT
) -> IfTime[CondT, ThenT, ElseT]
z3_if(
condition: CondT, then_: ThenT, else_: ElseT
) -> IfDuration[CondT, ThenT, ElseT]
z3_if(
condition: CondT, then_: ThenT, else_: ElseT
) -> IfBool[CondT, ThenT, ElseT]
z3_if(
condition: CondT, then_: ThenT, else_: ElseT
) -> IfDimensionExpr[CondT, ThenT, ElseT]
z3_if(condition, then_, else_)
Symbolic if/then/else.
Returns then_ when condition is true, else_ otherwise. Chooses among
IfTime, IfDuration,
IfBool, and IfDimensionExpr
by inspecting the types of then_ and else_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition
|
BoolLike
|
The symbolic boolean condition. |
required |
then_
|
object
|
The branch returned if the condition evaluates to true. |
required |
else_
|
object
|
The branch returned if the condition evaluates to false. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A symbolic branch wrapper. |
Source code in src/guardrail_calculus/dimensions.py
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 812 813 814 815 816 817 818 819 820 821 822 823 824 | |
bind_value
bind_value(value, *, subject_name)
Recursively bind subject-bound placeholders (_.name) in a value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
The value to bind. |
required |
subject_name
|
str
|
The name of the subject to bind to. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The bound object/expression. |
Source code in src/guardrail_calculus/dimensions.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 | |
bind_bool_expr
bind_bool_expr(expr, *, subject_name)
Bind subject-bound placeholders in a boolean expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
BoolExpr[NodeT]
|
The boolean expression. |
required |
subject_name
|
str
|
The subject name to bind to. |
required |
Returns:
| Type | Description |
|---|---|
BoolExpr[Any]
|
The bound expression. |
Source code in src/guardrail_calculus/dimensions.py
877 878 879 880 881 882 883 884 885 886 887 | |
bind_time_expr
bind_time_expr(expr, *, subject_name)
Bind subject-bound placeholders in a time expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
TimeExpr[NodeT]
|
The time expression. |
required |
subject_name
|
str
|
The subject name to bind to. |
required |
Returns:
| Type | Description |
|---|---|
TimeExpr[Any]
|
The bound expression. |
Source code in src/guardrail_calculus/dimensions.py
890 891 892 893 894 895 896 897 898 899 900 | |
bind_duration_expr
bind_duration_expr(expr, *, subject_name)
Bind subject-bound placeholders in a duration expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
DurationExpr[NodeT]
|
The duration expression. |
required |
subject_name
|
str
|
The subject name to bind to. |
required |
Returns:
| Type | Description |
|---|---|
DurationExpr[Any]
|
The bound expression. |
Source code in src/guardrail_calculus/dimensions.py
903 904 905 906 907 908 909 910 911 912 913 914 915 | |