problems.n_minus_1.quantum_annealing

Quantum Annealing based solution to the N-1 problem.

class tno.quantum.problems.n_minus_1.quantum_annealing.DecodedResult(graph)[source]

Bases: object

The DecodedResult class.

DecodedResult stores results decoded from a sample of a sampleset.

__eq__(other)[source]

Simple equals function.

Two DecodedResults are equal if if the underlying graph after performing the switches are equal.

Return type:

bool

__hash__()[source]

Simple hash function.

Creates a hash of the graph using the Return Weisfeiler Lehman (WL) graph hash together with simple hashes of the turned on/off edges.

Return type:

int

__init__(graph)[source]

Init of the DecodedResult class.

Parameters:

graph (Graph) – Graph of a power network. If the DecodedResult is used store decoded results containing loadflow constraints, then graph should have nodes and edges as described in QABasedNMinusOneSolver.

__repr__()[source]

String representation of the result.

Return type:

str

Returns:

String representation of the class, using the class name, number of nodes, turned on edges and turned off edges.

Example

"DecodedResult[n_nodes=4, turned_on=[(3,4)], turned_off=[(2,3)]]".

draw(ax=None, *, check_loadflow=False)[source]

Create image of the result.

Parameters:
  • check_loadflow (bool) – Wether to check if the graph is loadflow complient. Default is False.

  • ax (Optional[Axes]) – Axes to plot on. If None create a new figure with a new ax.

Return type:

None

get_k()[source]

Get k, which is the number of switches.

Return type:

int

Returns:

Integer value representing the number of switched used in this solution. In this case, the failing edge is not interpreted as a switch.

class tno.quantum.problems.n_minus_1.quantum_annealing.FactoryArguments(n_layers, K, L, M)[source]

Bases: BaseArguments

Arguments for the N-Minus-1 QUBO factory.

K: int

Number of auxiliary variables to use for encoding real part of the potential.

L: int

Number of auxiliary variables to use for encoding imaginary part of the potential.

M: int

Number of auxiliary variables to use for encoding the current.

__init__(n_layers, K, L, M)[source]

Init of the NMOFactory.

Parameters:
  • n_layers (Optional[SupportsInt]) – Number of layers to use for the tree formulation.

  • K (SupportsInt) – Number of auxiliary variables to use or encoding the real part of the potential.

  • L (SupportsInt) – Number of auxiliary variables to use or encoding the imaginary part of the potential.

  • M (SupportsInt) – Number of auxiliary variables to use for encoding the current.

classmethod default()[source]

Create a default instance of the factory arguments.

The defaults sets the following values:

  • Number of layers: n_layers = None,

  • Number of auxiliary variables real part potential: K = 6,

  • Number of auxiliary variables imag part potential: L = 5,

  • Number of auxiliary variables current: M = 5,

Return type:

Self

n_layers: int | None

Number of layers to use for the tree formulation.

class tno.quantum.problems.n_minus_1.quantum_annealing.QABasedNMinusOneSolver(graph, failing_edge)[source]

Bases: object

Quantum Annealing Based N-1 Solver.

The Quantum Annealing solver performs the following steps:

  1. Transform the problem to a Binary Quadratic Model, also known as a Quadratic Unconstrained Optimization (QUBO).

  2. Approximate a solution to this problem with the given QUBO solver. This solver can be a quantum solver.

  3. Decode the bitstrings returned by the solver.

__init__(graph, failing_edge)[source]

Init of the QABasedNMinusOneSolver.

Parameters:
  • graph (Graph) – Network represented as a graph. Each node should have the following attributes: type, U_ref, P_low, P_high, U_min and U_max. Each edge should have the following attributes: active, edge_idx, Z and I_max.

  • failing_edge (tuple[Hashable, Hashable]) – The edge that will fail in the scenario.

run(factory_arguments=None, qubo_arguments=None, solver_config=None)[source]

Run the algorithm.

Parameters:
Return type:

ResultsOverview

Returns:

Result overview object containing the results.

class tno.quantum.problems.n_minus_1.quantum_annealing.QUBOArguments(penalty_depth, penalty_connectivity, penalty_loadflow, penalty_auxvar, p_extra)[source]

Bases: BaseArguments

Arguments for the N-1 QUBO.

__init__(penalty_depth, penalty_connectivity, penalty_loadflow, penalty_auxvar, p_extra)[source]

Arguments to configure the QUBO formulation for the N-1 problem.

Parameters:
  • penalty_depth (SupportsFloat) – Absolute penalty scaling to use for the depth penalty.

  • penalty_connectivity (SupportsFloat) – Absolute penalty scaling to use for the connectivity penalty.

  • penalty_loadflow (SupportsFloat) – Absolute penalty scaling to use for the loadflow penalty.

  • penalty_auxvar (SupportsFloat) – Absolute penalty scaling to use for the penalty governing the behavior of the auxiliary variables.

  • p_extra (SupportsFloat) – Extra power to add to each node for numerical stability.

classmethod default()[source]

Create a default instance of the QUBO arguments.

The defaults sets the following absolute penalty scaling values:

  • Depth penalty: penalty_depth = 400,

  • Connectivity: penalty_connectivity = 100,

  • Loadflow: penalty_loadflow = 2,

  • Auxiliary variables: penalty_auxvar = 1,

  • Numerical stability power: p_extra = 1,

Return type:

Self

p_extra: float

Extra power to add to each node for numerical stability.

penalty_auxvar: float

Absolute penalty scaling to use for the penalty governing the behaviour of the auxiliary variables.

penalty_connectivity: float

Absolute penalty scaling to use for the connectivity penalty.

penalty_depth: float

Absolute penalty scaling to use for the depth penalty.

penalty_loadflow: float

Absolute penalty scaling to use for the loadflow penalty.

class tno.quantum.problems.n_minus_1.quantum_annealing.ResultsOverview[source]

Bases: object

ResultsOverview.

The ResultsOverview class is a collection of DecodedResult.

__init__()[source]

Init of the ResultsOverview class.

__iter__()[source]

Iterate over the results and counts, starting with the smallest k.

Return type:

Iterator[tuple[DecodedResult, int]]

__len__()[source]

Number of unique results in the overview.

Return type:

int

__repr__()[source]

Make a string representation of the ResultsOverview.

Return type:

str

add_result(result, count=1)[source]

Add a result to the overview.

Parameters:
  • result (DecodedResult) – Result to add to the overview.

  • count (int) – Number of times the result was seen. Default is 1.

Return type:

Self

Returns:

Self.