This release is a pre-release and may not be stable for production use.
cqlib-tianyan
Python bindings for the Tianyan quantum cloud platform client.
Overview
This package provides synchronous Python access to the Tianyan quantum computing cloud platform, allowing users to:
- Authenticate with API keys
- Discover available quantum backends
- Submit quantum circuits (QCIS format)
- Retrieve execution results with readout error mitigation
All blocking operations release the GIL, making the library safe for use in multi-threaded Python applications.
Installation
From Source (Development)
# Install maturin if not already installed
pip install maturin
# Build and install the package
maturin develop
Production Build
maturin build --release
pip install target/wheels/*.whl
Quick Start
from cqlib_tianyan import TianyanPlatform
# Authenticate with your API key
platform = TianyanPlatform.login("your_api_key")
# List available backends
backends = platform.list_backends()
for backend in backends:
print(f"{backend.name}: {backend.status}")
# Get a specific backend
backend = platform.get_backend("tianyan-287")
print(f"Physical qubits: {backend.num_qubits()}")
# Submit a circuit
task = backend.run(["H Q1\nM Q1"], shots=1000)
# Wait for results
results = task.wait(timeout=120.0)
for result in results:
print(f"Task ID: {result.task_id}")
print(f"Counts: {result.counts}")
print(f"Probabilities: {result.probabilities}")
API Reference
Core Classes
TianyanPlatform
The main entry point for interacting with the Tianyan platform.
# Login with API key
platform = TianyanPlatform.login(
api_key="your_key",
domain="qc.zdxlz.com", # Optional
save_credentials=True, # Optional, default: True
auto_refresh=True, # Optional, default: True
)
# Load from saved credentials
platform = TianyanPlatform.from_credentials()
# List all backends
backends = platform.list_backends()
# Get specific backend
backend = platform.get_backend("device_name")
# Submit circuits directly
task = platform.submit(
circuits=["H Q1\nM Q1"],
shots=1000,
device_name="tianyan-287"
)
TianyanBackend
Represents a quantum computing backend.
Only superconducting devices and simulators can submit tasks. Photonic and ion-trap
devices fail before submission. Configuration access (device_config() and
num_qubits()) and readout calibration require a superconducting device.
In "auto" mode, simulators return raw counts without downloading configuration;
superconducting devices apply calibration when data is available and at most 14
qubits are measured. Explicit "enabled" mode fails before submission on any
non-superconducting device. "disabled" always returns raw counts.
# Backend properties
backend.name # Device identifier
backend.display_name # Human-readable name
backend.device_type # DeviceType enum
backend.status # DeviceStatus enum
backend.toll # DeviceToll enum (free/paid)
if backend.device_type == "superconducting":
backend.num_qubits() # Physical qubit count (loads config on first use)
# Check availability
if backend.is_available() and backend.device_type.value in ("superconducting", "simulator"):
# Submit circuits
task = backend.run(circuits=["H Q1\nM Q1"], shots=1000)
# Raw execution (no calibration)
task = backend.run(circuits=["H Q1\nM Q1"], shots=1000, calibration_mode="disabled")
# With explicit calibration mode
task = backend.run(
circuits=["H Q1\nM Q1"],
shots=1000,
calibration_mode="disabled" # "auto", "enabled", "disabled"
)
# Get device configuration
if backend.device_type == "superconducting":
device = backend.device_config() # Returns cqlib.device.Device
run(circuits, shots, *, calibration_mode="auto") accepts a string or a
CalibrationMode object. platform.submit() accepts the same keyword-only
option. Each call submits a new task. run_raw() and run_with_mode() remain
deprecated aliases and emit DeprecationWarning.
TaskHandle
Represents a batch of submitted circuits.
wait() and wait_raw() take timeout and poll_interval in seconds, with
defaults of 120.0 and 5.0. Both methods can be called without arguments.
# Task properties
task.task_ids # List of platform-assigned task IDs
task.device_name # Backend name
task.shots # Number of shots
task.submitted_at # ISO 8601 timestamp
# Non-blocking status check
results = task.status() # Returns completed results only
# Blocking wait for all results
results = task.wait(
timeout=120.0,
poll_interval=5.0
)
# Wait for raw results
results = task.wait_raw() # timeout=120.0, poll_interval=5.0 (seconds)
TianyanConfig
Configuration for the platform client.
config = TianyanConfig(
domain="qc.zdxlz.com",
save_credentials=True,
auto_refresh=True,
credentials_path="~/.cqlib/tianyan/credentials.json"
)
Enums
from cqlib_tianyan import DeviceStatus, DeviceToll, DeviceType, CalibrationMode
# DeviceStatus values: "running", "calibration", "under_maintenance", "offline", "upgrading", "unknown"
# DeviceToll values: "free", "paid", "unknown"
# DeviceType values: "superconducting", "photonic", "ion_trap", "simulator"
# CalibrationMode values: "auto", "enabled", "disabled"
Read backend.device_type.value, or compare directly with a string, such as
backend.device_type == "simulator".
| Device type | .value |
Devices |
|---|---|---|
| Simulator | simulator |
tianyan_sw, tianyan_s, tianyan_tn, tianyan_tnn, tianyan_sa, tianyan_swn |
| Photonic | photonic |
tianyan-p2000 |
| Superconducting | superconducting |
tianyan176, tianyan176-2, tianyan24, tianyan504, tianyan-287, tianyan-294 |
Exception Handling
from cqlib_tianyan import TianyanError
try:
platform = TianyanPlatform.login("invalid_key")
except Exception as e:
# Handle authentication failure
print(f"Login failed: {e}")
Note: In abi3 mode, TianyanError cannot be caught by type. Catch Exception instead.
Testing
Test Structure
tests/
├── conftest.py # Pytest configuration and fixtures
└── test_cqlib_tianyan.py # Main test file
Environment Variables
| Variable | Required | Description |
|---|---|---|
TIANYAN_API_KEY |
For integration tests | Your Tianyan platform API key |
TIANYAN_DOMAIN |
Optional | Custom domain (defaults to qc.zdxlz.com) |
TIANYAN_DEVICE |
Optional | Target device name (e.g., "tianyan-287") |
Running Tests
# Run all tests (requires API key)
TIANYAN_API_KEY="your_key" pytest tests/ -v
# Run with specific device
TIANYAN_API_KEY="your_key" TIANYAN_DEVICE="tianyan-287" pytest tests/ -v
# Run only unit tests (no API key required)
pytest tests/ -v -m "not integration"
# Run integration tests only
TIANYAN_API_KEY="your_key" pytest tests/ -v -m integration
# Include slow tests (long timeouts)
TIANYAN_API_KEY="your_key" pytest tests/ -v --run-slow
# Run specific test class
TIANYAN_API_KEY="your_key" pytest tests/test_cqlib_tianyan.py::TestCircuitSubmission -v
Test Markers
| Marker | Description |
|---|---|
integration |
Requires API access and network connectivity |
slow |
Long-running tests (waits for circuit execution) |
Technical Details
Architecture
This package is built with:
- PyO3: Rust-Python bindings
- Maturin: Build tool for Python-Rust hybrid projects
- abi3: Stable ABI with a CPython 3.11 baseline
Module Structure
crates/binding-python/
├── Cargo.toml # Rust package manifest
├── pyproject.toml # Python package configuration
├── src/
│ ├── lib.rs # Module initialization
│ ├── error.rs # Exception types
│ ├── config.rs # TianyanConfig bindings
│ ├── platform.rs # TianyanPlatform bindings
│ ├── backend.rs # TianyanBackend bindings
│ └── task.rs # TaskHandle bindings
├── cqlib_tianyan/
│ ├── __init__.py # Python package entry
│ ├── __init__.pyi # Type stubs
│ └── py.typed # PEP 561 marker
└── tests/
├── conftest.py # Pytest configuration
└── test_cqlib_tianyan.py # Test suite
Known Limitations
-
ABI3 Mode: Due to
abi3-py311feature:TianyanErrorcannot inherit fromRuntimeErrorTianyanErrorcannot be instantiated directly in Python- Exception catching must use
except Exception:instead ofexcept TianyanError:
-
GIL Release: Long-running operations (
wait(),wait_raw()) release the GIL to allow other Python threads to run.
Dependencies
- CPython 3.11+
cqlib>=2.0.0b1(installed automatically) fordevice_config()andExecutionResultconversion. The classic PyPIcqlib 1.3.xis not compatible; it does not providecqlib.deviceorcqlib.circuit.cqlib-core>=0.1.0-beta.1(Rust workspace dependency from crates.io)cqlib-tianyan(Rust workspace dependency)
License
Licensed under the Apache License, Version 2.0.
Copyright (c) 2026 China Telecom Quantum Group
Metadata
Release files for cqlib-tianyan 0.1.0b3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| cqlib_tianyan-0.1.0b3-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for cqlib_tianyan-0.1.0b3-cp311-abi3-win_amd64.whl |
| cqlib_tianyan-0.1.0b3-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details for cqlib_tianyan-0.1.0b3-cp311-abi3-manylinux_2_28_x86_64.whl |
| cqlib_tianyan-0.1.0b3-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details for cqlib_tianyan-0.1.0b3-cp311-abi3-manylinux_2_28_aarch64.whl |
| cqlib_tianyan-0.1.0b3-cp311-abi3-macosx_11_0_x86_64.whl | CPython 3.11 | abi3 | macOS 11.0+ x86-64 | Details for cqlib_tianyan-0.1.0b3-cp311-abi3-macosx_11_0_x86_64.whl |
| cqlib_tianyan-0.1.0b3-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for cqlib_tianyan-0.1.0b3-cp311-abi3-macosx_11_0_arm64.whl |
Total release size: 13.9 MB
Release files / cqlib_tianyan-0.1.0b3-cp311-abi3-win_amd64.whl
| Download URL | cqlib_tianyan-0.1.0b3-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e6e321ff2b0a95d821dde6974328f2f8c92665a096536f944a595c5575bc4f13
|
|
BLAKE2b-256 checksum How to use checksums |
0259c49f3d1c405aa41cd8a89640925595d2cf6107fce5e69e184535c23b5065
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / cqlib_tianyan-0.1.0b3-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | cqlib_tianyan-0.1.0b3-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0eec7d5a5c949d3e3ec7f2725d73967bd68f63984e6cb66af53c14d1cb37991b
|
|
BLAKE2b-256 checksum How to use checksums |
bae6c2159fc4829ca7574a75e8cfb2ed2a7ae8d947df06af67bc0aab8478b15d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / cqlib_tianyan-0.1.0b3-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | cqlib_tianyan-0.1.0b3-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
811d5681e9ac72215aff443761fa6e60e2bc8a561f83debfd2c2366322ff5bc7
|
|
BLAKE2b-256 checksum How to use checksums |
4c89265cbdd41ca902a2508f25bb54d9a748430cde1696f778336b2f4853e21f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / cqlib_tianyan-0.1.0b3-cp311-abi3-macosx_11_0_x86_64.whl
| Download URL | cqlib_tianyan-0.1.0b3-cp311-abi3-macosx_11_0_x86_64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
cbf94c02254fbe13d8767de57f8046c5c68ce4224e553e15e7b010ea6fd5428f
|
|
BLAKE2b-256 checksum How to use checksums |
fa23bec4b1fbeb5e482799306bba7a1ca35815bb23cdd63f518951ac4a5402b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / cqlib_tianyan-0.1.0b3-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | cqlib_tianyan-0.1.0b3-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e8e44f0b8e07bc6d4b34bc7d29e70b5012ad2b2d8180f5d18efab6bc9606e187
|
|
BLAKE2b-256 checksum How to use checksums |
7f5c6ea3b72770ae14fdc5d08a560e6f46273fa3e2088d0eb27a631db5be022e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for cqlib-tianyan 0.1.0b3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.