Hi there,
Suppose I have the final circuit output from ADAPT-VQE, where all parameters have already been optimized.
My question is: Is there a way to reuse this circuit structure but reparameterize it with new (unoptimized) parameters? In other words, can I retain the same gate sequence but reset the parameter values to allow for fresh optimization?
This is my code by the way. Thanks so much.
# Load the dataset
dataset = qml.data.load("qchem", molname="H2", basis="6-31G")[0]
H, qubits = dataset.hamiltonian, len(dataset.hamiltonian.wires)
hf_state = dataset.hf_state
n_electrons = dataset.electrons
# Print dataset details
print("--- ADAPT-VQE BENCHMARK ---")
print("Number of qubits = ", qubits)
print("Hartree-Fock state = ", hf_state)
print("Reference VQE energy = ", dataset.vqe_energy)
# Define the quantum device
dev = qml.device("lightning.qubit", wires=qubits)
# Counter for circuit evaluations
circuit_evals = 0
# Generate operator pool
singles, doubles = qml.qchem.excitations(n_electrons, qubits)
singles_excitations = [qml.SingleExcitation(0.0, x) for x in singles]
doubles_excitations = [qml.DoubleExcitation(0.0, x) for x in doubles]
operator_pool = doubles_excitations + singles_excitations
# Define the circuit
@qml.qnode(dev)
def circuit():
global circuit_evals
circuit_evals += 1
qml.BasisState(hf_state, wires=range(qubits))
return qml.expval(H)
# Instantiate the optimizer
opt = qml.AdaptiveOptimizer(10, 0.9)
total_adapt_evals = 0
# Optimization loop
for i in range(len(operator_pool)):
# Reset counter for this step
circuit_evals = 0
# Perform adaptive optimization step
circuit, target, gradient = opt.step_and_cost(circuit, operator_pool, drain_pool=True)
circuit_adapt = circuit
# Count evaluations
evals_for_step = circuit_evals
total_adapt_evals += evals_for_step
# Print results
print(f'ADAPT-VQE Step {i+1}:')
print('Energy:', target)
print('Largest Gradient:', gradient)
print('Circuit evaluations for gradient:', evals_for_step)
print()
# Check convergence
if gradient < 1e-3:
break
# Print final result
print(f"Final ADAPT-VQE energy: {target:.8f} Hartree")
print(f"Total ADAPT-VQE evaluations: {total_adapt_evals}")
print("-----------------------------")```