qlauncher.problems#

All problems together

Submodules:

Subpackages:

Summary#

__all__ Classes:

EC

Class for exact cover problem.

GraphColoring

Class for Graph Coloring Problem which is a combinatorial problem involving assigning labels to vertices of the graph such that no two adjacent vertices share the same label.

JSSP

Class for Job Shop Scheduling Problem.

Knapsack

Class for 0/1 Knapsack Problem.

MaxCut

Class for MaxCut Problem.

Problem

Abstract class for defining Problems.

QATM

Abstract class for defining Problems.

TSP

Traveling Salesman Problem (TSP) definition.

TabularML

VertexCover

Class for the Vertex Cover problem which is a combinatorial problem involving choosing a subset of graph vertices such that each edge of the graph has at least one vertex in the chosen subset.

Reference#

class qlauncher.problems.EC(instance: list[set[int]], instance_name: str = 'unnamed')[source]#

Bases: Problem

Class for exact cover problem.

The exact cover problem is a combinatorial optimization problem that involves finding a subset of a given set of elements such that the subset covers all elements and the number of elements in the subset is minimized. The class contains an instance of the problem, so it can be passed into QLauncher.

Attributes:

onehot (str): The one-hot encoding used for the problem. instance (any): The instance of the problem. instance_name (str | None): The name of the instance. instance_path (str): The path to the instance file.

classmethod from_file(path: str, **kwargs) EC[source]#
static from_preset(instance_name: Literal['micro', 'default'], **kwargs) EC[source]#
static generate_ec_instance(n: int, m: int, p: float = 0.5, **kwargs) EC[source]#
get_mixer_hamiltonian(amount_of_rings: int | None = None) Equation[source]#

generates mixer hamiltonian

to_hamiltonian(onehot: Literal['exact', 'quadratic'] = 'exact') Hamiltonian[source]#
to_qubo() QUBO[source]#
visualize(marked: str | None = None) None[source]#
class qlauncher.problems.GraphColoring(instance: Graph, num_colors: int, instance_name: str = 'unnamed')[source]#

Bases: Problem

Class for Graph Coloring Problem which is a combinatorial problem involving assigning labels to vertices of the graph such that no two adjacent vertices share the same label.

instance#

The graph for which the coloring problem is to be solved.

Type:

nx.Graph

classmethod from_file(path: str) Problem[source]#
static from_preset(instance_name: Literal['default', 'small'], **kwargs) GraphColoring[source]#
static generate_graph_coloring_instance(num_vertices: int, edge_probability: int, num_colors: int) GraphColoring[source]#
static randomly_choose_a_graph(num_colors: int) GraphColoring[source]#
property setup: dict#
to_bqm() BQM[source]#

Returns BQM

to_hamiltonian(constraints_weight: float = 1, costs_weight: float = 1) Hamiltonian[source]#
to_qubo() QUBO[source]#
visualize(solution: list[int] | None = None) None[source]#
class qlauncher.problems.JSSP(max_time: int, instance: dict[str, list[tuple[str, int]]], instance_name: str = 'unnamed', optimization_problem: bool = False)[source]#

Bases: Problem

Class for Job Shop Scheduling Problem.

This class represents Job Shop Scheduling Problem (JSSP) which is a combinatorial optimization problem that involves scheduling a set of jobs on a set of machines. Each job consists of a sequence of operations that must be performed on different machines. The objective is to find a schedule that minimizes the makespan, i.e., the total time required to complete all jobs. The class contains an instance of the problem, so it can be passed into QLauncher.

max_time#

The maximum time for the scheduling problem.

Type:

int

onehot#

The one-hot encoding method to be used.

Type:

str

optimization_problem#

Flag indicating whether the problem is an optimization problem or a decision problem.

Type:

bool

results#

Dictionary to store the results of the problem instance.

Type:

dict

classmethod from_file(path: str, **kwargs) JSSP[source]#
static from_preset(instance_name: Literal['default'], **kwargs) JSSP[source]#
property setup: dict#
to_bqm(lagrange_one_hot: float = 1, lagrange_precedence: float = 2, lagrange_share: float = 5) BQM[source]#
to_hamiltonian(lagrange_one_hot: float = 1, lagrange_precedence: float = 2, lagrange_share: float = 5, onehot: Literal['exact', 'quadratic'] = 'exact') Hamiltonian[source]#
class qlauncher.problems.Knapsack(values: Sequence[int], weights: Sequence[int], capacity: int, instance_name: str = 'unnamed')[source]#

Bases: Problem

Class for 0/1 Knapsack Problem.

This class represents the 0/1 Knapsack problem: maximize the total value of chosen items subject to a capacity constraint on total weight. The class wraps a concrete instance and can be passed into QLauncher.

static from_preset(instance_name: Literal['default', 'small'], **kwargs) Knapsack[source]#
to_bqm(penalty_weight: float = 2.0, value_weight: float = 1.0) BQM[source]#

Returns BQM for Knapsack problem.

class qlauncher.problems.MaxCut(instance: Graph, instance_name: str = 'unnamed')[source]#

Bases: Problem

Class for MaxCut Problem.

This class represents MaxCut Problem which is a combinatorial optimization problem that involves partitioning the vertices of a graph into two sets such that the number of edges between the two sets is maximized. The class contains an instance of the problem, so it can be passed into QLauncher.

Parameters:

instance (nx.Graph) – The graph instance representing the problem.

static from_preset(instance_name: Literal['default'], **kwargs) MaxCut[source]#
static generate_maxcut_instance(num_vertices: int, edge_probability: float) MaxCut[source]#
property setup: dict#
to_hamiltonian() Hamiltonian[source]#
to_qubo() QUBO[source]#
visualize(bitstring: str | None = None) None[source]#
class qlauncher.problems.Problem(instance: Any, instance_name: str = 'unnamed')[source]#

Bases: object

Abstract class for defining Problems.

variant#

The variant of the problem. The default variant is “Optimization”.

Type:

str

path#

The path to the problem.

Type:

str | None

name#

The name of the problem.

Type:

str

instance_name#

The name of the instance.

Type:

str

instance#

An instance of the problem.

Type:

any

analyze_result(result) Any[source]#

Analyzes the result.

Parameters:

result – The result.

classmethod from_file(path: str) Problem[source]#
static from_preset(instance_name, **kwargs) Problem[source]#
read_result(exp, log_path)[source]#

Reads a result from a file.

Parameters:
  • exp – The experiment.

  • log_path – The path to the log file.

Returns:

The result.

to(problem_type: type[Model]) Model[source]#
class qlauncher.problems.QATM(cm: ndarray, aircrafts: DataFrame, onehot: Literal['exact', 'quadratic', 'xor'] = 'exact', optimization: bool = False)[source]#

Bases: Problem

analyze_result(result: dict) dict[str, ndarray][source]#

Analyzes the result in terms of collisions and violations of onehot constraint.

Parameters:

result (dict) – A dictionary where keys are bitstrings and values are probabilities.

Returns:

A dictionary containing collisions, onehot violations, and changes as ndarrays.

Return type:

dict

classmethod from_file(path: str, instance_name: str = 'QATM', onehot: Literal['exact', 'quadratic', 'xor'] = 'exact', optimization: bool = False) QATM[source]#
static from_preset(instance_name: Literal['rcp-3'], **kwargs) QATM[source]#
get_initial_state() QuantumCircuit[source]#
get_mixer_hamiltonian() Equation[source]#
to_hamiltonian(onehot: Literal['exact', 'quadratic', 'xor'] = None) Hamiltonian[source]#
class qlauncher.problems.TSP(instance: Graph, instance_name: str = 'unnamed')[source]#

Bases: Problem

Traveling Salesman Problem (TSP) definition.

static from_preset(instance_name: Literal['default'] = 'default', **kwargs) TSP[source]#

Generate TSP instance from a preset name.

Parameters:
  • instance_name (str) – Name of the preset instance

  • quadratic (bool, optional) – Whether to use quadratic constraints. Defaults to False

Returns:

TSP instance

Return type:

TSP

static generate_tsp_instance(num_vertices: int, min_distance: float = 1.0, max_distance: float = 10.0, **kwargs) TSP[source]#

Generate a random TSP instance.

Parameters:
  • num_vertices (int) – Number of vertices in the graph

  • min_distance (float, optional) – Minimum distance between vertices. Defaults to 1.0

  • max_distance (float, optional) – Maximum distance between vertices. Defaults to 10.0

  • quadratic (bool, optional) – Whether to use quadratic constraints. Defaults to False

Returns:

TSP instance

Return type:

TSP

property setup: dict#
to_hamiltonian(constraints_weight: int = 5, costs_weight: int = 1, return_to_start: bool = True, onehot: Literal['exact', 'quadratic'] = 'exact') Hamiltonian[source]#

Creates a Hamiltonian for the TSP problem.

Parameters:
  • problem – TSP problem instance

  • quadratic – Whether to encode as a quadratic Hamiltonian

  • constraints_weight (int) – Weight of the constraints in the Hamiltonian

  • costs_weight (int) – Weight of the costs in the Hamiltonian

Returns:

Hamiltonian representing the TSP problem

Return type:

np.ndarray

to_qubo(constraints_weight: int = 5, costs_weight: int = 1, return_to_start: bool = True) QUBO[source]#
visualize(solution: SamplingMinimumEigensolverResult | str | list[int] | None = None) None[source]#
class qlauncher.problems.TabularML(X: ndarray, y: ndarray | None = None, instance_name: str = 'unnamed')[source]#

Bases: Model

static from_preset(instance_name: Literal['default'], **kwargs) TabularML[source]#
visualize() None[source]#
class qlauncher.problems.VertexCover(instance: Graph, instance_name: str = 'unnamed')[source]#

Bases: Problem

Class for the Vertex Cover problem which is a combinatorial problem involving choosing a subset of graph vertices such that each edge of the graph has at least one vertex in the chosen subset.

instance#

The graph for which the coloring problem is to be solved.

Type:

nx.Graph

static from_preset(instance_name: Literal['default'], **kwargs) VertexCover[source]#
static generate_vertex_cover_instance(num_vertices: int, edge_probability: int) VertexCover[source]#
to_bqm(constraint_weight: int = 5, cost_weight: int = 1) BQM[source]#
visualize(solution: list[int] | None = None) None[source]#