optflow package#

Subpackages#

Submodules#

optflow.analyzer module#

optflow.analyzer.analyse_expr_rec(expr, stat, parent_node=None, g=None, label=None)#
optflow.analyzer.analyze_expr(expr, visualization=False, filename=None, view=False, return_graph=False, g: Digraph | None = None, root_color: str | None = None)#
optflow.analyzer.visualize_problem(prob)#

optflow.constants module#

optflow.executor module#

optflow.executor.compile_expr(expr, input_nodes: list | None = None, mdp=False, action_batch=0, print_ir=False)#
optflow.executor.compile_expr_rec(expr, input_nodes: list, args, module, builder: IRBuilder, temp_nodes: dict)#
optflow.executor.compute_expr(expr, node_value: dict | None = None, temp_value: dict | None = None)#
optflow.executor.compute_expr_kernel(expr, node_value: dict | None = None, temp_value: dict | None = None)#
optflow.executor.ir_to_ctype(r: Type)#
optflow.executor.params_to_ctype(params: list)#

optflow.mdp module#

class optflow.mdp.ActionSlice(action)#

Bases: object

class optflow.mdp.DataGenerator#

Bases: object

class optflow.mdp.Env(mdp_elements: dict, inputs: dict | None = None, inputs_generator: DataGenerator | None = None, enable_jit=False, include_inputs_in_states=False)#

Bases: object

get_action_mask(agent_id: int | None = None)#
preprocess_state(state_value, agent_id: int | None = None)#
reset()#
step(a)#
optflow.mdp.analyze_mdp(prob: Problem)#

optflow.operators module#

class optflow.operators.BaseNode(name=None)#

Bases: object

class optflow.operators.Constant(value, dtype=None, shape=None, size=None, name=None)#

Bases: BaseNode

class optflow.operators.ConstantSlice(parent, indices)#

Bases: Constant

property name#
property shape#
property value#
class optflow.operators.CustomOperator(num_return_value=1, name=None)#

Bases: BaseNode

abstract run(*args)#
class optflow.operators.ForLoop(T=None)#

Bases: object

class optflow.operators.Graph(num_nodes, adjacent_matrix, node_attributes=None, name=None)#

Bases: NodeBundle

bundle()#
distance(i, j)#
class optflow.operators.GraphAgent(graph: Graph, location, attributes: dict | None = None, name=None)#

Bases: NodeBundle

bundle()#
property location#
moveto(new_loc)#
class optflow.operators.IfCond(condition)#

Bases: object

class optflow.operators.Input(dtype, shape=None, size=None, name=None)#

Bases: BaseNode

class optflow.operators.InputSlice(parent, indices)#

Bases: Input

property name#
property value#
class optflow.operators.NodeBundle(name=None)#

Bases: BaseNode

abstract bundle()#
class optflow.operators.Operation(op, operands, dtype=None, name=None)#

Bases: BaseNode

class optflow.operators.Set(size: int, value=None, name=None)#

Bases: Constant

property value#
class optflow.operators.Variable(cat, size=None, shape=None, name=None, elements=None)#

Bases: BaseNode

class optflow.operators.VariableSlice(parent, indices)#

Bases: Variable

property cat#
property name#
property optimized_value#
property shape#
property size#
optflow.operators.abs(a)#
optflow.operators.add(a, b)#
optflow.operators.break_loop()#
optflow.operators.cond(c, a, b)#
optflow.operators.debug_print(a)#
optflow.operators.eq(a, b)#
optflow.operators.for_loop(old_nodes: list, new_nodes: list, T, break_cond, loop_var)#
optflow.operators.geq(a, b)#
optflow.operators.graph_agent_location(graph_agent)#
optflow.operators.graph_agent_move_to(graph_agent, new_loc)#
optflow.operators.graph_distance(g, i, j)#
optflow.operators.gt(a, b)#
optflow.operators.identity(a)#
optflow.operators.leq(a, b)#
optflow.operators.logical_and(a, b)#
optflow.operators.logical_not(a)#
optflow.operators.logical_or(a, b)#
optflow.operators.lt(a, b)#
optflow.operators.maximum(a, b)#
optflow.operators.minimum(a, b)#
optflow.operators.mul(a, b)#
optflow.operators.ne(a, b)#
optflow.operators.neg(a)#
optflow.operators.rand()#
optflow.operators.reduce_sum(a)#
optflow.operators.set_add(s, a)#
optflow.operators.set_eq(a, b)#
optflow.operators.set_in(s, a)#
optflow.operators.set_not_in(s, a)#
optflow.operators.sub(a, b)#
optflow.operators.sum(a)#
optflow.operators.unpack(a, i)#
optflow.operators.watch_variable_name()#

optflow.problem module#

class optflow.problem.Problem(objective=None, constraints=None, sense=None)#

Bases: object

The class in OptFlow to represent an optimization problem.

Parameters:
  • objective – a Node representing the objective of the problem (to be maximized or minimized)

  • constraints – a list of boolean Node

  • senseflow.maximize or flow.minimize

load_model(save_path)#

Load a model trained by OptFlow

Parameters:

save_path – the directory of OptFlow model

Returns:

solve(solver=None, inputs: dict | None = None, init_state_inputs: dict | None = None, params: dict | None = None)#

Solve a problem

Parameters:
  • solverflow.programming, flow.metaheuristics, flow.search, flow.dp, flow.rl

  • inputs – a dict with node-value pairs

  • init_state_inputs – a dict with node-value pairs, only when flow.dp is set as the solver

  • params – a dict specifying the parameters for solving

Returns:

the optimized objective (variable solutions can be accessed by optflow.operators.Variable.optimized_value

train(trainer=None, inputs: dict | None = None, inputs_generator=None, params: dict | None = None)#

Train a model to solve the problem

Parameters:
  • traineroptflow.rl (reinforcement learning) or optflow.dp (dynamic programming)

  • inputs – a dict with node-value pairs

  • inputs_generator – a optflow.mdp.DataGenerator instance

  • params – a dict specifying the parameters for training

Returns:

visualize()#

Show the dataflow graph of the problem.

Returns:

optflow.problem.solve(objective=None, sense=None, solver=None, constraints=None, inputs=None, params=None)#

A shortcut of:

prob = Problem(objective=objective, constraints=constraints, sense=sense)
prob.solve(solver, inputs=inputs, params=params)
Parameters:
  • objective

  • sense

  • solver

  • constraints

  • inputs

  • params – the optimized objective

Returns:

Module contents#