Reduce QUBO/Hamiltonian (exact reduction). Source code for the paper 'FastHare: Fast Hamiltonian Reduction for Large-scale Quantum Annealing, IEEE Int. Conf. on Quantum Computing and Engineering (QCE) 2022' https://arxiv.org/abs/2205.05004
Project description
Python Interface for FastHare
Installation
This requires Python 3.10+ and c++14
- clone this repository
pip install ./python_package
Test
import fasthare as m
print("Using list of triples i, j, h_ij")
sk_ising = [(0, 1, -3)] # SK Hamiltonian: min - (-3 * x_0 * x_1 )
print(m.fasthare_reduction(sk_ising) )
# Or using the exp3.net in the "tests" folder
print("Reading triples i, j, h_ij from file")
rh, map, sign, time = m.fasthare_reduction(file ="exp3.net",alpha=0.2)
print(rh)
print(map)
print(sign)
print(time)
Output
Using list of triples i, j, h_ij
([], [0, 0], [1, -1], 1.9e-05)
Reading triples i, j, h_ij from file
[(0, 1, 1.0), (0, 2, 3.0), (1, 2, 3.0)]
[2, 2, 2, 2, 2, 2, 2, 1, 0, 1]
[1, -1, -1, 1, 1, 1, 1, 1, 1, 1]
4.4e-05
The output is a tuple of <compressed_hamiltonian, spin_mapping, spin_sign, running_time>.
- compressed_hamiltonian: triples of (i, j, h_ij)
- spin_mapping: The ith entry indicates which spin in the compressed hamiltonian that the ith spin in the input Hamiltonian mapped to
- spin_sign: The ith entry is -1 if the ith spin in the input Hamiltonian is reversed (+1 otherwise)
- running_time: run time in second(s)
Explanation for the output of "exp3.net"
exp3.net | compressed_hamiltonian | spin_mapping/spin_sign |
---|---|---|
10 14 0 1 -2 0 2 -4 1 2 2 1 3 -1 2 3 -6 3 4 3 4 5 4 4 6 4 5 6 -1 6 7 3 6 8 3 7 8 -1 7 9 3 8 9 2 |
[(0, 1, 1.0), (0, 2, 3.0), (1, 2, 3.0)] |
[2, 2, 2, 2, 2, 2, 2, 1, 0, 1] [1, -1, -1, 1, 1, 1, 1, 1, 1, 1] |
... | Compressed into the below Hamiltonian with |
The qubits |
Remark: Since the version 1.0, the Hamiltonian will be compressed into a single node.