BQPhy Python SDK
This documentation provides the steps to install, configure, and execute optimization jobs using the BQPhy Python SDK.
1. Installation
Install the BQPhy Client using the provided wheel file via pip. Ensure the .whl file is in your current directory.
pip install bqphy_client-0.1.1-py3-none-any.whl
2. Configuration
The SDK requires two configuration files located in the .bqphy directory within your user home folder (e.g., ~/.bqphy/ or C:\Users\Username\.bqphy\).
secrets.json
Add your authentication token here:
{
"TOKEN": "YOUR_API_TOKEN_HERE"
}
config.json
Add your environment-specific details (API URL, Tenant ID, etc.):
{
"API_URL": "https://bqphy.bqpsim.com",
"TENANT_ID": "your_account_id",
"SERVER_ID": "server_id",
"REALM": "bqphy",
"skip_upload_on_error": false,
"optimization": {
"trials": 1,
"poll_interval": 30,
"max_wait": 3600
}
}
3. Prepare the Optimization Model
Create a Python file (e.g., FO_Knapsack_500.py) containing your optimization logic. This file must define the function or class (e.g., Evaluator) that the BQPhy engine will invoke.
4. Submitting a Job
Use the following Python snippet to initialize the optimizer and submit your job to the BQPhy API.
from bqphy_client.optimiser import BQPhy_API
# 1. Define Optimization Parameters
OPTIMIZATION_PARAMS = {
"designVariables": 500,
"numPopulation": 50,
"maxGeneration": 100,
"deltaTheta": 0.1,
"typeOfOptimisation": "Discrete"
}
# 2. Initialize the API Client
optimizer = BQPhy_API()
# 3. Configure Model Details
optimizer.model_file_path("FO_Knapsack_500.py")
optimizer.model("Evaluator")
# 4. Initialize credentials from home directory and run
optimizer.initialize_from_home(OPTIMIZATION_PARAMS)
optimizer.run(log_level="info")
5. Output and Results
Once the execution is complete, the SDK downloads the output data automatically.
- Location: Results are generated under the
resultsdirectory in your current working directory (./results). - Logs: You can monitor the progress in the terminal via the
log_level="info"parameter.