lava.lib.optimization.solvers.generic

lava.lib.optimization.solvers.generic.builder

Inheritance diagram of lava.lib.optimization.solvers.generic.builder
class lava.lib.optimization.solvers.generic.builder.SolverProcessBuilder

Bases: object

Builder to dynamically create the process and model for the solver of an optimization problem.

create_solver_model(target_cost, requirements, protocol)

Create and set the model class for the solver process in the building pipeline.

Parameters
  • target_cost (int) – A cost value provided by the user as a target for the solution to be found by the solver, when a solution with such cost is found and read, execution ends.

  • requirements (ty.List[AbstractComputeResource]) – Specifies which resources the ProcessModel requires.

  • protocol (AbstractSyncProtocol) – The SyncProtocol that the ProcessModel implements.

create_solver_process(problem, hyperparameters)

Create and set a solver process for the specified optimization problem.

Parameters
  • problem (OptimizationProblem) – Optimization problem defined by cost and constraints which will be used to ensemble the necessary variables and ports with their shape and initial values deriving from the problem specification.

  • hyperparameters (dict) – A dictionary specifying values for steps_to_fire, noise_amplitude, step_size and init_value. All but the last are integers, the initial value is an array-like of initial values for the variables defining the problem.

property solver_model: AbstractProcessModel

Returns the solver process model if already created.

Return type

AbstractProcessModel

property solver_process: AbstractProcess

Returns the solver process if already created.

Return type

AbstractProcess

static update_parent_process(data_class, parent)
verify_model_exists()

Assert the solver process model has already been created.

verify_process_exists()

Assert the solver process has already been created.

lava.lib.optimization.solvers.generic.dataclasses

Inheritance diagram of lava.lib.optimization.solvers.generic.dataclasses
class lava.lib.optimization.solvers.generic.dataclasses.ConstraintEnforcing(continuous, discrete, mixed)

Bases: object

Processes implementing an optimization problem’s constraints and their enforcing.

continuous: ContinuousConstraintsProcess
discrete: DiscreteConstraintsProcess
mixed: MixedConstraintsProcess
class lava.lib.optimization.solvers.generic.dataclasses.CostMinimizer(coefficients_2nd_order)

Bases: object

Processes implementing an optimization problem’s cost function.

coefficients_2nd_order: Dense
property gradient_out

Port sending gradient descent components to the dynamical systems.

property state_in

Port receiving input from dynamical systems representing variables.

class lava.lib.optimization.solvers.generic.dataclasses.MacroStateReader(read_gate, solution_readout, cost_convergence_check=None, sat_convergence_check=None)

Bases: object

Processes for checking convergence and reading network state encoding the solution .

cost_convergence_check: CostConvergenceChecker = None
property cost_in
property min_cost
read_gate: ReadGate
property read_gate_ack
property read_gate_cost_out
property read_gate_in_port
property read_gate_req_stop
property read_gate_solution_out
property ref_port
sat_convergence_check: SatConvergenceChecker = None
property satisfaction
property solution
solution_readout: SolutionReadout
property solution_readout_ack
property solution_readout_cost_in
property solution_readout_req_stop_in
property solution_readout_solution_in
property solution_step
property update_buffer
class lava.lib.optimization.solvers.generic.dataclasses.ProximalGradientMinimizer(augmented_terms)

Bases: object

augmented_terms: AugmentedTermsProcess
class lava.lib.optimization.solvers.generic.dataclasses.VariablesImplementation(continuous=None, discrete=None)

Bases: object

Processes implementing the variables of an optimization problem.

continuous: ContinuousVariablesProcess = None
discrete: DiscreteVariablesProcess = None
property gradient_in
property importances
property local_cost
property state_out
property variables_assignment

lava.lib.optimization.solvers.generic.hierarchical_processes

Inheritance diagram of lava.lib.optimization.solvers.generic.hierarchical_processes
class lava.lib.optimization.solvers.generic.hierarchical_processes.AugmentedTermsProcess(*args, **kwargs)

Bases: AbstractProcess

Process implementing cost coefficients as synapses.

class lava.lib.optimization.solvers.generic.hierarchical_processes.ContinuousConstraintsProcess(*args, **kwargs)

Bases: AbstractProcess

Process implementing continuous constraints via neurons and synapses.

class lava.lib.optimization.solvers.generic.hierarchical_processes.ContinuousVariablesProcess(*args, **kwargs)

Bases: AbstractProcess

Process which implementation holds the evolution of continuous variables on the solver of an optimization problem.

class lava.lib.optimization.solvers.generic.hierarchical_processes.CostConvergenceChecker(shape, name=None, log_config=None)

Bases: AbstractProcess

Process that continuously monitors cost convergence.

cost_components

Additive contributions to the total cost.

Type

InPort

update_buffer

Notifies the next process about the detection of a better cost.

Type

OutPort

min_cost

Current minimum cost, i.e., the lowest reported cost so far.

Type

Var

class lava.lib.optimization.solvers.generic.hierarchical_processes.DiscreteConstraintsProcess(*args, **kwargs)

Bases: AbstractProcess

Process implementing discrete constraints via synapses.

class lava.lib.optimization.solvers.generic.hierarchical_processes.DiscreteVariablesProcess(shape, cost_diagonal=None, hyperparameters=None, name=None, log_config=None)

Bases: AbstractProcess

Process which implementation holds the evolution of discrete variables on the solver of an optimization problem.

a_in

The addition of all inputs (per dynamical system) at this timestep will be received by this port.

Type

InPort

s_out

The payload to be exchanged between the underlying dynamical systems when these fire.

Type

OutPort

local_cost

The cost components per dynamical system underlying these variables, i.e., c_i = sum_j{Q_{ij} cdot x_i} will be sent through this port. The cost integrator will then complete the cost computation by adding all contributions, i.e., x^T cdot Q cdot x = sum_i{c_i}.

Type

OutPort

variable_assignment

Holds the current value assigned to the variables by the solver network.

Type

Var

class lava.lib.optimization.solvers.generic.hierarchical_processes.MixedConstraintsProcess(*args, **kwargs)

Bases: AbstractProcess

Process implementing continuous constraints via neurons and synapses.

class lava.lib.optimization.solvers.generic.hierarchical_processes.SatConvergenceChecker(*args, **kwargs)

Bases: AbstractProcess

Process that continuously monitors satisfiability convergence.

class lava.lib.optimization.solvers.generic.hierarchical_processes.StochasticIntegrateAndFire(*, step_size, shape=(1,), init_state=0, noise_amplitude=1, noise_precision=8, input_duration=6, min_state=1000, min_integration=-1000, steps_to_fire=10, refractory_period=1, cost_diagonal=0, name=None, log_config=None, init_value=0)

Bases: AbstractProcess

Event-driven stochastic discrete dynamical system with two outputs.

The main output is intended as input to other dynamical systems on the network, whilst the second output is to transfer local information to be integrated by an auxiliary dynamical system or circuit.

added_input

The addition of all inputs (per dynamical system) at this timestep will be received by this port.

Type

InPort

replace_assignment

Todo: deprecate

Type

InPort

messages

The payload to be sent to other dynamical systems when firing.

Type

OutPort

local_cost

the cost component corresponding to this dynamical system, i.e., c_i = sum_j{Q_{ij} cdot x_i} will be sent through this port. The cost integrator will then complete the cost computation by adding all contributions, i.e., x^T cdot Q cdot x = sum_i{c_i}.

Type

OutPort

lava.lib.optimization.solvers.generic.processes

lava.lib.optimization.solvers.generic.solver

Inheritance diagram of lava.lib.optimization.solvers.generic.solver
class lava.lib.optimization.solvers.generic.solver.OptimizationSolver(problem, run_cfg=None)

Bases: object

Generic solver for constrained optimization problems defined by variables, cost and constraints.

The problem should behave according to the OptimizationProblem’s interface so that the Lava solver can be built correctly.

A Lava OptimizationSolverProcess and a Lava OptimizationSolverModel will be created from the problem specification. The dynamics of such process implements the algorithms that search a solution to the problem and reports it to the user.

property hyperparameters
property last_run_report
measure_energy_to_solution(timeout, target_cost, backend, hyperparameters=None)

Run solver until target_cost or timeout and returns energy to solution.

Parameters
  • timeout (int) – Maximum number of iterations (timesteps) to be run. If set to -1 then the solver will run continuously in non-blocking mode until a solution is found.

  • target_cost (int, optional) – A cost value provided by the user as a target for the solution to be found by the solver, when a solution with such cost is found and read, execution ends.

  • backend (BACKENDS) – At the moment, only the Loihi2 backend can be used.

  • hyperparameters (ty.Dict[str, ty.Union[int, npt.ArrayLike]], optional) – A dictionary specifying values for steps_to_fire, noise_amplitude, step_size and init_value. All but the last are integers, the initial value is an array-like of initial values for the variables defining the problem.

Returns

energy_to_solution – Total energy to solution in Joule.

Return type

npt.ArrayLike

measure_time_to_solution(timeout, target_cost, backend, hyperparameters=None)

Run solver until target_cost or timeout and returns total time to solution.

Parameters
  • timeout (int) – Maximum number of iterations (timesteps) to be run. If set to -1 then the solver will run continuously in non-blocking mode until a solution is found.

  • target_cost (int, optional) – A cost value provided by the user as a target for the solution to be found by the solver, when a solution with such cost is found and read, execution ends.

  • backend (BACKENDS) – At the moment, only the Loihi2 backend can be used.

  • hyperparameters (ty.Dict[str, ty.Union[int, npt.ArrayLike]], optional) – A dictionary specifying values for steps_to_fire, noise_amplitude, step_size and init_value. All but the last are integers, the initial value is an array-like of initial values for the variables defining the problem.

Returns

time_to_solution – Total time to solution in seconds.

Return type

npt.ArrayLike

property run_cfg

Run configuration for process model selection.

solve(timeout, target_cost=0, backend=<class 'lava.magma.core.resources.CPU'>, hyperparameters=None)

Create solver from problem spec and run until target_cost or timeout.

Parameters
  • timeout (int) – Maximum number of iterations (timesteps) to be run. If set to -1 then the solver will run continuously in non-blocking mode until a solution is found.

  • target_cost (int, optional) – A cost value provided by the user as a target for the solution to be found by the solver, when a solution with such cost is found and read, execution ends.

  • backend (BACKENDS, optional) – Specifies the backend where the main solver network will be deployed.

  • hyperparameters (ty.Dict[str, ty.Union[int, npt.ArrayLike]], optional) – A dictionary specifying values for steps_to_fire, noise_amplitude, step_size and init_value. All but the last are integers, the initial value is an array-like of initial values for the variables defining the problem.

Returns

solution – Candidate solution to the input optimization problem.

Return type

npt.ArrayLike

tune(params_grid, timeout, target_cost=0, backend=<class 'lava.magma.core.resources.CPU'>, stopping_condition=None)

Provides an interface to SolverTuner to search hyperparameters on the specififed grid. Returns the optimized hyperparameters.

Return type

Tuple[Dict, bool]

lava.lib.optimization.solvers.generic.solver.solve(problem, timeout, target_cost=None, backend=<class 'lava.magma.core.resources.Loihi2NeuroCore'>)

Create solver from problem spec and run until target_cost or timeout.

Parameters
  • problem (OptimizationProblem) – Optimization problem to be solved.

  • timeout (int) – Maximum number of iterations (timesteps) to be run. If set to -1 then the solver will run continuously in non-blocking mode until a solution is found.

  • target_cost (int, optional) – A cost value provided by the user as a target for the solution to be found by the solver, when a solution with such cost is found and read, execution ends.

  • backend (BACKENDS, optional) – Specifies the backend where the main solver network will be deployed.

Returns

solution – Candidate solution to the input optimization problem.

Return type

npt.ArrayLike

lava.lib.optimization.solvers.generic.sub_process_models

Inheritance diagram of lava.lib.optimization.solvers.generic.sub_process_models
class lava.lib.optimization.solvers.generic.sub_process_models.CostConvergenceCheckerModel(proc)

Bases: AbstractSubProcessModel

Model for the CostConvergence process.

The model composes a CostIntegrator unit with incomming connections, in this way, downstream processes can be directly connected to the CostConvergence process.

implements_process

alias of CostConvergenceChecker

implements_protocol

alias of LoihiProtocol

required_resources: ty.List[ty.Type[AbstractResource]] = [<class 'lava.magma.core.resources.CPU'>]
class lava.lib.optimization.solvers.generic.sub_process_models.DiscreteVariablesModel(proc)

Bases: AbstractSubProcessModel

Model for the DiscreteVariables process.

The model composes a population of StochasticIntegrateAndFire units and connects them via Dense processes as to represent integer or binary variables.

implements_process

alias of DiscreteVariablesProcess

implements_protocol

alias of LoihiProtocol

required_resources: ty.List[ty.Type[AbstractResource]] = [<class 'lava.magma.core.resources.CPU'>]
class lava.lib.optimization.solvers.generic.sub_process_models.StochasticIntegrateAndFireModel(proc_params=None)

Bases: PyLoihiProcessModel

CPU Model for the StochasticIntegrateAndFire process.

The model computes stochastic gradient and local cost both based on the input received from the recurrent connectivity ot other units. # Todo deprecate in favour of QuboScif.

added_input: PyInPort = LavaPyType(cls=<class 'lava.magma.core.model.py.ports.PyInPortVectorDense'>, d_type=<class 'int'>, precision=None)
assignment: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
cost_diagonal: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
do_fire(state)
firing: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'bool'>, precision=None)
implements_process

alias of StochasticIntegrateAndFire

implements_protocol

alias of LoihiProtocol

input_duration: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
integration: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
is_satisfied(prev_assignment, integration)
iterate_dynamics(added_input, state)
local_cost: PyOutPort = LavaPyType(cls=<class 'lava.magma.core.model.py.ports.PyOutPortVectorDense'>, d_type=<class 'int'>, precision=None)
messages: PyOutPort = LavaPyType(cls=<class 'lava.magma.core.model.py.ports.PyOutPortVectorDense'>, d_type=<class 'int'>, precision=None)
min_cost: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
min_integration: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
min_state: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
noise_amplitude: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
noise_precision: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
prev_assignment: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
refractory_period: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
required_resources: ty.List[ty.Type[AbstractResource]] = [<class 'lava.magma.core.resources.CPU'>]
reset_state(firing_vector)
run_spk()

Function that runs in Spiking Phase

state: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
step_size: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
steps_to_fire: ndarray = LavaPyType(cls=<class 'numpy.ndarray'>, d_type=<class 'int'>, precision=32)
class lava.lib.optimization.solvers.generic.sub_process_models.StochasticIntegrateAndFireModelSCIF(proc)

Bases: AbstractSubProcessModel

Model for the StochasticIntegrateAndFire process.

The process is just a wrapper over the QuboScif process. # Todo deprecate in favour of QuboScif.

implements_process

alias of StochasticIntegrateAndFire

implements_protocol

alias of LoihiProtocol

required_resources: ty.List[ty.Type[AbstractResource]] = [<class 'lava.magma.core.resources.Loihi2NeuroCore'>]