# Hardware Efficient Ansatz¶

In NISQ-era devices, short and hardware-fitting quantum circuits are preferred in order to reduce the noise. Hardware-efficient ansatz is generated to fit a specific hardware with given connectivity map and basis gates  . The hardware efficient ansatz is build 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.

## Syntax¶

Function: HardwareEfficientAnsatz

Parameters:

• num_qubits: Optional[int] - Number of qubits in the ansatz. If none specified - use all qubits from the connectivity map
• connectivity_map: Optional[List[Tuple[int]]] - Hardware's 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"]

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 none specified as well, all qubit pairs will be connected.

## Example¶

In the following example, we demonstrate how to generate a hardware-efficient ansatz. In this example we will use a four qubit hardware, with full connectivity.

{"model":
{
"constraints": {
"max_depth": 100,
"max_width": 4
},
"logic_flow": [
{
"function": "HardwareEfficientAnsatz",
"function_params": {
"num_qubits": 4,
"connectivity_map": [
[0,1],
[0,2],
[0,3],
[1,2],
[1,3],
[2,3]
],
"reps": 2,
"one_qubit_gates": ["x", "ry"],
"two_qubit_gates": "cx"
}
}
]
}
}


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

from classiq import ModelDesigner
from classiq.builtin_functions import HardwareEfficientAnsatz

NUM_QUBITS = 4
FULLY_CONNECTED_MESH = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]
hwea_params = HardwareEfficientAnsatz(
num_qubits=NUM_QUBITS,
connectivity_map=FULLY_CONNECTED_MESH,
one_qubit_gates=["x", "ry"],
two_qubit_gates="cx",
reps=2,
)
model_designer = ModelDesigner()
model_designer.HardwareEfficientAnsatz(params=hwea_params)
generation_result = model_designer.synthesize()


The output Circuit is: 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)