I am using qiskit's VQC to build a classifier. Dimensionality of the data is 2 and number of classes are 4. The feature map I used is ZZFeatureMap and ansatz is the RealAplitudes. Then entanglement and reps are "full" and 2 respectively for both feature map and ansatz. Optimizer used is 'COBYLA'. Please find below the respective code.

enter image description here

When I try to fit the classifier, it is not optimising the weights and the loss is always "nan". It is stopping after 7 iterations.

enter image description here

What am I doing wrong and how can I train a classifier using qiskit's VQC ? Thank you!

  • $\begingroup$ Try to change your optimizer and see if that changes anything, $\endgroup$
    – KAJ226
    Oct 19, 2021 at 19:49
  • $\begingroup$ I did, I tried with ADAM and AMSGRAD too. I can't be help but think I am missing something basic somewhere. $\endgroup$ Oct 21, 2021 at 1:24
  • $\begingroup$ I strongly believe it is to do with the number of classes the dataset has. Upon trying a tutorial of qiskit on this topic, everything worked well until I changed the dataset to include more classes. I have elaborated on this here: quantumcomputing.stackexchange.com/questions/21661/… $\endgroup$ Oct 24, 2021 at 18:45

1 Answer 1


The issue was with 0.3.0 version of qiskit_machine_learning library. Fix is to install 0.4.0 version. More details about the issue and how to install 0.4.0 is in this answer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.