wy_qcos.engine.qubo package

Submodules

wy_qcos.engine.qubo.qubo_precision module

wy_qcos.engine.qubo.qubo_precision.find_matrix_gcd(matrix)

Find the greatest common divisor (GCD) of all non-zero elements.

参数:

matrix -- a 2D numpy array

返回:

the GCD of all non-zero elements in the matrix

wy_qcos.engine.qubo.qubo_precision.scale_to_integer_matrix(matrix)

Scale matrix to interger matrix.

参数:

matrix -- a 2D numpy array

返回:

a scaled integer matrix.

wy_qcos.engine.qubo.qubo_precision.check_matrix(matrix)

Check matrix is square array or not.

Check if the input 2D list is a square array (i.e., the number of rows and columns are equal).

参数:

matrix -- list(list())

返回:

True if valid, False otherwise error_msg: str

返回类型:

bool

wy_qcos.engine.qubo.qubo_precision.check_qubo_matrix_bit_width(qubo_matrix, param_bit)

Check qubo matrix bit width.

参数:
  • qubo_matrix (np.ndarray) -- qubo matrix to be checked

  • param_bit (int) -- param bit width

返回:

success of failed (bool), error message list.

wy_qcos.engine.qubo.qubo_precision.qubo_matrix_to_ising_matrix(qubo_matrix)

Convert QUBO matrix to ising matrix.

tip: Ising matrix is added a variable to the diagonal.

参数:

qubo_matrix (np.ndarray) -- qubo matrix

返回:

ising matrix

返回类型:

np.ndarray

wy_qcos.engine.qubo.qubo_precision.ising_matrix_to_qubo_matrix(ising_matrix)

Convert ising matrix to QUBO matrix.

参数:

ising_matrix (np.ndarray) -- ising matrix

返回:

QUBO matrix

返回类型:

np.ndarray

wy_qcos.engine.qubo.qubo_precision.get_spins_num(mat, max_value)

Get the number of spin variables.

Obtain the number of spin variables after the matrix is reduced in precision.

参数:
  • mat (np.ndarray) -- upper triangular matrix

  • max_value (int) -- max value of the matrix

返回:

spin variables list

返回类型:

list

wy_qcos.engine.qubo.qubo_precision.precision_reduction(ising_matrix, param_bit)

Precision reduction algorithm.

参数:
  • ising_matrix (np.ndarray) -- ising matrix

  • param_bit (int) -- Parameters indicating matrix accuracy

返回:

np.ndarray: new ising matrix list: last index int: total_spins_num

返回类型:

tuple

wy_qcos.engine.qubo.qubo_precision.process_qubo_solution(job_results, last_idx, qubo_matrix)

Process qubo solution.

参数:
  • job_results (dict) -- job_results returned by the driver

  • last_idx (list) -- last index returned by precsion reduction

  • qubo_matrix (np.array) -- QUBO matrix

返回:

new job_results

返回类型:

dict

wy_qcos.engine.qubo.subqubo module

class wy_qcos.engine.qubo.subqubo.SubQUBOMultiSolution(N_I=20, N_E=1, N_S=5, qubo_matrix=None, subqubo_size=100, max_converged_num=3)

基类:object

Implement subQUBO with multiple solution instances.

参数:

qubo_matrix (ndarray | None)

set_subqubo_size(subqubo_size)

Set subqubo size.

参数:

subqubo_size (int) -- new_subqubo_size

set_qubo_matrix(qubo_matrix)

Set QUBO matrix and convert to binary quadratic model.

参数:

qubo_matrix (np.ndarray) -- n-by-n QUBO-matrix

get_max_converged_num()

Get max converged num.

返回:

converged num

返回类型:

max_converged_num (int)

init_instance_pool()

Initialize the instance solutions pool include N_I solution.

返回:

solution pool

返回类型:

np.ndarray

find_best_solution(pool)

Find the best solution.

返回:

best solution np.ndarray: ascending order index

返回类型:

QUBOSolution

optimize_solution_pool(pool)

Optimize all solutions.

参数:

pool (list) -- list of solutions

返回:

list of optimized solutions.

返回类型:

list

construct_subqubo(n_s_solutions_pool)

Construct subqubo matrix from N_S solutions pool.

参数:

n_s_solutions_pool (list) -- N_S solutions pool

返回:

subqubo matrix np.ndarray: temporary solution in QUBO-matrix np.ndarray: extracted index

返回类型:

np.ndarray

merge_solution(tmp_solution, sub_solution, extracted_index)

Merge the sub solution into the tentative solution.

参数:
  • tmp_solution (QUBOSolution) -- tmp solution

  • sub_solution (np.ndarray) -- sub solution to be merged

  • extracted_index (list) -- extracted index of sub solution

返回:

merged solution

返回类型:

QUBOSolution

create_sub_solution_pools(solution_pool)

Create N_E sub-solution pools.

Create N_E sub-solution pools from the main solution pool, each formed by randomly selecting N_S solution instances.

参数:

solution_pool (list) -- solutions pool.

返回:

A list of N_E sub solution pools.

返回类型:

list

update_solution_pool(solution_pool, new_solutions)

Update the solution pool.

Update the solution pool by replacing the worst solutions with the best solution.

参数:
  • solution_pool (list) -- The current solution pool.

  • new_solutions (list) -- A list of new solutions to be added to the pool.

返回:

The best solution found in the updated pool. list: The updated solution pool.

返回类型:

QUBOSolution

wy_qcos.engine.qubo.tabu module

class wy_qcos.engine.qubo.tabu.QUBOSolution(solution, energy)

基类:object

Solution information.

This class contains:
  • solution (np.ndarray): n-sized solution composed of binary variables

  • energy (float): energy value obtained from QUBO(QuadraticProgram) of all term

参数:
  • solution (ndarray)

  • energy (float)

solution: ndarray
energy: float
classmethod calculate_energy(qubo, solution=None)

Calculate the energy from the QUBO-matrix & solution.

参数:
  • qubo (np.ndarray) -- n-by-n QUBO-matrix

  • solution (np.ndarray) -- n-sized solution composed of binary variables

返回:

Energy value.

返回类型:

float

class wy_qcos.engine.qubo.tabu.TabuSearch(qubo, init_solution=None)

基类:object

tabu search algorithm.

参数:
  • qubo (ndarray)

  • init_solution (ndarray | None)

update_tabu(index)

Update tabu table.

参数:

index (int) -- index of the variable

get_best_solution()

Obtain the optimal solution and Hamiltonian.

返回:

(best_solution, best_energy).

返回类型:

tuple

update_impact()

Compute and update the flip cost vector for each bit.

返回:

Change in objective value for

flipping each bit.

返回类型:

np.ndarray

find_best_flip()

Looking for the best flip.

返回:

index of the best flip

返回类型:

int

solve()

Solve the problem.

返回:

solution.

返回类型:

np.ndarray

determine_tabu_tenure()

Determine an appropriate tabu tenure based on problem size.

返回:

Tabu tenure.

返回类型:

int

Module contents