I would like to add a noise model to one of the tutorial examples of quantum machine learning in the Qiskit site (PyTorch QGAN implementation).
I used the following codes
sampler_n = AerSampler()
sampler_n.set_options(noise_model=noise_model)
instead of
sampler = Sampler(options={ "shots": shots, "seed": algorithm_globals.random_seed})
Whenever the quantum circuit is well-defined (does not have any parameters), such as
weights_n = algorithm_globals.random.random(qc_zofal.num_parameters)
def create_generator() -> TorchConnector:
p = qc_zofal.assign_parameters(weights_n)
qnn = SamplerQNN(
sampler = sampler_n,
circuit= p,
input_params=[],
weight_params=p.parameters,
sparse=False,
)
return TorchConnector(qnn, [])
generator_n = create_generator()
print(generator_n)
print(generator_n(torch.tensor([])).reshape(-1,1))
print(generator.parameters)
Everything is ok. But if I put a parametric circuit in it, I encounter the following error:
WARNING:qiskit_aer.backends.aerbackend:Simulation failed and returned the following error message:
ERROR: Failed to load circuits: Invalid parameterized qobj: instruction param position out of range
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/qiskit/result/result.py in _get_experiment(self, key)
367 try:
--> 368 exp = self.results[key]
369 except IndexError as ex:
IndexError: list index out of range
The above exception was the direct cause of the following exception:
QiskitError Traceback (most recent call last)
14 frames
QiskitError: 'Result for experiment "0" could not be found.'
The above exception was the direct cause of the following exception:
QiskitMachineLearningError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/qiskit_machine_learning/neural_networks/sampler_qnn.py in _forward(self, input_data, weights)
360 results = job.result()
361 except Exception as exc:
--> 362 raise QiskitMachineLearningError("Sampler job failed.") from exc
363 result = self._postprocess(num_samples, results)
364
QiskitMachineLearningError: 'Sampler job failed.'
Could you please help me How can I fix this error?
And my next question is: How can I access the QNN parameters after each training from pytorchconnector?