scan_1d¶
- scan_1d(program, *, center=None, direction=None, n_points=51, span=(-3.141592653589793, 3.141592653589793), normalize_directions=True, rng=None, reporter=None)[source]¶
One-dimensional loss-landscape scan for a variational program.
The scan is constructed by taking a center point in parameter space and a direction vector, then evaluating the program’s cost function at evenly spaced offsets along that line. Internally, the scan uses
_evaluate_cost_param_sets()directly, so it reuses the program’s normal batched evaluation path instead of going throughrun().Geometry matches the usual
orqviz1D pattern whenspanuses the default \((-\pi, \pi)\) andnormalize_directionsisFalse: each offset \(t\) maps tocenter + t * directionwith the direction norm affecting Euclidean step size. The defaultnormalize_directions=Truekeeps a unit direction sospanis measured along a normalized axis.- Parameters:
program (
_SupportsVizScan) – Variational program to scan.center (
TypeAliasType|None) – Flat parameter vector around which the scan is performed. If omitted, the scan centers onprogram.best_paramsfrom a previous optimization run.direction (
TypeAliasType|None) – Flat direction vector in parameter space. If omitted, a random direction is drawn (reproducible viarng).n_points (
int) – Number of sample points along the scan line. Must be at least 2.span (
tuple[float,float]) – Inclusive scalar offset range applied alongdirection(orqvizend_pointsdefault is \((-\pi, \pi)\)).normalize_directions (
bool) – IfTrue(default), non-zerodirectionis unit-normalized before buildingcenter + t * direction.rng (
Generator|int|None) – Optionalnumpy.random.Generatoror integer seed used whendirectionisNone.reporter (
ProgressReporter|None) – OptionalProgressReporter. When omitted, usesprogram.reporterif present, otherwiseLoggingProgressReporter. Start/finish messages are emitted around the single batched evaluation (same pattern asrun).
- Returns:
Object containing offsets, sampled loss values, the concrete parameter sets that were evaluated, and plotting helpers.
- Return type:
- Raises:
TypeError – If
programis not a supportedVariationalQuantumAlgorithm.NotImplementedError – If
programis anIterativeQAOAinstance.ValueError – If
centerordirectionhas the wrong shape, ifdirectionis zero, or ifn_pointsis invalid.