Package: lava-optimization
Neuromorphic Constrained Optimization LibraryA library of solvers that leverage neuromorphic hardware for constrained optimization.Table of ContentsAbout The ProjectTaxonomy of Optimization ProblemsOptimizationSolver and OptimizationProblem ClassesTutorialsQuadratic ProgrammingQuadratic Unconstrained Binary OptimizationExamplesSolving QPSolving QUBOGetting StartedRequirementsInstallationAbout the ProjectConstrained optimization searches for the values of input variables that minimize or maximize a given objective function, while the variables are subject to constraints. This kind of problem is ubiquitous throughout scientific domains and industries.
Constrained optimization is a promising application for neuromorphic computing as
itnaturally aligns with the dynamics of spiking neural networks. When individual neurons represent states of variables, the neuronal connections can directly encode constraints between the variables: in its simplest form, recurrent inhibitory synapses connect neurons that represent mutually exclusive variable states, while recurrent excitatory synapses link neurons representing reinforcing states. Implemented on massively parallel neuromorphic hardware, such a spiking neural network can simultaneously evaluate conflicts and cost functions involving many variables, and update all variables accordingly. This allows a quick convergence towards an optimal state. In addition, the fine-scale timing dynamics of SNNs allow them to readily escape from local minima.This Lava repository currently supports solvers for the following constrained optimization problems:Quadratic Programming (QP)Quadratic Unconstrained Binary Optimization (QUBO)As we continue development, the library will support more constrained optimization problems that are relevant for robotics and operations research.
We currently plan the following development order in such a way that new solvers build on the capabilities of existing ones:Constraint Satisfaction Problems (CSP) [problem interface already available]Integer Linear Programming (ILP)Mixed-Integer Linear Programming (MILP)Mixed-Integer Quadratic Programming (MIQP)Linear Programming (LP)Taxonomy of Optimization ProblemsMore formally, the general form of a constrained optimization problem is:$$
\displaystyle{\min_{x} \lbrace f(x) | g_i(x)	\leq  b,	h_i(x)	= c.\rbrace}
$$Where $f(x)$ is the objective function to be optimized while $g(x)$ and $h(x)$
constrain the validity of $f(x)$ to regions in the state space satisfying the
respective equality and inequality constraints. The vector $x$ can be
continuous, discrete or a mixture of both. We can then construct the following
taxonomy of optimization problems according to  the characteristics of the
variable domain and of $f$, $g$, and $h$:In the long run, lava-optimization aims to offer support to solve all of the problems in the figure with a neuromorphic backend.OptimizationSolver and OptimizationProblem ClassesThe figure below shows the general architecture of the library.  We harness the general definition of constraint optimization problems to createOptimizationProbleminstances by composingConstraints,Variables, andCostclasses which describe the characteristics of every subproblem class. Note that while a quadratic problem (QP) will be described by linear equality and inequality constraints with variables on the continuous domain and a quadratic function. A constraint satisfaction problem (CSP) will be described by discrete constraints, defined by variable subsets and a binary relation describing the mutually allowed values for such discrete variables and will have a constant cost function with the pure goal of satisfying constraints.An API for every problem class can be created by inheriting fromOptimizationSolverand composing particular flavors ofConstraints,Variables, andCost.The instance of anOptimization problemis the valid input for instantiating the genericOptimizationSolverclass. In this way, theOptimizationSolverinterface is left fixed and theOptimizationProblemallows the greatest flexibility for creating new APIs. Under the hood, theOptimizationSolverunderstands the composite structure of theOptimizationProblemand will in turn compose the required solver components and Lava processes.TutorialsQuadratic ProgrammingSolving LASSO.Quadratic Unconstrained Binary OptimizationSolving Maximum Independent Set.ExamplesSolving QP problemsimportnumpyasnpfromlava.lib.optimization.problems.problemsimportQPfromlava.lib.optimization.solvers.generic.solverimport(SolverConfig,OptimizationSolver,)# Define QP problemQ=np.array([[100,0,0],[0,15,0],[0,0,5]])p=np.array([[1,2,1]]).TA=-np.array([[1,2,2],[2,100,3]])k=-np.array([[-50,50]]).Tqp=QP(Q,p,A,k)# Define hyper-parametershyperparameters={"neuron_model":"qp-lp_pipg","alpha_mantissa":160,"alpha_exponent":-8,"beta_mantissa":7,"beta_exponent":-10,"decay_schedule_parameters":(100,100,0),"growth_schedule_parameters":(3,2),}# Solve using QPSolversolver=OptimizationSolver(problem=qp)config=SolverConfig(timeout=400,hyperparameters=hyperparameters,backend="Loihi2")solver.solve(config=config)Solving QUBOimportnumpyasnpfromlava.lib.optimization.problems.problemsimportQUBOfromlava.lib.optimization.solvers.generic.solverimport(SolverConfig,OptimizationSolver,)# Define QUBO problemq=np.array([[-5,2,4,0],[2,-3,1,0],[4,1,-8,5],[0,0,5,-6]]))qubo=QUBO(q)# Solve using generic OptimizationSolversolver=OptimizationSolver(problem=qubo)config=SolverConfig(timeout=3000,target_cost=-50,backend="Loihi2")solution=solver.solve(config=config)Getting StartedRequirementsWorking installation of Lava, installed automatically with poetry below.For custom installs see Lava installation
tutorial.Installation[Linux/MacOS]cd$HOMEgitclonegit@github.com:lava-nc/lava-optimization.gitcdlava-optimization
curl-sSLhttps://install.python-poetry.org|python3-
poetryconfigvirtualenvs.in-projecttruepoetryinstallsource.venv/bin/activate
pytest[Windows]# Commands using PowerShellcd$HOMEgitclonegit@github.com:lava-nc/lava-optimization.gitcdlava-optimizationpython3-mvenv.venv.venv\Scripts\activatepipinstall-Upipcurl-sSLhttps://install.python-poetry.org|python3-poetryconfigvirtualenvs.in-projecttruepoetryinstallpytest[Alternative] Installing Lava via CondaIf you use the Conda package manager, you can simply install the Lava package
via:condainstalllava-optimization-cconda-forgeAlternatively with intel numpy and scipy:condacreate-nlava-optimizationpython=3.9-cintel
condaactivatelava-optimization
condainstall-nlava-optimization-cintelnumpyscipy
condainstall-nlava-optimization-cconda-forgelava-optimization--freeze-installed