Skip to content

Preserve each scan point's status and result

Submit two RX angles through one scan Job, then build a result table that keeps parameter identity, status and measurements together. Complete results and diagnostics and Hybrid parameter scans. Use the installed environment.

The angles are 0.1 and 0.7 rad. Starting from |0⟩, RX gives P(1)=sin²(θ/2), approximately 0.002498 and 0.117579. With eight shots per point, either point can produce no 1 samples. That is different from a failed point that produced no result.

Read the aggregate and then the children

"""Observe aggregate and child lifecycle facts for a local Sweep Job.

The aggregate Job owns ordered child outcomes and partial-failure policy. Each
child keeps a typed bind set and result; consumers should not infer success by
looking only at the aggregate counts array.
"""

from __future__ import annotations

import json

from cascaqit import Circuit, HybridProgram, LocalBackend
from cascaqit.parameters import ParameterScan


def main() -> None:
    """Submit two scan points and inspect aggregate lifecycle fields."""
    circuit = Circuit(1, program_id="lesson.platform.sweep.digital")
    theta = circuit.parameter("theta", lower_bound=0.0, upper_bound=1.0)
    circuit.rx(theta, 0)
    program = (
        HybridProgram("lesson.platform.sweep").digital("rotate", circuit).measure_all()
    )
    scan = ParameterScan.explicit(
        scan_id="lesson.platform.sweep.points",
        points=({"theta": 0.1}, {"theta": 0.7}),
    )
    job = LocalBackend(seed=403).run(program, sweep=scan, shots=8)
    queued = job.status()
    result = job.result()
    completed = job.status()

    if completed.state != "completed" or any(
        item.state != "completed" or item.result is None for item in result.items
    ):
        raise RuntimeError("The platform scan did not complete every point.")

    payload = {
        "track": "sdk_platform_engineer",
        "level": "applied",
        "lesson": "sweep_job",
        "facts": {
            "queued_state": queued.state,
            "completed_state": completed.state,
            "total_items": completed.total_items,
            "item_states": [item.state for item in result.items],
            "theta_values": [item.bind_set.values["theta"] for item in result.items],
            "probabilities": [
                item.result.probabilities for item in result.items if item.result
            ],
            "bind_hashes_valid": all(
                item.bind_set.verify_hash() for item in result.items
            ),
            "counts_totals": [
                sum((item.result.counts if item.result else {}).values())
                for item in result.items
            ],
        },
        "boundaries": {
            "hardware_execution": False,
            "cloud_execution": False,
            "network_accessed": False,
            "credentials_loaded": False,
        },
    }
    print(json.dumps(payload, sort_keys=True))


if __name__ == "__main__":
    main()

Download the full script

python3 examples/user/tracks/sdk_platform_engineer/03_applied_sweep_job_en.py

The program contains only Digital operations inside a Hybrid container. The scan needs no Analog integrator. Like a single local Job, it is initially queued and starts executing when result() is requested.

{
  "boundaries": {
    "cloud_execution": false,
    "credentials_loaded": false,
    "hardware_execution": false,
    "network_accessed": false
  },
  "facts": {
    "bind_hashes_valid": true,
    "completed_state": "completed",
    "counts_totals": [
      8,
      8
    ],
    "item_states": [
      "completed",
      "completed"
    ],
    "probabilities": [
      {
        "0": 0.997502082639013,
        "1": 0.002497917360987117
      },
      {
        "0": 0.8824210936422442,
        "1": 0.11757890635775578
      }
    ],
    "queued_state": "queued",
    "theta_values": [
      0.1,
      0.7
    ],
    "total_items": 2
  },
  "lesson": "sweep_job",
  "level": "applied",
  "track": "sdk_platform_engineer"
}

The example requires aggregate completion and two completed child results; otherwise it raises an error. Expected count totals are [8, 8], for 16 samples across the scan. total_items=2 describes workload size, not shot count or execution success by itself.

For each row, retain scan_index, bind_set, state, result reference and diagnostics. A verified binding hash checks the consistency of the recorded binding. The probability prediction provides a separate numerical check that the binding has the intended effect.

Point outcome How an application should represent it
Completed, no 1 samples A valid measured zero frequency, with its shot count.
Failed, no result Missing measurement data with the failure diagnostics.
not_run after an earlier failure Work that has not been attempted; do not call it a zero or a failed execution.
Completed alongside failed points Keep the successful result and label the aggregate's partial completion.

continue_on_error retains runtime failures while allowing other points to run. fail_fast stops starting points after the first failure. Neither policy bypasses scan-wide binding validation before execution. Partial completion should be visible in an exported table or plot; silently dropping failed rows can bias an analysis.

Exercise the data handling

  1. Change the first angle to zero. Should a completed all-zero sample disappear from a chart?
  2. Reverse the points. Which field tells you which angle produced a result?
  3. Set the second angle to 1.1, beyond its declared bound, and try continue_on_error. Do you receive a successful first point?

At zero angle the first point is a valid result with P(1)=0; retain it. The reversed scan preserves the new input order, and bind_set.values identifies the angle. The invalid 1.1 rejects submission with LOCAL_HYBRID_SCAN_INVALID before child execution, so this request has no first-point measurement. Runtime failure policy is a later decision.

See job lifecycle for the common status vocabulary. Continue with local recovery to preserve job definitions and results beyond the current Python object.

中文版

SDK 1.0.8a · `8b227bff`