Installation Guide#
This chapter explains how to install Kaiwu-PyTorch-Plugin and its dependencies.
1. System Requirements#
Before installation, make sure your system meets the following requirements:
Dependency |
Version Required |
|---|---|
Python |
3.10 |
PyTorch |
2.7.0 |
NumPy |
2.2.6 |
Kaiwu SDK |
v1.2.0+ |
Check your Python version:
python --version
# or
python3 --version
If you need to install Python 3.10, visit the Python 3.10 download page <https://www.python.org/downloads/release/python-31011/ >_.
2. Installing Kaiwu-PyTorch-Plugin#
2.1 Create and Activate Environment#
We recommend creating an isolated Python environment with conda:
# Create a new environment
conda create -n quantum_env python=3.10
# Activate the environment
conda activate quantum_env
2.2 Clone the Repository#
Clone the project from GitHub to your local machine:
git clone https://github.com/QBoson/Kaiwu-pytorch-plugin.git
cd kaiwu-pytorch-plugin
2.3 Install Dependencies#
Install project dependencies:
pip install -r requirements/requirements.txt
2.4 Install the Plugin#
pip install .
3. Install Kaiwu SDK (Required)#
Kaiwu-PyTorch-Plugin relies on Kaiwu SDK for quantum-computing capabilities; you must install Kaiwu SDK separately.
3.1 Obtain the SDK#
Visit the
Kaiwu SDK download page <https://platform.qboson.com/sdkDownload >_Download the SDK package for your system
Follow the Kaiwu SDK installation guide to complete installation
3.2 Configure Credentials#
After installation, configure your SDK credentials:
User ID: <your-user-id>
SDK Token: <your-sdk-token>
Note
Replace the placeholders with your actual credentials, which can be obtained from the Kaiwu SDK page on the QBoson platform.
4. Verify Installation#
After installation, run the following code to verify success:
# 验证 PyTorch
import torch
print(f"PyTorch version: {torch.__version__}")
# 验证 Kaiwu SDK
import kaiwu
import numpy as np
from kaiwu.classical import SimulatedAnnealingOptimizer
opt = SimulatedAnnealingOptimizer()
mat = np.array([[1, -1], [-1, 1]])
result = opt.solve(mat)
print(f"Kaiwu SDK version: {kaiwu.__version__}")
print(result)
# 验证 Kaiwu-PyTorch-Plugin
from kaiwu.torch_plugin import RestrictedBoltzmannMachine
print("Kaiwu-PyTorch-Plugin imported successfully!")
# 简单测试
rbm = RestrictedBoltzmannMachine(num_visible=10, num_hidden=5)
print(f"RBM created with {rbm.num_visible} visible and {rbm.num_hidden} hidden units")
If no errors appear, installation is complete. You can now build models and validate them with classical simulators; once satisfied, switch to a quantum backend to leverage real quantum resources.
5. Obtain Quantum-Computer Access#
To experience genuine quantum computing power, you need access to a quantum computer:
Register an account on the QBoson platform
Contact official staff through the platform to obtain real-machine quota
Note
While awaiting real-machine access, you can develop and test with simulators. Kaiwu SDK provides several classical optimizers (e.g. simulated-annealing optimizer) as classical substitutes for quantum samplers.
6. Development Environment Setup (Optional)#
If you plan to contribute to the plugin, install the development dependencies:
pip install -r requirements/devel.txt
Run tests:
# Run all tests
pytest tests/
# Run specific tests
pytest tests/test_rbm.py
Code-style check:
pylint kaiwu/
7. FAQ#
Q: Installation reports incompatible Python version?#
A: Kaiwu-PyTorch-Plugin currently requires Python 3.10. Create a Python 3.10 environment with conda:
conda create -n quantum_env python=3.10
conda activate quantum_env
Q: Cannot import kaiwu.torch_plugin?#
A: Please ensure that:
the environment is activated (
conda activate quantum_env)Kaiwu SDK is correctly installed
Kaiwu-PyTorch-Plugin is correctly installed (
pip install .); check with
Q: How do I update to the latest version?#
A: Enter the project directory and pull the latest code:
cd kaiwu-pytorch-plugin
git pull origin main
pip install .