QCloudService
QCloudService is the entry point for OriginQ cloud backends.
QCloudService
QCloudService(api_key: str)
QCloudService(api_key: str, url: str)- The single-argument constructor resolves the service domain from a new-format API key; legacy keys do not carry a domain and fall back to the historical default cloud endpoint.
- The two-argument constructor's
urlexplicitly overrides the domain encoded in the key, for testing or private deployments; in the 0.5.1 bindingsurlno longer has a default value.
Methods
| Method | Signature | Description |
|---|---|---|
setup_logging | setup_logging(output: LogOutput = LogOutput.CONSOLE, file_path: str = "") -> None | Configure client-side logging. |
backends | backends() -> dict[str, bool] | List backend names and availability flags. |
best_qubit_blocks | best_qubit_blocks(chip_id: str, qubit_num: int, label: int = 1, qubit_block_num: int = 1) -> BestQubitBlocks | Query optimal qubit blocks for a chip. |
backend | backend(backend_name: str) -> QCloudBackend | Open a backend by name. |
BestQubitBlocks
BestQubitBlocks stores the result of a cloud-side optimal-qubit-block query. The returned blocks are ranked by quality and can be used directly with QCloudOptions.set_specified_block(...).
| Property / Method | Type | Description |
|---|---|---|
chip_id | str | Chip identifier used for the query. |
qubit_num | int | Number of qubits requested for each block. |
label | int | Optimization label used for block selection. |
qubit_block_num | int | Number of qubit blocks requested. |
qubit_blocks | list[list[int]] | Selected qubit blocks, each a list of physical qubit indices. |
size() | int | Number of selected blocks (len(blocks)). |
empty() | bool | Whether no blocks were selected. |
block(index: int) | list[int] | One selected block by index. Raises IndexError if out of range. |
BestQubitBlocks supports __getitem__ / __len__ / __repr__.
from pyqpanda3.qcloud import QCloudService
service = QCloudService("your_api_key")
blocks = service.best_qubit_blocks("WK_C180_2", qubit_num=2, label=1, qubit_block_num=2)
print(blocks.chip_id) # "WK_C180_2"
print(blocks.qubit_blocks) # [[59, 69], [99, 108]]
print(blocks.size()) # 2
print(blocks.block(0)) # [59, 69]
print(blocks[0]) # [59, 69]
print(len(blocks)) # 2QCloudBackend
QCloudBackend represents one selected cloud backend.
QCloudBackend(backend_name: str)Common execution overloads
run(
prog: QProg,
shots: int,
model: QCloudNoiseModel = QCloudNoiseModel(),
batch_id: str = "",
task_form: int = 4,
) -> QCloudJobrun(
prog: QProg,
shots: int,
options: QCloudOptions,
enable_binary_encoding: bool = False,
batch_id: str = "",
task_form: int = 4,
) -> QCloudJobrun(
progs: list[QProg],
shots: int,
options: QCloudOptions,
enable_binary_encoding: bool = False,
batch_id: str = "",
task_form: int = 4,
) -> QCloudJobOther source-supported overloads also include:
run(prog, qubits=[...])run(prog, amplitudes=[...])run(prog, amplitude="0101")run_quantum_state_tomography(prog, shots, options=QCloudOptions())
run_instruction
run_instruction(
instruction: str | list[str],
shots: int,
options: QCloudOptions,
batch_id: str = "",
task_form: int = 4,
) -> QCloudJobSubmit instruction JSON directly instead of sending QProg.
Chip and layout helpers
| Method | Signature | Description |
|---|---|---|
chip_info | chip_info() -> ChipInfo | Raw chip metadata. |
chip_backend | chip_backend(qubits: list[int] = []) -> ChipBackend | Convenience wrapper for chip_info().get_chip_backend(). |
best_qubit_blocks | best_qubit_blocks(qubit_num: int, label: int = 1, qubit_block_num: int = 1) -> BestQubitBlocks | Query optimal qubit blocks for this backend. |
name | name() -> str | Backend name. |
NOTE
Real QPU limitation
chip_info() and chip_backend() are only available for real QPU backends. Calling them on cloud simulators such as full_amplitude, partial_amplitude, or single_amplitude raises RuntimeError: This function is only for real QPU backend. Since 0.5.0, chip_info() can be called without arguments (the options overload remains available).
Expectation interfaces
expval_hamiltonian(
prog: QProg,
hamiltonian: Hamiltonian,
shots: int = 1000,
noise_model: QCloudNoiseModel = QCloudNoiseModel(),
) -> floatexpval_hamiltonian(
prog: QProg,
hamiltonian: Hamiltonian,
options: QCloudOptions,
) -> floatEquivalent overloads exist for expval_pauli_operator(...).
ChipInfo
ChipInfo exposes hardware calibration data and can materialize a ChipBackend.
| Method | Description |
|---|---|
qubits_num() | Number of qubits. |
chip_id() | Chip identifier. |
available_qubits() | Available physical qubits. |
high_frequency_qubits() | High-frequency qubits. |
single_qubit_info() | Per-qubit readout and coherence data. |
double_qubits_info() | Two-qubit fidelity data. |
get_basic_gates() | Native gate set. |
get_compensate_angle_map() | CZ compensation angles. |
get_double_gate_timing() | Double-qubit gate timing values. |
get_single_gate_timing() | Single-qubit gate timing values. |
get_chip_topology(qubits=[]) | Coupling graph. |
get_chip_backend(qubits=[]) | Build a ChipBackend with timing, topology, and fidelity maps. |
QCloudOptions
QCloudOptions controls compilation, mapping, correction, and output options for cloud submissions.
QCloudOptions(
amend_flag: int = 1,
use_cz_pattern: bool = False,
mapping: bool = True,
optimization: bool = True,
point_label: int = 1,
is_prob_counts: bool = True,
specified_block: list[int] = [],
)| Method | Signature | Description |
|---|---|---|
set_amend_flag | set_amend_flag(amend_flag: int) -> None | 0 disables correction, 1 enables global sampling correction, 3 enables local real-time correction. |
amend_flag | amend_flag() -> int | Returns the correction mode. |
set_use_cz_pattern | set_use_cz_pattern(use_cz_pattern: bool) -> None | Sets crosstalk noise suppression. |
use_cz_pattern | use_cz_pattern() -> bool | Returns the crosstalk noise suppression setting. |
The existing setters (set_amend, set_mapping, set_optimization, set_point_label, set_specified_block, set_is_prob_counts, set_custom_option) remain available.
QCloudOptions.print() prints the current settings:
is_prob_counts: true
amend_flag: 1
use_cz_pattern: false
mapping: true
optimization: true
point_label: 1Example
import os
from pyqpanda3.core import CZ, H, QProg, measure
from pyqpanda3.qcloud import QCloudOptions, QCloudService
from pyqpanda3.transpilation import Transpiler, decompose
from pyqpanda3.visualization import draw_time_scheduling
service = QCloudService(os.environ["QPANDA_QCLOUD_API_KEY"])
backend = service.backend(os.environ.get("QPANDA_QCLOUD_BACKEND", "WK_C180_2"))
chip_info = backend.chip_info()
chip_backend = backend.chip_backend([0, 10])
prog = QProg()
prog << H(0) << CZ(0, 1) << measure(0, 0) << measure(1, 1)
decomposed = decompose(prog, ["U3", "CZ"])
transpiled = Transpiler().transpile(decomposed, chip_backend, {}, 2, "fidelity")
instruction = transpiled.to_instruction(
chip_backend,
offset=1,
is_scheduling=True,
compensate_pulse=False,
)
figures = draw_time_scheduling(instruction, backend=chip_backend, output="plotly")
options = QCloudOptions()
options.set_mapping(False)
options.set_optimization(False)
options.set_amend(False)
options.set_specified_block([0, 10])
job = backend.run_instruction([instruction], 1000, options)
print(chip_backend.basic_gates)
print(chip_backend.single_gate_timing, chip_backend.double_gate_timing)
print(type(figures).__name__)
print(job.job_id())Example output shape:
['RPhi', 'CZ']
25 40
Figure
JOB_IDNotes
chip_info().get_chip_backend()is the explicit path from cloud calibration data to the local transpiler APIs. The returnedChipBackendcarries topology, fidelity, compensation, and timing data used bytranspile(),to_instruction(is_scheduling=True), and schedule visualization.- The optional
options=None/ default-QPU run overloads are part of the 0.4.0 QCloud workflow documented from the current source bindings. - In pyqpanda3 0.4.0,
QCloudOptions()defaults are:mapping=True,optimization=True,amend=True,prob_counts=True,point_label=1,specified_block=[]. - Since 0.5.0,
QCloudOptions.get_custom_option(name)returns the stored value's actual type (int/float/str/bool); previously only theintoverload was reachable from Python. The setters (set_amend,set_mapping,set_optimization,set_point_label,set_specified_block,set_is_prob_counts,set_custom_option) andhas_custom_optionare unchanged from 0.4.x. - Since 0.5.1,
QCloudOptionssupports keyword construction and addsamend_flag(0/1/3) anduse_cz_pattern;print()outputsamend_flag/use_cz_patternand no longer printsamend. QCloudService.best_qubit_blocks(chip_id, qubit_num, label=1, qubit_block_num=1)andQCloudBackend.best_qubit_blocks(qubit_num, label=1, qubit_block_num=1)are both exposed in the 0.4.0 source. To pin physical qubits manually, useQCloudOptions.set_specified_block([...])after inspectingChipInfo.available_qubits()andChipInfo.get_chip_topology().