uniqc.backend_adapter.task.normalizers module

Platform-specific result normalizers.

This module provides functions to convert platform-specific result formats into the unified UnifiedResult format. Each platform (OriginQ, Quark, IBM) has its own normalizer that handles the unique output format of that platform.

The normalizers are used by the adapter classes to ensure consistent result handling across all platforms.

Usage:

from uniqc.backend_adapter.task.normalizers import normalize_originq
from uniqc.backend_adapter.task.result_types import UnifiedResult

# Convert OriginQ result to unified format
unified = normalize_originq(originq_result, task_id="abc123")
uniqc.backend_adapter.task.normalizers.normalize_dummy(probs_list, task_id, shots=1000)[source]

Normalize local simulator probability output.

The local OriginIR simulator returns a list of probabilities indexed by computational basis state (little-endian).

Parameters:
  • probs_list – List of probabilities indexed by basis state.

  • task_id – Task identifier.

  • shots – Number of shots.

Returns:

UnifiedResult with probabilities converted to bitstrings.

Example

>>> probs = [0.5, 0.0, 0.0, 0.5]  # |00> and |11> each 50%
>>> result = normalize_dummy(probs, "task-3")
>>> print(result.probabilities)
{'00': 0.5, '11': 0.5}
uniqc.backend_adapter.task.normalizers.normalize_ibm(result_obj, task_id)[source]

Normalize IBM Quantum (Qiskit) Result format.

IBM returns a Qiskit Result object with:
  • get_counts(): Returns dict or list of dicts for measurement counts

  • to_dict(): Returns full result as dict with metadata

Parameters:
  • result_obj – Qiskit Result object.

  • task_id – Task identifier (Qiskit job ID).

Returns:

UnifiedResult with counts and probabilities.

Note

For batch jobs, this normalizes the first circuit result only. Use result_obj.get_counts() directly for batch results.

Example

>>> # result_obj is a qiskit Result
>>> unified = normalize_ibm(result_obj, "job-123")
>>> print(unified.counts)
{'0x0': 512, '0x3': 488}
uniqc.backend_adapter.task.normalizers.normalize_logicalqubit(raw, task_id, backend_name=None)[source]

Normalize an lqcloud (LogicalQubit) counts payload.

job.result().get_counts() returns qiskit-style big-endian keys ({"00": 503, ...}) where the rightmost character is c[0] — identical to the uniqc convention (platform_conventions.md §2.6), so no bit reversal is applied. Hex keys (0x...) are converted to a uniform-width binary form inferred from the largest observed outcome.

Parameters:
  • raw – Counts dict, or an object exposing get_counts().

  • task_id – Task identifier (lqcloud job id).

  • backend_name – Optional backend name.

Returns:

UnifiedResult with counts following the uniqc cbit convention.

uniqc.backend_adapter.task.normalizers.normalize_originq(raw, task_id, shots=1000, n_qubits=None)[source]

Normalize OriginQ Cloud result format.

OriginQ returns results either in the legacy probability format:

{'key': ['0x0', '0x1', ...], 'value': [0.5, 0.3, ...]}

where keys are hexadecimal bitstrings and values are probabilities, or as a plain counts dict:

{0: 100, 1: 200, 7: 50}   # int outcome -> shot count
{'0x0': 100, '0x1': 200}  # hex string outcome -> shot count
Parameters:
  • raw – Raw result dict from OriginQ Cloud API. Either the {"key": [...], "value": [...]} probability form or a flat counts dict mapping integer/hex/binary outcomes to shot counts.

  • task_id – Task identifier.

  • shots – Number of shots (default 1000). Ignored when raw is a counts dict (in which case the sum of counts is used).

  • n_qubits – Number of qubits in the source circuit. If None the width is inferred from the highest observed integer outcome via int.bit_length(), which is unsafe for sparse distributions where the most-significant qubits happen to read 0 (the resulting bitstrings will be shorter than the true register width). Passing the explicit n_qubits from circuit.qubit_num is strongly preferred and a UserWarning is emitted when it is omitted.

Returns:

UnifiedResult with normalized probabilities and counts.

Example

>>> raw = {'key': ['0x0', '0x3'], 'value': [0.5, 0.5]}
>>> result = normalize_originq(raw, "task-1", n_qubits=2)
>>> print(result.probabilities)
{'00': 0.5, '11': 0.5}
uniqc.backend_adapter.task.normalizers.normalize_tianyan(raw, task_id, backend_name=None)[source]

Normalize a TianYan (cqlib) experiment-result entry.

raw is one entry of data.experimentResultModelList from the TianYan result endpoint, carrying resultStatus (see tianyan_result_status_to_counts() for the layout), probability and experimentTaskId.

Parameters:
  • raw – Raw experiment-result entry dict.

  • task_id – Task identifier (cqlib query_id).

  • backend_name – Optional machine name (e.g. "tianyan176").

Returns:

UnifiedResult with counts following the uniqc cbit convention.

uniqc.backend_adapter.task.normalizers.tianyan_result_status_to_counts(result_status)[source]

Convert a cqlib (TianYan) resultStatus payload to a counts dict.

resultStatus is a list of rows: row 0 holds the measured-qubit labels in measurement order (the first entry corresponds to c[0]), and each subsequent row holds one shot’s bits in that same order.

uniqc convention (docs/source/1_basic_usage/platform_conventions.md §2.6): the rightmost bitstring character is c[0]. Each shot row is therefore reversed so the first-measured bit lands on the right.

Parameters:

result_status – Raw resultStatus value from the TianYan experiment-result response.

Returns:

Counts dict mapping bitstrings to shot counts. Empty when the payload carries no shot rows.