Skip to main contentIBM Quantum Documentation

hamiltonian_variational_ansatz

class qiskit.circuit.library.hamiltonian_variational_ansatz(hamiltonian, reps=1, insert_barriers=False, name='HVA', parameter_prefix='t')

GitHub

Bases:

Construct a Hamiltonian variational ansatz.

For a Hamiltonian H=k=1KHkH = \sum_{k=1}^K H_k where the terms HkH_k consist of only commuting Paulis, but the terms do not commute among each other [Hk,Hk]0[H_k, H_{k'}] \neq 0, the Hamiltonian variational ansatz (HVA) is

r=1R(k=K1eiθk,rHk)\prod_{r=1}^{R} \left( \prod_{k=K}^1 e^{-i\theta_{k, r} H_k} \right)

where the exponentials exp(iθHk)exp(-i\theta H_k) are implemented exactly [1, 2]. Note that this differs from evolved_operator_ansatz(), where no assumptions on the structure of the operators are done.

The Hamiltonian can be passed as SparsePauliOp, in which case we split the Hamiltonian into commuting terms {Hk}k\{H_k\}_k. Note, that this may not be optimal and if the minimal set of commuting terms is known it can be passed as sequence into this function.

Examples

A single operator will be split into commuting terms automatically:

from qiskit.quantum_info import SparsePauliOp
from qiskit.circuit.library import hamiltonian_variational_ansatz
 
# this Hamiltonian will be split into the two terms [ZZI, IZZ] and [IXI]
hamiltonian = SparsePauliOp(["ZZI", "IZZ", "IXI"])
ansatz = hamiltonian_variational_ansatz(hamiltonian, reps=2)
ansatz.draw("mpl")
../_images/qiskit-circuit-library-hamiltonian_variational_ansatz-1.png

Alternatively, we can directly provide the terms:

from qiskit.quantum_info import SparsePauliOp
from qiskit.circuit.library import hamiltonian_variational_ansatz
 
zz = SparsePauliOp(["ZZI", "IZZ"])
x = SparsePauliOp(["IXI"])
ansatz = hamiltonian_variational_ansatz([zz, x], reps=2)
ansatz.draw("mpl")
../_images/qiskit-circuit-library-hamiltonian_variational_ansatz-2.png

Parameters

  • hamiltonian (SparsePauliOp | Sequence[SparsePauliOp]) – The Hamiltonian to evolve. If given as single operator, it will be split into commuting terms. If a sequence of SparsePauliOp, then it is assumed that each element consists of commuting terms, but the elements do not commute among each other.
  • reps (int) – The number of times to repeat the evolved operators.
  • insert_barriers (bool) – Whether to insert barriers in between each evolution.
  • name (str) – The name of the circuit.
  • parameter_prefix (str) – Set the names of the circuit parameters. If a string, the same prefix will be used for each parameters. Can also be a list to specify a prefix per operator.

Return type

QuantumCircuit

References

[1] D. Wecker et al. Progress towards practical quantum variational algorithms (2015)

Phys Rev A 92, 042303

[2] R. Wiersema et al. Exploring entanglement and optimization within the Hamiltonian

Variational Ansatz (2020) arXiv:2008.02941

Was this page helpful?
Report a bug or request content on GitHub.