beanmachine.ppl.compiler.fix_requirements module

This module takes a Bean Machine Graph builder and makes a best effort attempt to transform the accumulated graph to meet the requirements of the BMG type system. All possible transformations are made; if there are nodes that cannot be represented in BMG or cannot be made to meet type requirements, an error report is returned.

class beanmachine.ppl.compiler.fix_requirements.RequirementsFixer(bmg: beanmachine.ppl.compiler.bm_graph_builder.BMGraphBuilder, typer: beanmachine.ppl.compiler.lattice_typer.LatticeTyper)

Bases: object

This class takes a Bean Machine Graph builder and attempts to fix violations of BMG type system requirements.

The basic idea is that every edge in the graph has a requirement, such as “the type of the input must be Probability”. We do a traversal of the input edges of every node in the graph; if the input node meets the requirement, it is unchanged. If it does not, then a new node that has the same semantics that meets the requirement is returned. If there is no such node then an error is added to the error report.

bmg: beanmachine.ppl.compiler.bm_graph_builder.BMGraphBuilder
errors: beanmachine.ppl.compiler.error_report.ErrorReport
fix_problems() bool
meet_requirement(node: beanmachine.ppl.compiler.bmg_nodes.BMGNode, requirement: Union[beanmachine.ppl.compiler.bmg_types.BMGLatticeType, beanmachine.ppl.compiler.bmg_types.BaseRequirement], consumer: beanmachine.ppl.compiler.bmg_nodes.BMGNode, edge: str) beanmachine.ppl.compiler.bmg_nodes.BMGNode

The consumer node consumes the value of the input node. The consumer’s requirement is given; the name of this edge is provided for error reporting.

beanmachine.ppl.compiler.fix_requirements.requirements_fixer(bmg: beanmachine.ppl.compiler.bm_graph_builder.BMGraphBuilder)