# From QUBO matrix to Ising model in Qiskit

Given a general QUBO matrix $$Q$$ for a quadratic minimization problem, is there a Qiskit way to obtain the Pauli gate list or the Ising model for it? A related question is Qiskit: Taking a QUBO matrix into qubit_op', but it seems to be about a graph related model. The solution given there is also for a particular graph metric for the stable_set.

I prepared this code based on Qiskit tutorial. Firstly, lets prepare a QUBO task.

# Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *

print(qubo.export_as_lp_string())


Now, we have a QUBO task and you can convert it to Ising Hamiltonian with this code:

#converting QUBO task to Ising Hamiltonian for simulation on quantum computer
operator, offset = qubo.to_ising()

#operator - unitary operator representing the simulated Hamiltonian
#offset - used after solution on QC to convert objective function value to the proper one

print(operator)



This code converts Ising Hamiltonian to QUBO:

#conversion of Ising Hamiltonian to QUBO
`
Given a matrix $$H$$, you can decompose to $$H$$ into Pauli operators
$$H = \sum_{i} h_{i}H_i = \sum_{i_1,i_2,\cdots, i_n} a_{i_1,i_2,\cdots, i_n}(\sigma_{i_1} \otimes \sigma_{i_2} \otimes \cdots \otimes \sigma_{i_n})$$ where $$\sigma_{i_j}\in {I,X,Y,Z}$$ and $$a_{i_1,i_2,\cdots, i_n} = \dfrac{1}{2^n} Tr( (\sigma_{i_1} \otimes \sigma_{i_2} \otimes \cdots \otimes \sigma_{i_n}) \cdot H) = \dfrac{1}{2^n} Tr( H_i \cdot H)$$