hamiltonian_variational_ansatz
class qiskit.circuit.library.hamiltonian_variational_ansatz(hamiltonian, reps=1, insert_barriers=False, name='HVA', parameter_prefix='t')
Bases:
Construct a Hamiltonian variational ansatz.
For a Hamiltonian where the terms consist of only commuting Paulis, but the terms do not commute among each other , the Hamiltonian variational ansatz (HVA) is
where the exponentials 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 . 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")
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")
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
References
[1] D. Wecker et al. Progress towards practical quantum variational algorithms (2015)
[2] R. Wiersema et al. Exploring entanglement and optimization within the Hamiltonian
Variational Ansatz (2020) arXiv:2008.02941