uniqc.compile.policy module

Per-platform submission policy: basis gates, language, compile dispatch.

This module is the single source of truth for “what does each cloud platform expect from a circuit before we hand it over”. Two pieces of policy live here:

  • PLATFORM_BASIS_GATES — the gate set we compile to before submission on each platform. For superconducting CN-style platforms (originq, quafu, quark) we use ("CZ", "SX", "RZ"). For IBM we defer to the backend’s advertised basis_gates (read from BackendInfo.extra ["basis_gates"]) and fall back to qiskit’s defaults if missing.

  • PLATFORM_SUBMIT_LANGUAGE — the IR string each adapter actually sends on the wire. OriginIR for OriginQ (pyqpanda3 path) and QASM2 for qiskit / quafu / quark.

The high-level helper compile_for_backend() glues the policy and the existing uniqc.compile.compile() function together, returning a circuit that is ready to submit (gate set + language) for the given backend.

uniqc.compile.policy.PLATFORM_BASIS_GATES: dict[str, tuple[str, ...]] = {'dummy': (), 'ibm': (), 'originq': ('CZ', 'SX', 'RZ'), 'quafu': ('CZ', 'SX', 'RZ'), 'quark': ('CZ', 'SX', 'RZ')}

Default basis gate set per platform (uppercase, OriginIR/qiskit names). Empty tuple means “no opinion — defer to the backend’s own advertisement”.

uniqc.compile.policy.PLATFORM_SUBMIT_LANGUAGE: dict[str, str] = {'dummy': 'OriginIR', 'ibm': 'QASM2', 'originq': 'OriginIR', 'quafu': 'QASM2', 'quark': 'QASM2'}

The wire language each adapter submits with.

uniqc.compile.policy.compile_for_backend(circuit, backend_info, *, level=2, output_format='circuit')[source]

Compile circuit so that it satisfies backend_info.

For originq, quafu and quark this lowers the circuit to cz + sx + rz (the supported superconducting basis) using the existing uniqc.compile.compile() pipeline. For ibm, the basis set is read from the backend’s advertised basis_gates (typically ("CZ", "SX", "RZ", "X") plus IBM-specific extras). When the backend does not advertise a basis set, qiskit’s default is used.

Parameters:
  • circuit – The input circuit. Accepts a uniqc.Circuit, an OriginIR string, an OpenQASM 2.0 string, or a qiskit.QuantumCircuit. Normalization is delegated to uniqc.compile.compile().

  • backend_info (BackendInfo) – Target backend descriptor. Topology and num_qubits are used by the routing pass.

  • level (int) – Optimization level (0–3) for the underlying transpiler. Default: 2.

  • output_format (str) – "circuit" (default) returns a Circuit; "originir" returns an OriginIR string; "qasm" returns an OpenQASM 2.0 string; "auto" matches the detected input format.

Returns:

The compiled circuit in the requested format.

Return type:

Circuit | str

uniqc.compile.policy.resolve_basis_gates(backend, backend_info=None)[source]

Return the basis gate set we will compile to before submission.

Resolution order:
  1. Platform default from PLATFORM_BASIS_GATES if non-empty.

  2. backend_info.extra["basis_gates"] if non-empty.

  3. Empty tuple — caller should treat this as “skip compile”.

Parameters:
Return type:

tuple[str, …]

uniqc.compile.policy.resolve_submit_language(backend)[source]

Return the wire language for backend or None if unknown.

Parameters:

backend (str | BackendInfo)

Return type:

str | None