Skip to content

Commit

Permalink
Introducing pg.Inferential: a new interface for symbolic value infe…
Browse files Browse the repository at this point in the history
…rence.

This CL introduces interface `pg.Inferentiable` for representing symbolic nodes that could be inferred dynamically upon read. Based this new design, we were able to get rid of `pg.ContextualValue` and its leaky implementation (e.g. `sym_contextual_getattr`). As a result, we replaced `sym_value` with `sym_inferred`, and removed `sym_contextual_getattr/hasattr`, together with `pg.ContextualValue` and `pg.symbolic.GetAttributeContext`.

PiperOrigin-RevId: 552091721
  • Loading branch information
daiyip authored and pyglove authors committed Jul 29, 2023
1 parent 531ce8e commit 5ef667c
Show file tree
Hide file tree
Showing 15 changed files with 447 additions and 660 deletions.
12 changes: 3 additions & 9 deletions pyglove/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,9 @@
Insertion = symbolic.Insertion
WritePermissionError = symbolic.WritePermissionError

# Contextual value marker.
ContextualValue = symbolic.ContextualValue
ContextualGetter = symbolic.ContextualGetter

# Decorator for making contextual getters.
contextual_getter = symbolic.contextual_getter

# Context object for computing contextual attribute.
GetAttributeContext = symbolic.GetAttributeContext
# Inferentiable classes.
Inferentiable = symbolic.Inferential
InferredValue = symbolic.InferredValue

#
# Symbols from 'typing.py'
Expand Down
10 changes: 4 additions & 6 deletions pyglove/core/symbolic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@
from pyglove.core.symbolic.flags import auto_call_functors
from pyglove.core.symbolic.flags import should_call_functors_during_init

# Marker for contextual values.
from pyglove.core.symbolic.base import ContextualValue
from pyglove.core.symbolic.contextual import ContextualGetter
from pyglove.core.symbolic.contextual import contextual_getter
# Inferential values
from pyglove.core.symbolic.base import Inferential

# GetAttribute context for computing contextual values.
from pyglove.core.symbolic.base import GetAttributeContext
from pyglove.core.symbolic.inferred import InferredValue
from pyglove.core.symbolic.inferred import ValueFromParentChain

# Symbolic types and their definition helpers.
from pyglove.core.symbolic.base import Symbolic
Expand Down
Loading

0 comments on commit 5ef667c

Please sign in to comment.