Skip to content

QCloudService ​

QCloudService is the entry point for OriginQ cloud backends.

QCloudService ​

python
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 url explicitly overrides the domain encoded in the key, for testing or private deployments; in the 0.5.1 bindings url no longer has a default value.

Methods ​

MethodSignatureDescription
setup_loggingsetup_logging(output: LogOutput = LogOutput.CONSOLE, file_path: str = "") -> NoneConfigure client-side logging.
backendsbackends() -> dict[str, bool]List backend names and availability flags.
best_qubit_blocksbest_qubit_blocks(chip_id: str, qubit_num: int, label: int = 1, qubit_block_num: int = 1) -> BestQubitBlocksQuery optimal qubit blocks for a chip.
backendbackend(backend_name: str) -> QCloudBackendOpen 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 / MethodTypeDescription
chip_idstrChip identifier used for the query.
qubit_numintNumber of qubits requested for each block.
labelintOptimization label used for block selection.
qubit_block_numintNumber of qubit blocks requested.
qubit_blockslist[list[int]]Selected qubit blocks, each a list of physical qubit indices.
size()intNumber of selected blocks (len(blocks)).
empty()boolWhether 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__.

python
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))           # 2

QCloudBackend ​

QCloudBackend represents one selected cloud backend.

python
QCloudBackend(backend_name: str)

Common execution overloads ​

python
run(
    prog: QProg,
    shots: int,
    model: QCloudNoiseModel = QCloudNoiseModel(),
    batch_id: str = "",
    task_form: int = 4,
) -> QCloudJob
python
run(
    prog: QProg,
    shots: int,
    options: QCloudOptions,
    enable_binary_encoding: bool = False,
    batch_id: str = "",
    task_form: int = 4,
) -> QCloudJob
python
run(
    progs: list[QProg],
    shots: int,
    options: QCloudOptions,
    enable_binary_encoding: bool = False,
    batch_id: str = "",
    task_form: int = 4,
) -> QCloudJob

Other 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 ​

python
run_instruction(
    instruction: str | list[str],
    shots: int,
    options: QCloudOptions,
    batch_id: str = "",
    task_form: int = 4,
) -> QCloudJob

Submit instruction JSON directly instead of sending QProg.

Chip and layout helpers ​

MethodSignatureDescription
chip_infochip_info() -> ChipInfoRaw chip metadata.
chip_backendchip_backend(qubits: list[int] = []) -> ChipBackendConvenience wrapper for chip_info().get_chip_backend().
best_qubit_blocksbest_qubit_blocks(qubit_num: int, label: int = 1, qubit_block_num: int = 1) -> BestQubitBlocksQuery optimal qubit blocks for this backend.
namename() -> strBackend 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 ​

python
expval_hamiltonian(
    prog: QProg,
    hamiltonian: Hamiltonian,
    shots: int = 1000,
    noise_model: QCloudNoiseModel = QCloudNoiseModel(),
) -> float
python
expval_hamiltonian(
    prog: QProg,
    hamiltonian: Hamiltonian,
    options: QCloudOptions,
) -> float

Equivalent overloads exist for expval_pauli_operator(...).

ChipInfo ​

ChipInfo exposes hardware calibration data and can materialize a ChipBackend.

MethodDescription
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.

python
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] = [],
)
MethodSignatureDescription
set_amend_flagset_amend_flag(amend_flag: int) -> None0 disables correction, 1 enables global sampling correction, 3 enables local real-time correction.
amend_flagamend_flag() -> intReturns the correction mode.
set_use_cz_patternset_use_cz_pattern(use_cz_pattern: bool) -> NoneSets crosstalk noise suppression.
use_cz_patternuse_cz_pattern() -> boolReturns 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:

text
is_prob_counts: true
amend_flag: 1
use_cz_pattern: false
mapping: true
optimization: true
point_label: 1

Example ​

python
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:

text
['RPhi', 'CZ']
25 40
Figure
JOB_ID

Notes ​

See Also ​

Released under the MIT License.