qiskit-community / qiskit-machine-learning

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

Allow measuring subset of qubits when QuantumKernel.evaluate() is run on MPS simulator #157

Closed omarshehab closed 2 years ago

omarshehab commented 3 years ago

What is the expected enhancement?

Right now QuantumKernel.evaluate() measures all qubits used in the circuit. There should be a way to take advantage of the fix given here if the MPS simulator is used with the option "mps_sample_measure_algorithm": "mps_apply_measure".

woodsp-ibm commented 3 years ago

From the link this looks like a performance enhancement when using MPS simulator when all qubits are being measured. You can pass in an Aer simulator set for MPS mode and configure it accordingly. Having only just skimmed over the PR you linked what is it that you are proposing is changed here?

As far as the title is concerned Allow measuring subset of qubits - I got the impression from reading the linked PR that the change did not cater to that, but it might be possible to do later. Can you explain further...

omarshehab commented 3 years ago

@woodsp-ibm , The QuantumKernel.evaluate() API currently measures all qubits so we cannot take advantage of measuring subset of qubits when we are using the MPS simulator.

woodsp-ibm commented 3 years ago

I guess I am confused - the PR you linked says this as a summary

Performance improvement for the case where all qubits are measured.

and later

It is possible to implement for cases where a subset of the qubits is measured, but this will require additional effort to decide when propagation is necessary and when not.

which I took to mean that it was not implemented at present anyway.

omarshehab commented 3 years ago

@woodsp-ibm , it has been implemented and merged as shown below.

image

Unfortunately,QuantumKernel.evaluate(), while running on MPS simulator, cannot take advantage of this at this moment.

adekusar-drl commented 3 years ago

@omarshehab Could you please write a bit detailed description? I don't fully understand what is suggested to do here.

omarshehab commented 3 years ago

@adekusar-drl , measurement of only specific qubits is required for qiskit.aqua.algorithms.VQC(). When this API is run on MPS simulator, we want to make sure that MPS simulator is taking advantage of this partial measurement.

adekusar-drl commented 3 years ago

As I see in qiskit_machine_learning.kernels.QuantumKernel implementation, only a required number of qubits is measured, basically it is the number of qubits in the feature map passed to QuantumKernel. If you don't pass a feature map, then ZZFeatureMap(2) is used. So, that's why I don't fully understand what is wrong in the implementation.

By the way, aqua and qiskit.aqua.algorithms.VQC are deprecated, I don't think we will update them with new features.

adekusar-drl commented 2 years ago

I'm closing this issue as stale and unclear. Feel free to re-open with more details provided.