Skip to content

Hardware Efficient Ansatz

In NISQ-era devices, to reduce noise, use short and hardware-fitting quantum circuits.

Hardware-efficient ansatz is generated to fit a specific hardware with given connectivity map and basis gates [1] . The hardware-efficient 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.


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 four qubit hardware with full connectivity.

      "logic_flow": [
          "function": "HardwareEfficientAnsatz",
          "function_params": {
            "num_qubits": 4,
            "connectivity_map": [
            "reps": 2,
            "one_qubit_gates": ["x", "ry"],
            "two_qubit_gates": "cx"

The textual interface synthesizes the ansatz circuit by opening the Command Palette (Ctrl+Shift+P / Command+Shift+P on Windows/Mac, respectively) and choosing the "Generate Ansatz" command.

from classiq import Model
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()
generation_result = model.synthesize()

The output circuit:

alt text

[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).