SaashaJoshi / piQture

piQture: A quantum machine learning library for image processing.
https://saashajoshi.github.io/piQture/
Apache License 2.0
15 stars 7 forks source link

QuantumPoolingLayer (s): For odd number of qubits, cz gates are not applied to the last qubit when conditional is False #40

Open SaashaJoshi opened 7 months ago

SaashaJoshi commented 7 months ago

When the conditional argument is False, i.e. when dynamic circuits are not used, a cz gate should be applied to adjacent qubits to perform the pooling function. The adjacent qubits must be in pairs, (0, 1), (1, 2) or groups (0, 1, 2), (2, 3, 4), where the phase_bits are 1, 2 and 1, 3 respectively.

However, in the current implementation of the QuantumPoolingLayer(s) when the num_qubits is odd and conditional = False, a cz is not getting applied to the last qubit. This can also be seen in the unit test test_pooling_layer.py as below,

https://github.com/SaashaJoshi/quantum-image-processing/blob/828a9297f9fa1976f531b23c98ad05623c2a1390/tests/neural_networks/layers/test_pooling_layer.py#L132-L140

To pinpoint the origin of the error, the for loop here generates an incorrect group of qubits for the cz gate to be applied on. https://github.com/SaashaJoshi/quantum-image-processing/blob/828a9297f9fa1976f531b23c98ad05623c2a1390/quantum_image_processing/neural_networks/layers/pooling_layer.py#L152-L156

While it is sure that this bug occurs in QuantumPoolingLayer3, it still needs to be verified if QuantumPoolingLayer2 shows similar behaviour.

This bug was discovered after #39 was closed.

SaashaJoshi commented 4 months ago

Also consider the open boundary conditions for QCNN, as proposed in the following paper.

T. Hur, L. Kim, and D. K. Park, “Quantum convolutional neural network for classical data classification,” Quantum Machine Intelligence, vol. 4, no. 1, Feb. 2022, doi: https://doi.org/10.1007/s42484-021-00061-x.