qiskit-machine-learning icon indicating copy to clipboard operation
qiskit-machine-learning copied to clipboard

VQC inside session

Open dhirajmadan1 opened this issue 1 year ago • 4 comments
trafficstars

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)

dhirajmadan1 avatar Feb 19 '24 07:02 dhirajmadan1

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.

woodsp-ibm avatar Feb 20 '24 15:02 woodsp-ibm

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.'

dhirajmadan1 avatar Feb 28 '24 10:02 dhirajmadan1

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.

woodsp-ibm avatar Feb 28 '24 16:02 woodsp-ibm