stanza.routines.builtins.dqd_search.grid_search

Grid-based search utilities for DQD discovery.

Module Contents

Classes

NameDescription
SearchSquareResults from measuring a single grid square.

Functions

NameDescription
generate_grid_cornersGenerate grid of square corners covering the voltage space.
generate_diagonal_sweepGenerate diagonal line through a square.
generate_2d_sweepGenerate 2D grid sweep over a square.
get_neighboring_squaresGet neighboring grid square indices.
get_grid_distanceCalculate Manhattan distance between two grid squares.
select_weighted_by_scoreSelect candidate weighted by proximity and score of successful squares.
select_next_squareSelect next grid square using hierarchical priority strategy.

Data

HIGH_SCORE_THRESHOLD GRID_SQUARE_MULTIPLIER DISTANCE_DECAY_FACTOR

API

1stanza.routines.builtins.dqd_search.grid_search.HIGH_SCORE_THRESHOLD: float

Value: 1.5

1stanza.routines.builtins.dqd_search.grid_search.GRID_SQUARE_MULTIPLIER: float

Value: None

1stanza.routines.builtins.dqd_search.grid_search.DISTANCE_DECAY_FACTOR: float

Value: 1.0

1class stanza.routines.builtins.dqd_search.grid_search.SearchSquare

Results from measuring a single grid square.

1grid_idx: int

Value: None

1current_trace_currents: numpy.typing.NDArray[numpy.float64]

Value: None

1current_trace_voltages: numpy.typing.NDArray[numpy.float64]

Value: None

1current_trace_score: float

Value: None

1current_trace_classification: bool

Value: None

1low_res_csd_currents: numpy.typing.NDArray[numpy.float64] | None

Value: None

1low_res_csd_voltages: numpy.typing.NDArray[numpy.float64] | None

Value: None

1low_res_csd_score: float

Value: None

1low_res_csd_classification: bool

Value: None

1high_res_csd_currents: numpy.typing.NDArray[numpy.float64] | None

Value: None

1high_res_csd_voltages: numpy.typing.NDArray[numpy.float64] | None

Value: None

1high_res_csd_score: float

Value: None

1high_res_csd_classification: bool

Value: None

1total_score: float
1is_dqd: bool
1to_list(arr: numpy.typing.NDArray[numpy.float64] | None) -> list[float] | None
1to_dict() -> dict[str, typing.Any]

Convert to JSON-serializable dictionary.

1stanza.routines.builtins.dqd_search.grid_search.generate_grid_corners(
2 plunger_x_bounds: tuple[float, float],
3 plunger_y_bounds: tuple[float, float],
4 square_size: float
5) -> tuple[numpy.typing.NDArray[numpy.float64], int, int]

Generate grid of square corners covering the voltage space.

Parameters:

plunger_x_bounds
tuple[float, float]

(min, max) voltage bounds for X plunger

plunger_y_bounds
tuple[float, float]

(min, max) voltage bounds for Y plunger

square_size
float

Side length of each grid square

Returns:

Tuple of (grid_corners, n_x, n_y) where:

  • grid_corners: (n_x*n_y, 2) array of bottom-left corners
  • n_x: Number of squares in X direction
  • n_y: Number of squares in Y direction
1stanza.routines.builtins.dqd_search.grid_search.generate_diagonal_sweep(
2 corner: numpy.typing.NDArray[numpy.float64],
3 size: float,
4 num_points: int
5) -> numpy.typing.NDArray[numpy.float64]

Generate diagonal line through a square.

Parameters:

corner
numpy.typing.NDArray[numpy.float64]

(2,) bottom-left corner coordinates

size
float

Square side length

num_points
int

Number of points along diagonal

Returns:

(num_points, 2) array of voltage coordinates

1stanza.routines.builtins.dqd_search.grid_search.generate_2d_sweep(
2 corner: numpy.typing.NDArray[numpy.float64],
3 size: float,
4 num_points: int
5) -> numpy.typing.NDArray[numpy.float64]

Generate 2D grid sweep over a square.

Parameters:

corner
numpy.typing.NDArray[numpy.float64]

(2,) bottom-left corner coordinates

size
float

Square side length

num_points
int

Number of points per axis

Returns:

(num_points, num_points, 2) array of voltage coordinates

1stanza.routines.builtins.dqd_search.grid_search.get_neighboring_squares(
2 grid_idx: int,
3 n_x: int,
4 n_y: int,
5 include_diagonals: bool = False
6) -> list[int]

Get neighboring grid square indices.

Parameters:

grid_idx
int

Linear index of current grid square

n_x
int

Number of grid squares in X direction

n_y
int

Number of grid squares in Y direction

include_diagonals
boolDefaults to False

Use 8-connected (True) vs 4-connected (False)

Returns:

List of neighboring grid square indices

1stanza.routines.builtins.dqd_search.grid_search.get_grid_distance(
2 idx1: int,
3 idx2: int,
4 n_x: int,
5 n_y: int
6) -> int

Calculate Manhattan distance between two grid squares.

Manhattan distance is the sum of horizontal and vertical distances, appropriate for grid topology where moves are limited to cardinal directions.

Parameters:

idx1
int

Linear index of first square

idx2
int

Linear index of second square

n_x
int

Number of squares in X direction

n_y
int

Number of squares in Y direction

Returns:

Manhattan distance (sum of horizontal and vertical distance)

1stanza.routines.builtins.dqd_search.grid_search.select_weighted_by_score(
2 candidates: list[int],
3 successful_squares: list[stanza.routines.builtins.dqd_search.grid_search.SearchSquare],
4 n_x: int,
5 n_y: int,
6 distance_decay: float = DISTANCE_DECAY_FACTOR
7) -> int

Select candidate weighted by proximity and score of successful squares.

DQDs cluster in voltage space, so weight candidates by nearby high scores.

Parameters:

candidates
list[int]

Candidate square indices

successful_squares
list[stanza.routines.builtins.dqd_search.grid_search.SearchSquare]

High-scoring squares

n_x
int

Number of squares in X direction

n_y
int

Number of squares in Y direction

distance_decay
floatDefaults to DISTANCE_DECAY_FACTOR

Weight decay per unit distance

Returns:

Selected square index

1stanza.routines.builtins.dqd_search.grid_search.select_next_square(
2 visited: list[stanza.routines.builtins.dqd_search.grid_search.SearchSquare],
3 dqd_squares: list[stanza.routines.builtins.dqd_search.grid_search.SearchSquare],
4 n_x: int,
5 n_y: int,
6 include_diagonals: bool,
7 score_threshold: float = HIGH_SCORE_THRESHOLD
8) -> int | None

Select next grid square using hierarchical priority strategy.

Priority: DQD neighbors > high-score neighbors > random unvisited.

Parameters:

visited
list[stanza.routines.builtins.dqd_search.grid_search.SearchSquare]

Already-visited squares

dqd_squares
list[stanza.routines.builtins.dqd_search.grid_search.SearchSquare]

Confirmed DQD squares

n_x
int

Number of squares in X direction

n_y
int

Number of squares in Y direction

include_diagonals
bool

Use 8-connected vs 4-connected neighborhoods

score_threshold
floatDefaults to HIGH_SCORE_THRESHOLD

Minimum score for high-scoring squares

Returns:

Grid index to sample next, or None if all visited