scan_pca¶
- scan_pca(program, *, samples, center=None, grid_shape=(41, 41), components_ids=(0, 1), offset=(-1.0, 1.0), span_x=None, span_y=None, reporter=None)[source]¶
Evaluate a 2D scan in PCA score space (orqviz-compatible layout).
Fits
sklearn.decomposition.PCAonsamples, builds a rectangular grid in the selected principal-component scores (default PC0 vs PC1), maps each grid point throughinverse_transforminto full parameter space, and evaluates the program’s cost function in one batch.A typical choice for
samplesis the optimization trajectory:samples = np.vstack(program.param_history(mode="best_per_iteration"))
When using
program.viz.scan_pca(), samples are collected automatically if omitted.When
span_xandspan_yare both omitted, axis limits match orqvizPCAobject._get_endpoints_from_pca: min/max of the projectedsampleson each selected component, plusoffsetapplied to the low and high ends.- Parameters:
program (
_SupportsVizScan) – Variational program to scan.samples (
TypeAliasType) – Rows are parameter vectors used to fit PCA; shape(n_samples, n_params).center (
TypeAliasType|None) – Optional anchor in parameter space. IfNone, the scan plane is the standard PCA affine subspace through the sample mean (orqviz default). If provided (e.g.program.best_params), each reconstructed point is shifted by(center - sample_mean)so the same PC directions pass throughcenter.grid_shape (
tuple[int,int]) –(n_x, n_y)grid resolution in score space; both ≥ 2.components_ids (
tuple[int,int]) – Which PCA components form the scan axes (default(0, 1)).n_componentsis set tomax(components_ids) + 1.offset (
float|tuple[float,float]) – Extra padding on score-axis limits when using automatic spans. A scalarabecomes(-|a|, |a|)on each end (orqviz rule).span_x (
tuple[float,float] |None) – If given together withspan_y, fixed PC0 score range (bypasses automatic endpoints).span_y (
tuple[float,float] |None) – Fixed PC1 score range; must be set ifspan_xis set.reporter (
ProgressReporter|None) – Seescan_1d().
- Returns:
Grid in PCA score coordinates, loss values, full parameter sets, sklearn PC directions for the chosen indices, explained variance ratios, and projected
samplesscores for plotting.- Return type:
- Raises:
TypeError – If
programis not a supported variational program.NotImplementedError – If
programis anIterativeQAOAinstance.ValueError – If shapes, ranks,
grid_shape, or span arguments are invalid.