pg.hyper.dynamic_evaluate

Accessible via pg.hyper.dynamic_evaluate.

dynamic_evaluate(evaluate_fn, yield_value=None, exit_fn=None, per_thread=True)

Eagerly evaluate hyper primitives within current scope.

Example:

global_indices = [0]
def evaluate_fn(x: pg.hyper.HyperPrimitive):
  if isinstance(x, pg.hyper.OneOf):
    return x.candidates[global_indices[0]]
  raise NotImplementedError()

with pg.hyper.dynamic_evaluate(evaluate_fn):
  assert 0 = pg.oneof([0, 1, 2])

Please see pyglove.DynamicEvaluationContext.apply as an example for using this method.

Return type:

Iterator[Any]

Parameters:
  • evaluate_fn – A callable object that evaluates a hyper value such as oneof, manyof, floatv, and etc. into a concrete value.

  • yield_value – Value to yield return.

  • exit_fn – A callable object to be called when exiting the context scope.

  • per_thread – If True, the context manager will be applied to current thread only. Otherwise, it will be applied on current process.

Yields:

yield_value from the argument.