qiskit-machine-learning
qiskit-machine-learning copied to clipboard
`QGAN` unit tests re-use same instance for backend checks
Environment
- Qiskit Machine Learning version: 0.4.0
- Python version: 3.10.0
- Operating system: macOS Monterrey (12.2.1)
What is happening?
Most of the QGAN unit tests are supposed to check that the resulting relative entropies with qasm_simulator and statevector backends match, but instead of creating 2 separate instances of the QGAN class, what is done in test_qgan.py is:
trained_statevector = self.qgan.run(self.qi_statevector)
trained_qasm = self.qgan.run(self.qi_qasm)
self.assertAlmostEqual(trained_qasm["rel_entr"], trained_statevector["rel_entr"], delta=0.1)
This code retrains the QGAN with a different backend, without resetting the parameters in between, so it's not really performing the check it should.
How can we reproduce the issue?
Run unit tests (test_qgan.py) and print the entropy/parameter values, to see that the qasm_simulator run is not trained from scratch.
What should happen?
The 2 QGAN instances should be decoupled and run independently.
Any suggestions?
Store 2 copies of the QGAN instance, and run the tests like:
trained_statevector = self.qgan_statevec.run(qi_statevector)
trained_qasm = self.qgan_qasm.run(qi_qasm)
This issue has already been discussed with @Zoufalc and @ebermot, and is connected to #393.
A comment here. With algorithms they are supposed to be able to be re-used; e.g call the run() multiple times and it should behave as if the parameters were set just the same way on a brand new instance. I.e. run() should not depend on any prior state. As such running with a different quantum instance is legitimate in my mind. It it somehow passes due to saved state then it would be bad though so testing re-use is important in that area to ensure algorithms can be re-used but that runs are independent and not influenced by any state that might be saved/used.
The QGAN implementation is deprecated in #495. Unlikely this issue will be fixed.
Closing this issue as the original QGAN implementation has been removed.