Skip to content

Commit e415124

Browse files
committed
Rename MeasurableVariable to MeasurableOp
Also introduce MeasurableOpMixin for string representation
1 parent 2856062 commit e415124

File tree

6 files changed

+14
-19
lines changed

6 files changed

+14
-19
lines changed

pymc/logprob/basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,19 +485,19 @@ def conditional_logp(
485485

486486
# This is the updated random-to-value-vars map with the lifted/rewritten
487487
# variables. The rewrites are supposed to produce new
488-
# `MeasurableVariable`s that are amenable to `_logprob`.
488+
# `MeasurableOp`s whose variables are amenable to `_logprob`.
489489
updated_rv_values = rv_remapper.rv_values
490490

491491
# Some rewrites also transform the original value variables. This is the
492492
# updated map from the new value variables to the original ones, which
493493
# we want to use as the keys in the final dictionary output
494494
original_values = rv_remapper.original_values
495495

496-
# When a `_logprob` has been produced for a `MeasurableVariable` node, all
496+
# When a `_logprob` has been produced for a `MeasurableOp` node, all
497497
# other references to it need to be replaced with its value-variable all
498498
# throughout the `_logprob`-produced graphs. The following `dict`
499499
# cumulatively maintains remappings for all the variables/nodes that needed
500-
# to be recreated after replacing `MeasurableVariable`s with their
500+
# to be recreated after replacing `MeasurableOp` variables with their
501501
# value-variables. Since these replacements work in topological order, all
502502
# the necessary value-variable replacements should be present for each
503503
# node.

pymc/logprob/rewriting.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def apply(self, fgraph):
152152
rewriter_name = getattr(node_rewriter, "name", None) or getattr(
153153
node_rewriter, "__name__", ""
154154
)
155-
# If we converted to a MeasurableVariable we're done here!
155+
# If we converted to a MeasurableOp we're done here!
156156
if node not in fgraph.apply_nodes or isinstance(node.op, MeasurableOp):
157157
# go to next node
158158
break
@@ -364,11 +364,11 @@ def construct_ir_fgraph(
364364
365365
Our measurable IR takes the form of an PyTensor graph that is more-or-less
366366
equivalent to a given PyTensor graph (i.e. the keys of `rv_values`) but
367-
contains `Op`s that are subclasses of the `MeasurableVariable` type in
368-
place of ones that do not inherit from `MeasurableVariable` in the original
367+
contains `Op`s that are subclasses of the `MeasurableOp` type in
368+
place of ones that do not inherit from `MeasurableOp` in the original
369369
graph but are nevertheless measurable.
370370
371-
`MeasurableVariable`\s are mapped to log-probabilities, so this IR is how
371+
`MeasurableOp` variables are mapped to log-probabilities, so this IR is how
372372
non-trivial log-probabilities are constructed, especially when the
373373
"measurability" of a term depends on the measurability of its inputs
374374
(e.g. a mixture).
@@ -381,11 +381,6 @@ def construct_ir_fgraph(
381381
measurable IR includes manipulations that are not applicable to outside of
382382
the context of measurability/log-probabilities.
383383
384-
For instance, some `Op`s will be lifted through `MeasurableVariable`\s in
385-
this IR, and the resulting graphs will not be computationally sound,
386-
because they wouldn't produce independent samples when the original graph
387-
would. See https://github.com/aesara-devs/aeppl/pull/78.
388-
389384
Returns
390385
-------
391386
A `FunctionGraph` of the measurable IR, a copy of `rv_values` containing

pymc/logprob/scan.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ def remove(x, i):
269269
def get_random_outer_outputs(
270270
scan_args: ScanArgs,
271271
) -> list[tuple[int, TensorVariable, TensorVariable]]:
272-
"""Get the `MeasurableVariable` outputs of a `Scan` (well, its `ScanArgs`).
272+
"""Get the measurable outputs of a `Scan` (well, its `ScanArgs`).
273273
274274
Returns
275275
-------
276276
A tuple of tuples containing the index of each outer-output variable, the
277277
outer-output variable itself, and the inner-output variable that
278-
is an instance of `MeasurableVariable`.
278+
is an instance of `MeasurableOp` variable.
279279
"""
280280
rv_vars = []
281281
for n, oo_var in enumerate(
@@ -376,7 +376,7 @@ def find_measurable_scans(fgraph, node):
376376

377377
curr_scanargs = ScanArgs.from_node(node)
378378

379-
# Find the un-output `MeasurableVariable`s created in the inner-graph
379+
# Find the un-output `MeasurablOp` variables created in the inner-graph
380380
if not any(out in rv_map_feature.rv_values for out in node.outputs):
381381
# TODO: T
382382
# We need to remap user inputs that have been specified in terms of

pymc/logprob/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def populate_replacements(var):
132132

133133

134134
def rvs_in_graph(vars: Variable | Sequence[Variable]) -> set[Variable]:
135-
"""Assert that there are no `MeasurableVariable` nodes in a graph."""
135+
"""Assert that there are no `MeasurableOp` nodes in a graph."""
136136

137137
def expand(r):
138138
owner = r.owner
@@ -178,7 +178,7 @@ def check_potential_measurability(
178178
valued_rvs = set(valued_rvs)
179179

180180
def expand_fn(var):
181-
# expand_fn does not go beyond valued_rvs or any MeasurableVariable
181+
# expand_fn does not go beyond valued_rvs or any MeasurableOp variables
182182
if var.owner and not isinstance(var.owner.op, MeasurableOp) and var not in valued_rvs:
183183
return reversed(var.owner.inputs)
184184
else:

pymc/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ def seeded_numpy_distribution_builder(dist_name: str) -> Callable:
978978

979979

980980
def assert_no_rvs(vars: Sequence[Variable]) -> None:
981-
"""Assert that there are no `MeasurableVariable` nodes in a graph."""
981+
"""Assert that there are no `MeasurableOp` nodes in a graph."""
982982

983983
rvs = rvs_in_graph(vars)
984984
if rvs:

tests/logprob/test_transform_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def test_transformed_rv_and_value():
470470

471471
@pytest.mark.filterwarnings("error")
472472
def test_mixture_transform():
473-
"""Make sure that non-`RandomVariable` `MeasurableVariable`s can be transformed.
473+
"""Make sure that non-`RandomVariable` `MeasurableOp` variables can be transformed.
474474
475475
This test is specific to `MixtureRV`, which is derived from an `OpFromGraph`.
476476
"""

0 commit comments

Comments
 (0)