Run and identify every point in a scan¶
Scan a single RY(θ) gate at θ = -0.5, 0, 0.5 rad. A Digital-only Hybrid program keeps the prediction simple while exercising the same scan interface used for Digital-Analog experiments. Complete shared parameters first and use the installed environment.
Starting from |0⟩, P(1) = sin²(θ/2). Predict approximately 0.061209, 0, and 0.061209. Equal probabilities at opposite angles are expected in this measurement basis; they do not imply that the quantum states are identical.
Submit explicit points¶
"""Execute a deterministic parameter sweep through one Hybrid Backend path.
``ParameterScan`` expands explicit points in stable order. Every child keeps
its own bind set, seed, result, and status while the aggregate records worker
and resource planning facts.
"""
from __future__ import annotations
import json
from cascaqit import Circuit, HybridProgram, LocalBackend
from cascaqit.parameters import ParameterScan
def main() -> None:
"""Run three rotation values and inspect child results in scan order."""
circuit = Circuit(1, program_id="lesson.hybrid.sweep.digital")
theta = circuit.parameter("theta", lower_bound=-1.0, upper_bound=1.0)
circuit.ry(theta, 0)
program = (
HybridProgram("lesson.hybrid.sweep").digital("rotate", circuit).measure_all()
)
scan = ParameterScan.explicit(
scan_id="lesson.hybrid.sweep.points",
points=tuple({"theta": value} for value in (-0.5, 0.0, 0.5)),
)
job = LocalBackend(seed=103).run(
program, sweep=scan, shots=16, failure_policy="continue_on_error"
)
result = job.result()
if job.status().state != "completed" or any(
item.state != "completed" or item.result is None for item in result.items
):
raise RuntimeError("The parameter sweep did not complete every point.")
payload = {
"track": "hybrid_researcher",
"level": "applied",
"lesson": "parameter_sweep",
"facts": {
"job_state": job.status().state,
"item_states": [item.state for item in result.items],
"theta_values": [item.bind_set.values["theta"] for item in result.items],
"counts_totals": [
sum((item.result.counts if item.result else {}).values())
for item in result.items
],
"probabilities": [
item.result.probabilities for item in result.items if item.result
],
"selected_workers": result.metadata["scan_resource_plan"][
"selected_workers"
],
},
"boundaries": {
"hardware_execution": False,
"cloud_execution": False,
"network_accessed": False,
"credentials_loaded": False,
},
}
print(json.dumps(payload, sort_keys=True))
if __name__ == "__main__":
main()
python3 examples/user/tracks/hybrid_researcher/03_applied_parameter_sweep_en.py
ParameterScan.explicit() retains the supplied point order. shots=16 applies to each point, so this scan requests 48 shots in total. The scan derives a seed for each index from the root seed. Changing worker scheduling does not change which seed belongs to a point; changing point order can change that association.
The program contains no Analog evolution, so time integration is not applicable. You do not need an artificial Analog block or a time-step setting to execute this scan.
{
"boundaries": {
"cloud_execution": false,
"credentials_loaded": false,
"hardware_execution": false,
"network_accessed": false
},
"facts": {
"counts_totals": [
16,
16,
16
],
"item_states": [
"completed",
"completed",
"completed"
],
"job_state": "completed",
"probabilities": [
{
"0": 0.9387912809451864,
"1": 0.061208719054813655
},
{
"0": 1.0,
"1": 0.0
},
{
"0": 0.9387912809451864,
"1": 0.061208719054813655
}
],
"selected_workers": 3,
"theta_values": [
-0.5,
0.0,
0.5
]
},
"lesson": "parameter_sweep",
"level": "applied",
"track": "hybrid_researcher"
}
Check the aggregate job_state and all item_states before using the data. This example requires every point to complete and raises an error otherwise. Read each item.bind_set.values alongside its result. Worker completion order is not a parameter label. selected_workers can vary with available CPU and memory; three points do not guarantee three concurrent workers.
The probability arrays should match the prediction. The count totals should be [16, 16, 16], but the number of 1 samples at the two nonzero angles need not match each other. Keep missing results distinct from measured zeros: a failed point with no result is not a successful run that measured zero excitations.
Separate invalid input from execution failure¶
The scan validates its point bindings before starting child execution. An out-of-range value, unknown parameter or other invalid binding rejects submission with LOCAL_HYBRID_SCAN_INVALID. continue_on_error cannot turn invalid input into a runnable scan.
That policy applies to failures during child execution. Successful and failed child outcomes remain available; some successes and some failures give an aggregate partially_completed state. If every child fails, the scan is failed. With fail_fast, execution proceeds in index order and later unstarted points are marked not_run after a failure. Inspect the child diagnostics to understand the failing point before rerunning it.
Check ordering and sampling¶
- Reverse the three input points. Predict the returned parameter order and probabilities.
- Change the final value to
1.5, beyond the declared upper bound. Doescontinue_on_errorpreserve the first two results? - Raise shots from 16 to 4096. Which output should become less noisy, and how many shots are now requested?
Check your reasoning
The order becomes [0.5, 0.0, -0.5]; the Z probabilities have the same values because the function is even. Seeds follow indexes, so do not demand unchanged counts for the moved points. The invalid 1.5 rejects the whole scan before child execution; there are no first-two-point results from that submission. With 4096 shots per point, the total is 12288. Sample frequencies fluctuate less around the same state probabilities; extra shots do not improve the underlying state evolution.
See Hybrid parameters for grid scans and binding details. Continue with physical noise to distinguish a changed state from sampling fluctuations.