mqt.qecc.cococo.hill_climber

Hill Climbing with random restarts for Routing Layouts.

Classes

HillClimbing

Hill Climbing with random restarts for routing layouts.

Functions

save_to_file(path, data) → None

Safely saves data to a file.

Module Contents

save_to_file(path: str, data: Any) → None[source]

Safely saves data to a file.

class HillClimbing(max_restarts: int, max_iterations: int, circuit: list[tuple[int, int] | int], metric: str, t: int, custom_layout: list[list[mqt.qecc.cococo.types.pos] | networkx.Graph], use_dag: bool, valid_path: str, possible_factory_positions: list[mqt.qecc.cococo.types.pos] | None = None, num_factories: int | None = None, optimize_factories: bool = False, seed: int = 45)[source]

Hill Climbing with random restarts for routing layouts.

evaluate_solution(layout: dict[int | str, tuple[int, int] | list[tuple[int, int]]]) → int[source]

Evaluates the layout=solution according to self.metric.

gen_random_qubit_assignment() → dict[int | str, tuple[int, int] | list[tuple[int, int]]][source]

Yields a random qubit assignment given the data_qubit_locs.

gen_neighborhood(layout: dict[int | str, tuple[int, int] | list[tuple[int, int]]]) → list[dict[int | str, tuple[int, int] | list[tuple[int, int]]]][source]

Creates the Neighborhood of a given layout by going through each terminal pair and swapping their positions.

If there are no T gates, there will be l=len(terminal_pairs) elements in the neighborhood.

Parameters:

layout (dict) – qubit label assignment on the lattice. keys = qubit label, value = node label

Returns:

List of layouts constituting the neighborhood.

Return type:

list[dict]

single_hill_climbing(restart: int) → tuple[int, dict[int | str, tuple[int, int] | list[tuple[int, int]]], int, HistoryTemp][source]

Helper method for parallel execution of hill climbing restarts.

Parameters:

restart (int) – The restart index.

Returns:

Tuple of (restart index, best solution, best score, history for this restart)

run(prefix: str, suffix: str, parallel: bool, processes: int = 8) → tuple[dict[int | str, tuple[int, int] | list[tuple[int, int]]], int, int, dict[int, HistoryTemp]][source]

Executes the Hill Climbing algorithm with random restarts.

Parameters:
  • prefix (str) – prefix to add to the log file’s paths.

  • suffix (str) – suffix to add to the log file’s paths.

  • parallel (bool) – decides whether to use multiprocessing or not

  • processes (int) – number of processes (=number of available physical kernels)

Returns:

The best solution found. best_score: The score of the best solution.

Return type:

best_solution