Generating a hardware-efficient Ansatz

Mira Gross
Developer
Topics
Date
30 Jan 2022
Share this article
Topics
Date
31 March 2022
Our Library
Share this article

Given a molecule, the Hamiltonian describes the interactions between all electrons and nuclei.

Calculating the energies of a molecular Hamiltonian, and especially its ground state, allows us to understand the chemical properties of a molecule. Since the molecular Hamiltonian is inherently quantum, quantum computing can be used to calculate such properties efficiently by leveraging the same quantum effects in appropriate quantum algorithms. This is done in 3 steps:

  1. Calculating the molecular Hamiltonian for the desired molecule.
  2. Generating an appropriate variational quantum circuit to calculate the Hamiltonian's ground state. Today, we will focus on this step, demonstrate how to create a variational circuit.
  3. Executing the desired quantum circuit as part of a hybrid quantum-classical algorithm.

The ground state of a Hamiltonian is found by using an appropriate variational quantum circuit (usually called an Ansatz), and then combining it with a classical optimizer to find the minimal expectation value for the Hamiltonian. In NISQ-era devices, short and hardware-fitting quantum circuits are preferred, to reduce the noise and get better results.

In the following example, we demonstrate how to generate a hardware-efficient Ansatz, i.e. an Ansatz that is generated to fit a specific hardware.

In this example we will use a 4-qubit hardware, with full connectivity.

Using Classiq's textual model, the code looks like this:


{
    "quantum_circuit_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
                }
            }
        ]
    }
}

Alternatively, one can synthesize the same circuit using Classiq's Python SDK:


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,
    reps=2
)
model_designer = ModelDesigner()
model_designer.HardwareEfficientAnsatz(params=hwea_params)
generation_result = model_designer.synthesize()

Here is the resulting output circuit:

alt text

Given a molecule, the Hamiltonian describes the interactions between all electrons and nuclei.

Calculating the energies of a molecular Hamiltonian, and especially its ground state, allows us to understand the chemical properties of a molecule. Since the molecular Hamiltonian is inherently quantum, quantum computing can be used to calculate such properties efficiently by leveraging the same quantum effects in appropriate quantum algorithms. This is done in 3 steps:

  1. Calculating the molecular Hamiltonian for the desired molecule.
  2. Generating an appropriate variational quantum circuit to calculate the Hamiltonian's ground state. Today, we will focus on this step, demonstrate how to create a variational circuit.
  3. Executing the desired quantum circuit as part of a hybrid quantum-classical algorithm.

The ground state of a Hamiltonian is found by using an appropriate variational quantum circuit (usually called an Ansatz), and then combining it with a classical optimizer to find the minimal expectation value for the Hamiltonian. In NISQ-era devices, short and hardware-fitting quantum circuits are preferred, to reduce the noise and get better results.

In the following example, we demonstrate how to generate a hardware-efficient Ansatz, i.e. an Ansatz that is generated to fit a specific hardware.

In this example we will use a 4-qubit hardware, with full connectivity.

Using Classiq's textual model, the code looks like this:


{
    "quantum_circuit_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
                }
            }
        ]
    }
}

Alternatively, one can synthesize the same circuit using Classiq's Python SDK:


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,
    reps=2
)
model_designer = ModelDesigner()
model_designer.HardwareEfficientAnsatz(params=hwea_params)
generation_result = model_designer.synthesize()

Here is the resulting output circuit:

alt text

Start Creating Quantum Software Without Limits