qiskit-machine-learning
qiskit-machine-learning copied to clipboard
VQC inside session
What should we add?
How to train/ test a VQC model using qiskit runtime sessions? I tried encapsulating under session as below. But it seems to be running on simulator even though a real backend is selected.
service = QiskitRuntimeService(channel="ibm_quantum", token=qAccesKey)
backend = least_busy(service.backends(simulator=False, operational=True, min_num_qubits=args.dim))
with Session(service = service, backend = backend):
vqc = VQC(feature_map=feature_map,
ansatz=ansatz,
optimizer=NFT(maxiter=args.blk),
callback=callback_graph,
)
vqc.fit(train_data, train_labels)
VQC has a sampler parameter
sampler (BaseSampler | None) – an optional Sampler primitive instance to be used by the underlying SamplerQNN neural network. If None is passed then an instance of the reference Sampler will be used.
With None passed (default) as it states it uses the reference Sampler primitive from Qiskit. To use a real backend you need to instantiate and explicitly pass a runtime Sampler. As your code is above the Session is unused since that is only meaningful when used with the runtime primitives.
Thanks a lot @woodsp-ibm . I have made the above change i.e. adding a sampler. Now I am getting this exception:- qiskit_machine_learning.exceptions.QiskitMachineLearningError: 'Sampler job failed.'
Its not a lot to go on. It should work. Maybe add your updated code here just in case. You can also look at the jobs in your account and see if there is any further error information listed there.