A client python API for accessing LightSolver's capabilities
Project description
LightSolver Platform Client
The LightSolver Platform Client is a Python package designed to interface with the LightSolver Cloud to facilitate solving Quadratic Unconstrained Binary Optimization (QUBO) problems.
This package is designated for internal access to features during the development process, as well as serves as a prototype for future versions of the production LightSolver Platform Client.
Features
- QUBO Problem Solving: The
solve_qubo
function accepts a QUBO problem, represented either as a 2D array (matrix) or an adjacency list, and returns the solution. - Synchronous and Asynchronous Operation: Users can choose between blocking (synchronous) and non-blocking (asynchronous) modes for QUBO problem solving.
- Flexible Installation: Compatible with both Windows and Ubuntu systems.
Solve QUBO
The solve_qubo
function handles the computation of QUBO problems, either represented by a 2D array (matrix) or by an adjacency list. For code samples, see the Usage section.
Input Matrix Validity
- The matrix must be square.
- The matrix supports int or float cell values.
Return Value
A dictionary with the following fields:
- 'id': Unique identifier of the solution.
- 'solution': The solution as a Python list() of 1s and 0s.
- 'objval: The objective value of the solution.
- 'solverRunningTime': Time spent by the solver to calculate the problem.
- 'receivedTime': Timestamp when the request was received by the server.
Synchronous and Asynchronous Usage
- Synchronous Mode (Default): The
waitForSolution
flag is set to True by default. The function blocks operations until a result is received. - Asynchronous Mode: Set
waitForSolution
to False. The function returns immediately with a token object, allowing the script to continue while the server processes the QUBO problem.
Setting Up
Prerequisites
- Valid credentials for connecting to the LightSolver Cloud.
- LightSolver Client code project - please use this link to download.
- Python 3.10.
- Operating System: Linux or Windows. Tested on Ubuntu 20.04 and Windows 11.
- Highly Recommended: Use a virtual environment before installing laser-mind-client (Please see detailed action further below under the relevant OS).
Installation
Complete the installation on Windows or Ubuntu as described below. For further assistance with setup or connection issues, contact support@lightsolver.com.
Windows
-
Press the windows key, type "cmd", right click on the result and select "Run as administrator".
-
Navigate to the root folder where you unzipped and plan to use the LightSolver Client:
cd <your project folder>
-
(Recommended) Set the LightSolver credentials using environment variables (will remove the need to provide credentials for every usage). Run the following command:
python setup_env.py
- (Recommended) Create a virtual environment:
python -m venv .venv
- (Recommended) Activate the new virtual environment:
.venv\Scripts\activate
- Install the laser-mind-client package. This command instructs pip to install the package from a local folder instead of searching online:
pip install --no-cache-dir --find-links=.\packages laser-mind-client
- (Recommended) Test LightSolver credentials Run the following command:
python test_env.py
if test credentials failed , please reinstall credentials using following commands:
- Exit virtual environment , by running :
deactivate
- Run the following command:
python setup_env.py
Ubuntu
-
Open new terminal window
-
Navigate to the root folder where you unzipped and plan to use the LightSolver Client:
cd <your project folder>
-
(Recommended) Set the LightSolver credentials using environment variables (will remove the need to provide credentials for every usage). Run the following command:
python3 setup_env.py
source ~/.bash_profile
- (Recommended) Create a virtual environment:
python3 -m venv .venv
- (Recommended) Activate the new virtual environment:
chmod 755 .venv/bin/activate
source .venv/bin/activate
- Install the laser-mind-client package. This command instructs pip to install the package from a local folder instead of searching online:
pip install --no-cache-dir --find-links=./packages laser-mind-client
- (Recommended) Test LightSolver credentials Run the following command:
python3 test_env.py
if test credentials failed , please reinstall credentials using following commands:
- Exit virtual environment , by running :
deactivate
- Run the following command:
python3 setup_env.py
source ~/.bash_profile
Authentication
Initialization of the LaserMind
class automatically forms a secure and authenticated connection with the LightSolver Cloud.
Subsequent calls by the same user are similarly secure and authenticated.
Usage
To begin solving any QUBO problem:
- Create an instance of the
LaserMind
class. This class represents the client that requests solutions from the LightSolver Cloud. - Call the
solve_qubo
function using either a matrix or an adjacency list. Note: You may either provide a value formatrixData
or foredgeList
, but not both.
Solve QUBO Matrix Example
This example creates a matrix representing a QUBO problem and solves it using the LightSolver Platform Client.
The solve_qubo
function is used with the following parameters:
matrixData
: A 2D array representing the QUBO problem.timeout
: The required time limit for the calculation in seconds.
import numpy
from laser_mind_client import LaserMind
# Create a mock QUBO problem
quboProblemData = numpy.random.randint(-1, 2, (10,10))
# Symmetrize the matrix
quboProblemData = (quboProblemData + quboProblemData.T) // 2
# Connect to the LightSolver Cloud
lsClient = LaserMind()
res = lsClient.solve_qubo(matrixData = quboProblemData, timeout=1)
print(res)
Solve QUBO Adjacency List Example
This example describes a QUBO problem using an adjacency list. This is useful for sparse matrices.
The solve_qubo
function is used with the following parameters:
edgeList
: The adjacency list representing the QUBO problem.timeout
: The required time limit for the calculation in seconds.
from laser_mind_client import LaserMind
# Create a mock QUBO problem
quboListData = [
[1,1,5],
[1,2,-6],
[2,2,3],
[2,3,-1],
[3,10,1]]
# Connect to the LightSolver Cloud
lsClient = LaserMind()
res = lsClient.solve_qubo(edgeList=quboListData, timeout=1)
print(res)
Solve QUBO Matrix using Asynchronous Flow
This example demonstratse how to solve a QUBO problem asynchronously using the LightSolver Platform Client.
Begin by creating a matrix to represent your QUBO problem.
The solve_qubo
function is used with the following parameters:
matrixData
: A 2D array representing the QUBO problem.timeout
: The desired time limit for the calculation in seconds.waitForSolution
: A boolean flag set toFalse
to indicate non-blocking mode.
import numpy
from laser_mind_client import LaserMind
# Create a mock QUBO problem
quboProblemData = numpy.random.randint(-1, 2, (10,10))
# Symmetrize our matrix
quboProblemData = (quboProblemData + quboProblemData.T) // 2
# Connect to the LightSolver Cloud
lsClient = LaserMind()
# Request a solution to the QUBO problem and get the request token for future retrieval.
# This call does not block operations until the problem is solved.
requestToken = lsClient.solve_qubo(matrixData = quboProblemData, timeout=1, waitForSolution=False)
# You can run other code here that is not dependant on the request, while the server processes your request.
# Retrieve the solution using the get_solution_sync method.
# This blocks operations until the solution is acquired.
res = lsClient.get_solution_sync(requestToken)
print(res)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file laser_mind_client-0.21.0.tar.gz
.
File metadata
- Download URL: laser_mind_client-0.21.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afaaa0b38d68f44d6b94821ba3657d15efa01e1e222b536fe364cf2b20c74020 |
|
MD5 | 27955ea76d7c92fe87977b2c9220d7ed |
|
BLAKE2b-256 | 74eae06f7de7e282754998a9bcedd6f5060e7c00b2f87300cd63622c21fda70a |
File details
Details for the file laser_mind_client-0.21.0-py3-none-any.whl
.
File metadata
- Download URL: laser_mind_client-0.21.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80a3f8c6cd94e6f86026bcf0a96d46290ea2a4798c63f45374ebd2d83e51b58a |
|
MD5 | bf02d63019307a3045ee835407872157 |
|
BLAKE2b-256 | e32e0ae7b47c3a0323ed673e06d325c1ed1311634e92693b5d90bb254cb9eca9 |