# How to set hyper parameters for a Variational Quantum Classifier (qiskit)?

I am trying to implement a Variational Quantum Classifier using qiskit's VQC. I have set the feature map to ZZFeatureMap and am using the RealAmplitudes ansatz. I am using cross_entropy loss function and ADAM optimiser. One more parameter that VQC requires is a QuantumInstance object and this I have set to aer_simulator with 1024 shots. The code and instructions I followed is in this qiskit's tutorial.

When I try to train the classifier, it running for a different number of iterations each time. Is there a way to set minimum number of iterations ? and how are iterations different from shots ?

Also, how can I set the learning rate for the algorithm ? Thank you !

The VQC consists of a feedback loop of quantum and classical processor, where the loss function is evaluated on a quantum computer and the classical part suggests new parameters. The number of shots is the number of samples the quantum computer does to estimate the expectation values (-> the loss function). The number of iterations is the number of times the classical part updates the parameters.

The settings you want to specify are part of the classical optimizer, in your case ADAM. Following the tutorial you linked, I'm assuming you're constructing the algorithm as

# construct feature map, ansatz, and optimizer
feature_map = ZZFeatureMap(num_inputs)
ansatz = RealAmplitudes(num_inputs, reps=1)

# construct variational quantum classifier
vqc = VQC(feature_map=feature_map,
ansatz=ansatz,
loss='cross_entropy',
optimizer=optimizer,
quantum_instance=quantum_instance,
callback=callback_graph)


You can pass your settings into the ADAM class, for instance to set the learning rate

optimizer = ADAM(lr=your_desired_learning_rate)


The number of iterations depends on the convergence and I don't think you can set a minimum number of them. However you can set a lower tolerance which will lead to more iterations. For example

optimizer = ADAM(lr=0.01, tol=1e-7)


You can find more on that in the documentation.

• Thank you, this clears up a lot of things. Oct 18 at 12:58