pg.PureSymbolic

Accessible via pg.PureSymbolic, pg.symbolic.PureSymbolic.

class PureSymbolic[source]

Bases: pg.CustomTyping

Base class to classes whose objects are considered pure symbolic.

Pure symbolic objects can be used for representing abstract concepts - for example, a search space of objects - which cannot be executed but soely representational.

Having pure symbolic object is a key differentiator of symbolic OOP from regular OOP, which can be used to placehold values in an object as a high-level expression of ideas. Later, with symbolic manipulation, the pure symbolic objects are replaced with material values so the object can be evaluated. This effectively decouples the expression of ideas from the implementation of ideas. For example: pg.oneof(['a', 'b', 'c'] will be manipulated into ‘a’, ‘b’ or ‘c’ based on the decision of a search algorithm, letting the program evolve itself.

Methods:

custom_apply(path, value_spec, allow_partial)

Custom apply on a value based on its original value spec.

custom_apply(path, value_spec, allow_partial, child_transform=None)[source]

Custom apply on a value based on its original value spec.

This implements pg.pg_typing.CustomTyping, allowing a pure symbolic value to be assigned to any field. To customize this behavior, override this method in subclasses.

Return type:

Tuple[bool, Any]

Parameters:
  • path – KeyPath of current object under its object tree.

  • value_spec – Original value spec for this field.

  • allow_partial – Whether allow partial object to be created.

  • child_transform – Function to transform child node values into their final values. Transform function is called on leaf nodes first, then on their parents, recursively.

Returns:

A tuple (proceed_with_standard_apply, value_to_proceed).

If proceed_with_standard_apply is set to False, value_to_proceed will be used as final value.

Raises:

Error when the value is not compatible with the value spec.