Slow adapt VQE deisgn in qiskit aer backend

Hi,

I was seeing the implementation of Adapt-VQE in Pennylane present in: https://pennylane.ai/qml/demos/tutorial_adaptive_circuits.html. The code here uses default qubit as the device object:
dev = qml.device(“default.qubit”, wires=qubits).

I want to later extract the qasm file for the optimized circuit. Hence I tried to use the qiskit aer device so that I can later use the circuit to qasm option. But then the adaptive steps that adaptively select the single and double excitation gates take a very long time to run. I am hence unable to get the qiskit device to be able to get the assembly file.

Hi @Rquant, welcome to the forum!

You can export to openqasm from the “tape” of the qnode, which is the data structure that contains its operations. This is a minimum working example that can show you how to code this.

import pennylane as qml

dev = qml.device("default.qubit", wires=1)

def f(x):
    qml.RX(x, wires=0)
    return qml.expval(qml.PauliZ(0))
qnode = qml.QNode(f, dev)
qnode(0.3)

qsm = qnode.tape.to_openqasm(wires=0)
print(qsm)

The output you should get is

OPENQASM 2.0;
include “qelib1.inc”;
qreg q[1];
creg c[1];
rx(0.3) q[0];
measure q[0] -> c[0];

Please let me know if this helps!

Hi,

So my issue is since I have mostly only tried to create fiunctions for vbariational circuits they oiften dont have a return object. Like for Adapt VQE the function is defined as:

def circuit_1(params, wires, excitations):
    qml.BasisState(hf_state, wires=wires)
    for i, excitation in enumerate(excitations):
        if len(excitation) == 4:
            qml.DoubleExcitation(params[i], wires=excitation)
        else:
            qml.SingleExcitation(params[i], wires=excitation)

Since the circuit is defined without retun object (then combined with the device etc in the ExpVal function so how do you isolate the qnoide object for a circuit when it does not have a measurement on it?

Hi @Rquant! In this example, you could do this:

@qml.qnode(dev)
def circuit_1(params, wires, excitations):
    qml.BasisState(hf_state, wires=wires)
    for i, excitation in enumerate(excitations):
        if len(excitation) == 4:
            qml.DoubleExcitation(params[i], wires=excitation)
        else:
            qml.SingleExcitation(params[i], wires=excitation)
    return qml.expval(H)

where H is your Hamiltonian object.