Parameter Precision#
Precision Conversion Requirements#
In practical modeling problems, a QUBO formulation is often obtained first, which must then be converted into an Ising model to be executed on physical quantum hardware. The QUBO model needs to be transformed into an Ising model for real physical computation.
In actual computation, the coefficient bit-width is constrained by the physical hardware and can only take limited ranges.
1.CIM hardware only supports 8-bit signed integer range [-128, 127].
2.Users must ensure that the converted Ising matrix satisfies this precision requirement.
3.The conversion logic provided is for reference. Users can apply methods more suitable for their own matrices.
QUBO to Ising Transformation#
This section describes how to transform QUBO into Ising to illustrate how dynamic range limits the QUBO matrix.
The QUBO model is defined as follows:
Before computation, it must be converted into an Ising matrix. Let ,
QUBO variables satisfy , allowing linear terms to be represented by diagonal elements. In the Ising model,
, so this representation is not applicable.
The linear terms are converted into quadratic terms by introducing auxiliary spin variables , whose values 1 and -1 correspond to the original two solution states. Thus, introducing auxiliary variables preserves equivalence with the original problem.
Constant terms are recorded separately and added back into the final Hamiltonian calculation.
Example:
After the transformation, it becomes
Methods for reducing precision in kaiwuSDK#
kaiwuSDK provides two methods for reducing parameter precision: perform_precision_adaption_mutate and perform_precision_adaption_split. The mutate method preserves the optimal solution while modifying the matrix, but the extent of precision reduction depends on the matrix’s reducible space. The split method can adjust a matrix to any precision level; however, the number of bits grows rapidly with the magnitude of the required precision reduction.
perform_precision_adaption_mutate#
1 Dynamic Range#
1.1 Definitions Related to QUBO Matrix
Definition Let Q be a QUBO matrix. indicates that the optimal solution space of Q is included in that of Q’.
Definition denotes rounding each element of Q to the nearest integer.
1.2 Dynamic Range Definitions
Definition denotes a coefficient matrix.
denotes the maximum distance between elements of X.
denotes the minimum non-zero distance between elements of X.
defines the dynamic range of X.
Proposition If , then for any
,
.
The definition of dynamic range applies to both QUBO and Ising matrices. By reducing dynamic range, the required coefficient precision is reduced.
Since the final computation is performed on the Ising matrix, dynamic-range reduction is applied directly to the Ising matrix in kaiwuSDK.
2 Example Usage#
import kaiwu as kw
import numpy as np
mat0 = np.array([[0, -20, 0, 40, 1.1],
[0, 0, 12240, 1, 120],
[0, 0, 0, 0, -10240],
[0, 0, 0, 0, 2.05],
[0, 0, 0, 0, 0]])
mutated_mat = kw.preprocess.perform_precision_adaption_mutate(mat0)
print(mutated_mat)
perform_precision_adaption_split#
1 Parameter Precision#
Currently, Ising matrix coefficients are stored as fixed-point values with only 8-bit precision. Therefore, if the ratio between the maximum and minimum coefficients exceeds , large coefficients must be split.
This is achieved by replacing a single bit with multiple equivalent bits whose equality is enforced via constraint terms, thereby reducing the magnitude of each coefficient.
With QUBO-to-Ising transformation commonly applied, the splitting method converts into:
For example, for , if the coefficient ratio must not exceed 150, the polynomial is modified as:
.
2 Example Usage#
import kaiwu as kw
import numpy as np
mat = np.array([[0, -15,0, 40],
[-15,0, 0, 1],
[0, 0, 0, 0],
[40, 1, 0, 0]])
splitted_ret, last_idx = kw.preprocess.perform_precision_adaption_split(mat, 4)
print(splitted_ret)
The default min_increment computed value is 1. With precision set to 4 bits, values range from −7 to 7.
The program outputs the converted matrix as follows:
As shown, red arrows indicate the correspondence before and after splitting. Values in blue boxes are penalty terms that enforce equality of newly introduced variables. This allows reducing parameter precision while preserving the original optimal solution.
Precision reduction is controlled by parameters such as param_bit, min_increment, penalty, and round_to_increment.
Matrix values must be integer multiples of min_increment, which defaults to the smallest positive difference.
round_to_increment adjusts elements to ensure the sum of split values equals the original value. For example, splitting 15 into 7.5 + 7.5 would round to 8 + 8; with reduce_error=True, it becomes 7 + 8.
splitted_ret2, last_idx2 = kw.preprocess.perform_precision_adaption_split(mat, 4, min_increment=3, round_to_increment=True)
print(splitted_ret2)
Result:
[[ 0. 21. -6. 0. 3. 12.]
[21. 0. -9. 0. 12. 12.]
[-6. -9. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0.]
[ 3. 12. 0. 0. 0. 21.]
[12. 12. 0. 0. 21. 0.]]
After solving the reduced-precision matrix, the original matrix solution can be recovered using restore_split_solution.
worker = kw.classical.SimulatedAnnealingOptimizer()
output = worker.solve(splitted_ret)
sol = output[0]
org_sol = kw.preprocess.restore_split_solution(sol, last_idx)
print(org_sol)
Result:
[-1. 1. -1. -1.]
PrecisionReducer#
To support iterative computation using the CIM quantum solver, PrecisionReducer is provided based on the decorator design pattern. Users can wrap CIMOptimizer with PrecisionReducer and pass the PrecisionReducer into the Solver as the optimizer. For details, refer to:
More methods for precision handling#
See also