Skip to content

Hamiltonian Variational Ansatz (HVA)

The Hamiltonian Variational Ansatz (HVA) is inspired by the quantum approximate optimization algorithm [1] , [2] .

Syntax

HVAParameters:

  • reps: int – Number of layers in the ansatz.

Example

Initialize the circuit to the Hartree-Fock state and then apply the HVA function.

qmod
{
  "functions": [
    {
      "name": "main",
      "param_decls": {},
      "port_declarations": {},
      "operand_declarations": {},
      "parameters": [],
      "body": [
        {
          "function": "molecule_hartree_fock",
          "params": {
            "molecule_problem": {
              "expr": "struct_literal(MoleculeProblem, mapping=FermionMapping.JORDAN_WIGNER, z2_symmetries=False, molecule=struct_literal(Molecule, atoms=[struct_literal(ChemistryAtom, element=Element.H, position=struct_literal(Position, x=0.0, y=0.0, z=0.0)), struct_literal(ChemistryAtom, element=Element.H, position=struct_literal(Position, x=0.0, y=0.0, z=0.735))],spin=1,charge=0),freeze_core=False,remove_orbitals=[])"
            }
          },
          "function_params": {
            "parameters": [],
            "input_decls": {},
            "output_decls": {}
          },
          "control_states": [],
          "inputs": {},
          "inouts": {},
          "outputs": {
            "qbv": {
              "name": "hf"
            }
          },
          "name": "molecule_hartree_fock_cs4id_dR8jZl",
          "operands": {}
        },
        {
          "function": "molecule_hva",
          "params": {
            "reps": {
              "expr": "3"
            },
            "molecule_problem": {
              "expr": "struct_literal(MoleculeProblem, mapping=FermionMapping.JORDAN_WIGNER,z2_symmetries=False,molecule=struct_literal(Molecule, atoms=[struct_literal(ChemistryAtom, element=Element.H,position=struct_literal(Position, x=0.0,y=0.0,z=0.0)),struct_literal(ChemistryAtom, element=Element.H,position=struct_literal(Position, x=0.0,y=0.0,z=0.735))],spin=1,charge=0),freeze_core=False,remove_orbitals=[])"
            }
          },
          "function_params": {
            "parameters": [],
            "input_decls": {},
            "output_decls": {}
          },
          "control_states": [],
          "inputs": {
            "qbv": {
              "name": "hf"
            }
          },
          "inouts": {},
          "outputs": {},
          "name": "molecule_hva_cs4id_BRVy8w",
          "operands": {}
        }
      ],
      "local_handles": [
        {
          "name": "hf"
        }
      ]
    }
  ],
  "types": [],
  "classical_functions": [
    {
      "name": "cmain",
      "param_decls": {},
      "body": [
        {
          "name": "vqe_result",
          "var_type": {
            "kind": "vqe_result"
          }
        },
        {
          "invoked_expression": {
            "function": "vqe",
            "params": {
              "hamiltonian": {
                "expr": "molecule_problem_to_hamiltonian(struct_literal(MoleculeProblem, mapping=FermionMapping.JORDAN_WIGNER,z2_symmetries=False,molecule=struct_literal(Molecule, atoms=[struct_literal(ChemistryAtom, element=Element.H,position=struct_literal(Position, x=0.0,y=0.0,z=0.0)),struct_literal(ChemistryAtom, element=Element.H,position=struct_literal(Position, x=0.0,y=0.0,z=0.735))],spin=1,charge=0),freeze_core=False,remove_orbitals=[]))"
              },
              "maximize": {
                "expr": "false"
              },
              "initial_point": {
                "expr": "[]"
              },
              "optimizer_name": {
                "expr": "Optimizer.COBYLA"
              },
              "max_iteration": {
                "expr": "30"
              },
              "tolerance": {
                "expr": "0.0"
              },
              "step_size": {
                "expr": "0.0"
              },
              "skip_compute_variance": {
                "expr": "false"
              },
              "alpha_cvar": {
                "expr": "1.0"
              }
            },
            "target_function": "main",
            "target_params": {}
          },
          "assigned_variable": "vqe_result"
        },
        {
          "name": "molecule_result",
          "var_type": {
            "kind": "struct_instance",
            "name": "MoleculeResult"
          }
        },
        {
          "invoked_expression": {
            "expr": "molecule_ground_state_solution_post_process(struct_literal(MoleculeProblem, mapping=FermionMapping.JORDAN_WIGNER,z2_symmetries=False,molecule=struct_literal(Molecule, atoms=[struct_literal(ChemistryAtom, element=Element.H,position=struct_literal(Position, x=0.0,y=0.0,z=0.0)),struct_literal(ChemistryAtom, element=Element.H,position=struct_literal(Position, x=0.0,y=0.0,z=0.735))],spin=1,charge=0),freeze_core=False,remove_orbitals=[]),vqe_result)"
          },
          "assigned_variable": "molecule_result"
        },
        {
          "saved_variable": "molecule_result"
        }
      ]
    }
  ],
  "constants": [],
  "constraints": {
    "max_gate_count": {}
  },
  "execution_preferences": {
    "amplitude_amplification": {
      "iterations": []
    },
    "random_seed": 3212497124,
    "backend_preferences": {
      "backend_service_provider": "IBM Quantum",
      "backend_name": "aer_simulator",
      "provider": {}
    }
  },
  "preferences": {
    "custom_hardware_settings": {
      "basis_gates": [
        "x",
        "cz",
        "id",
        "cy",
        "p",
        "rx",
        "tdg",
        "sxdg",
        "u2",
        "sx",
        "rz",
        "t",
        "z",
        "u1",
        "y",
        "h",
        "ry",
        "sdg",
        "cx",
        "u",
        "s"
      ]
    },
    "random_seed": 2143886915
  }
}
from classiq import construct_chemistry_model, synthesize
from classiq.applications.chemistry import Molecule, MoleculeProblem
from classiq.applications.chemistry import HVAParameters, ChemistryExecutionParameters
from classiq.execution import OptimizerType

from classiq import execute

molecule = Molecule(
    atoms=[("H", (0.0, 0.0, 0.0)), ("H", (0.0, 0.0, 0.735))],
)
gs_problem = MoleculeProblem(
    molecule=molecule,
    mapping="jordan_wigner",
)

ansatz_parameters = HVAParameters(
    reps=3,
)
execution_params = ChemistryExecutionParameters(
    optimizer=OptimizerType.COBYLA,
    max_iteration=30,
)

model = construct_chemistry_model(
    chemistry_problem=gs_problem,
    use_hartree_fock=True,
    ansatz_parameters=ansatz_parameters,
    execution_parameters=execution_params,
)
qprog = synthesize(model)

result = execute(qprog)

The output circuit:

alt text

[1] Dave Wecker, Matthew B. Hastings, and Matthias Troye Towards Practical Quantum Variational Algorithms. Phys. Rev. A 92, 042303 (2015).

[2] Roeland Wiersema, Cunlu Zhou, Yvette de Sereville, Juan Felipe Carrasquilla, Yong Baek Kim, Henry Yuen Exploring entanglement and optimization within the Hamiltonian Variational Ansatz . PRX Quantum 1, 020319 (2020).