I'm trying to create a QSVM classifier model. I wanted to know which backend the fit() method uses to train the model. I checked on the IBM portal to see if there were any jobs being created, but there were none.

Also, is there a way to specify the backend on which the model will be trained?

  • 1
    $\begingroup$ In Qiskit you choose your own backend no? If they're somehow handling that for you, it's likely just a simulation. I doubt you would get any meaningful results trying to run the QSVM on an actual device. $\endgroup$
    – Dani007
    Nov 27, 2022 at 22:42
  • 1
    $\begingroup$ Hi, although you have quite a good answer, I would advise you next time to put much more details in your question, for example maybe the qiskit version you are using, or a snippet of your code, or more details about the problem you want to solve/you face, just to have a better idea of what you're trying to do so the answer can be more specific :) $\endgroup$
    – Lena
    Nov 28, 2022 at 9:31

1 Answer 1


First of all, I'm not sure the QSVM class is still part of Qiskit. There is no reference to it to be found in the documentation. It has likely been superseded by the QSVC class. See here for how to train a QSVC in the latest version of Qiskit.

Then, we can go to Qiskit's Github repository in order to find the source code of this class:

from sklearn.svm import SVC

class QSVC(SVC, SerializableModelMixin):
    def __init__(self, *args, quantum_kernel: Optional[BaseKernel] = None, **kwargs):
        super().__init__(kernel=self._quantum_kernel.evaluate, *args, **kwargs)

So, what it does it simply using the SVC class from sklearn with kernel self._quantum_kernel.evaluate. This is expected: the computational advantage of an SVC comes from the kernel evaluation.

Thus, the backend which is used is defined in the kernel that is used. For instance, for the FidelityQuantumKernel, one can see in the source code:

def __init__(
    feature_map: QuantumCircuit | None = None,
    fidelity: BaseStateFidelity | None = None,
    enforce_psd: bool = True,
    evaluate_duplicates: str = "off_diagonal",
) -> None:
    if fidelity is None:
        fidelity = ComputeUncompute(sampler=Sampler())
    self._fidelity = fidelity

So, under the hood, the computation uses the fidelity argument, which is an instance of BaseStateFidelity. For instance, if one uses the ComputeUncompute class, then one needs to pass a Sampler instance as an argument, which finally gives the answer.

If you're not familiar with Qiskit primitives, I encourage you to read about it in the documentation, in particular the Sampler page. What's important to note is that you can specify the backend that will be used by creating a Session instance with a context manager and creating your Sampler instance inside it, like this:

with Session(service=service, backend="ibmq_qasm_simulator"):
    sampler = Sampler()

Now, you have to be careful with the Sampler class, since they are two of them. The one which is used by default in the FidelityQuantumKernel is the one that lives in Qiskit, which, as mentioned in the documentation of the Sampler primitive, uses a local classical simulator. If you wish to change the backend, be sure to use the Sampler class from the qiksit_ibm_runtime package, as mentioned in the aforementioned documentation.


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.