qiskit-community / qiskit-machine-learning

Quantum Machine Learning
https://qiskit-community.github.io/qiskit-machine-learning/
Apache License 2.0
695 stars 328 forks source link

The return values from SamplerQNN are in the wrong shape. #819

Closed a-matsuo closed 1 month ago

a-matsuo commented 4 months ago

Environment

What is happening?

When the number of classical registers (measurements) is less than the total qubit size of the circuit, the shape of the return values is incorrect.

How can we reproduce the issue?

Run SamplerQNN where the circuit has fewer classical registers (measurements) than the total qubit size of the circuit.

What should happen?

The following line should be output_shape_ = 2**self.circuit.num_clbits https://github.com/qiskit-community/qiskit-machine-learning/blob/253b190eba869b4d002e490323ee4139612f01c9/qiskit_machine_learning/neural_networks/sampler_qnn.py#L280

Any suggestions?

No response

FrancescaSchiav commented 2 months ago

Hi @a-matsuo,

Thanks for your message. SamplerQNN does in fact return 2^circuit.num_qubits as per default when using it, as defined in it's description, which you can find here: https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html

But the output is indeed a modifiable parameter which you change for your needs. Just remember to change the output_shape alongside the interpret function, in order to have SamplerQNN work with a number of classical registers that is smaller than then number qubits.