Skip to content

Hardware Efficient Ansatz

The HardwareEfficientAnsatz built-in function generates parametric circuits to fit a specific hardware with a given connectivity map and a set of basis gates [1] . The ansatz is built from a layer of single qubit gates followed by a layer of entangling two qubit gates. Repeating this structure allows a more expressive ansatz at the cost of increased depth.

This built-in function can be called as part of a ground state solving algorithm, as described in Ground State Solving Algorithms, or explicitly within a quantum model, as described below. In the latter usage it can be accompanied with a user defined VQE call, or be called within a QNN model.


Function: HardwareEfficientAnsatz


  • num_qubits: Optional[int] – Number of qubits in the ansatz. If none are specified, use all qubits from the connectivity map.
  • connectivity_map: Optional[List[Tuple[int]]] – Hardware connectivity map, in the form [ [x0, x1], [x1, x2],...].
  • reps: [int] – Number of layers in the ansatz.
  • one_qubit_gates: Union[str, List[str]] – List of gates for the one qubit gates layer, e.g., ["x", "ry"].
  • two_qubit_gates: Union[str, List[str]] – List of gates for the two qubit gates entangling layer, e.g., ["cx", "cry"].
  • parameter_prefix: str – Prefix for the generated parameters.

If the number of qubits is not specified, the number of the qubits from the connectivity map is used. If the connectivity map is not specified, the connectivity map from the model hardware settings is used. If that is also not specified, all qubit pairs are connected.

The allowed one_qubit_gates: '["x", "y", "z", "h", "p", "i", "rx", "ry", "rz", "s", "sdg", "t", "tdg", "sx"]'.

The allowed two_qubit_gates: '["cx", "cy", "cz", "ch", "cp", "crx", "cry", "crz", "rxx", "ryy", "rzz", "swap", "iswap", "dcx"]'.


This example demonstrates how to generate a hardware-efficient ansatz. It uses a four qubit hardware with full connectivity.

  "functions": [
      "name": "main",
      "body": [
          "function": "HardwareEfficientAnsatz",
          "function_params": {
            "num_qubits": 4,
            "connectivity_map": [
            "reps": 2,
            "one_qubit_gates": ["x", "ry"],
            "two_qubit_gates": "cx"
from classiq import Model, synthesize
from classiq.builtin_functions import HardwareEfficientAnsatz

FULLY_CONNECTED_MESH = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]
hwea_params = HardwareEfficientAnsatz(
    one_qubit_gates=["x", "ry"],
model = Model()

[1] Abhinav Kandala, Antonio Mezzacapo, Kristan Temme, Maika Takita, Markus Brink, Jerry M. Chow, Jay M. Gambetta Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets. Nature 549, 242 (2017).