Inspect every control value changed by discretization¶
Validate an Analog program against a public mock target, then apply a named grid policy and inspect the numeric changes. Complete parameter projection and physical units. Use the installed environment.
The input amplitude is 0.8004 rad/us, detuning is −0.3004 rad/us and both durations are 0.2004 us. These small offsets are deliberate: they make the difference between a permitted continuous value and a grid-aligned value visible.
Validate first, then inspect the transformation¶
"""Keep validation and discretization as independent compiler stages.
Validation checks semantic and visible Target constraints. Discretization then
quantizes supported fields under an explicit policy and records original value,
target value, error, unit, and object path without claiming hardware preflight.
"""
from __future__ import annotations
import json
from cascaqit import AHSProgram, AtomRegister, MockNeutralAtomTarget, Waveform
def main() -> None:
"""Validate and discretize one waveform against a public mock target."""
target = MockNeutralAtomTarget.v0_1()
program = (
AHSProgram(
AtomRegister.line(count=1, spacing=5.0),
program_id="lesson.compiler.discretization",
)
.drive(
rabi=Waveform.constant(0.8004, duration=0.2004),
detuning=Waveform.constant(-0.3004, duration=0.2004),
phase=0.0,
)
.measure()
)
validated = program.validate(target, shots=16)
discretized, report = validated.discretize(target, policy="nearest")
payload = {
"track": "compiler_engineer",
"level": "advanced",
"lesson": "validation_discretization",
"facts": {
"validation_errors": [
item.code for item in validated.diagnostics if item.severity == "error"
],
"policy": report.policy,
"changed": report.original_program_hash != report.discretized_program_hash,
"field_changes": [item.to_dict() for item in report.field_reports],
"field_paths": [item.path for item in report.field_reports],
"lifecycle": discretized.program_ir.lifecycle_state,
"hardware_preflight_performed": False,
},
"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/compiler_engineer/04_advanced_validation_discretization_en.py
Validation checks the program and the target constraints visible to this public SDK. Discretization applies a grid policy to supported fields and returns a new program together with a report. A passing validation does not mean every value already lies on the grid.
{
"boundaries": {
"cloud_execution": false,
"credentials_loaded": false,
"hardware_execution": false,
"network_accessed": false
},
"facts": {
"changed": true,
"field_changes": [
{
"absolute_error": 0.0004,
"discretized_value": 0.8,
"original_value": 0.8004,
"path": "hamiltonian.terms.rabi.values[0]",
"unit": "rad/us"
},
{
"absolute_error": 0.0004,
"discretized_value": 0.2,
"original_value": 0.2004,
"path": "hamiltonian.terms.rabi.duration",
"unit": "us"
},
{
"absolute_error": 0.0004,
"discretized_value": -0.3,
"original_value": -0.3004,
"path": "hamiltonian.terms.detuning.values[0]",
"unit": "rad/us"
},
{
"absolute_error": 0.0004,
"discretized_value": 0.2,
"original_value": 0.2004,
"path": "hamiltonian.terms.detuning.duration",
"unit": "us"
}
],
"field_paths": [
"hamiltonian.terms.rabi.values[0]",
"hamiltonian.terms.rabi.duration",
"hamiltonian.terms.detuning.values[0]",
"hamiltonian.terms.detuning.duration"
],
"hardware_preflight_performed": false,
"lifecycle": "discretized",
"policy": "nearest",
"validation_errors": []
},
"lesson": "validation_discretization",
"level": "advanced",
"track": "compiler_engineer"
}
Under nearest, the amplitude becomes 0.8, detuning becomes −0.3, and each duration becomes 0.2, in its original unit. Each absolute change is 0.0004. Four fields change because Rabi and detuning each carry a duration; do not mistake those two entries for two successive time intervals.
field_changes supplies the original value, new value, absolute error, unit and path. The changed program hash records that the transformation altered the input. Neither the hash nor the discretized lifecycle label proves the transformation is acceptable for your experiment; inspect the report and any diagnostics.
Here absolute_error measures a control-value change. It is not an integration error, a shot standard error, a gate infidelity or a bound on the final quantum-state error. To assess physical impact, execute the intended original and transformed controls under comparable simulation settings and compare the relevant observable.
Try alternative policies¶
- Apply
floor. What happens to the negative detuning? - Apply
ceil. Which durations and amplitude values change upward? - Apply
strict. Does the API quietly round the values, or should the caller inspect diagnostics?
For this mock grid, floor gives amplitude 0.8, detuning −0.301 and duration 0.2. Flooring a negative number moves it toward a more negative grid point. ceil gives 0.801, −0.3 and 0.201. strict keeps off-grid values and reports DISCRETIZATION_STRICT_GRID_MISMATCH; it does not silently turn them into the nearest grid values. An empty field_reports list in that case is not proof of success.
The target is a public mock specification. Passing these checks does not establish current device calibration, private hardware preflight or a production pulse schedule. The validation request uses 16 shots as an input constraint; no measurements occur in this lesson. See validation and discretization, then reference compilation to follow the transformed input into its compiled records.