Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quantum convolutional neural network (QCNN) #6

Merged
merged 18 commits into from
Nov 23, 2023
Merged

Add quantum convolutional neural network (QCNN) #6

merged 18 commits into from
Nov 23, 2023

Conversation

SaashaJoshi
Copy link
Owner

@SaashaJoshi SaashaJoshi commented Nov 5, 2023

The QCNN structure consists of 4 layers: data embedding, convolutional layer, pooling layer, and fully connected layer, followed by measurement and training.

  • Convolutional Layer (inherits MERA)
  • Pooling Layer
  • Fully Connected Layer

- [ ] Data encoding integration (separate PR)
- [ ] Training integration (separate PR)

@SaashaJoshi SaashaJoshi marked this pull request as ready for review November 10, 2023 18:48
@SaashaJoshi
Copy link
Owner Author

Currently, the pooling layer considers two adjacent qubits and applies a dynamic circuit. It measures one of the qubits and a controlled phase gate on the other. However, as given in the reference paper, this measurement can also be performed on two adjacent qubits. Two qubits are measured, and corresponding controlled phase gates are applied to the qubit.

https://github.com/SaashaJoshi/quantum-image-processing/blob/2d21202f013546b7894bbbc90f368ae9ab2f87d6/quantum_image_processing/models/neural_networks/convolutional/qcnn.py#L121-L123

This flexibility in the number of qubits to be measured is yet to be implemented. This feature (perhaps) corresponds to the size of strides in a classical pooling layer.


return self.circuit.decompose(), list(self.circuit.qubits)
return self.circuit.compose(
method(self.complex_structure),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conv layer or the MERA structure still doesn't take into consideration only the unmeasured qubits. If applied more than once, a conv layer is built on all the qubits and not just the unmeasured ones. This needs to be corrected.

@SaashaJoshi
Copy link
Owner Author

SaashaJoshi commented Nov 15, 2023

The decision to make in-place changes to the circuit while applying different layers is made because dynamic circuits (if_test, or if_else), used in Pooling layers, cannot be composed with any other circuit in the current version of Qiskit. These instructions are applied with a context manager and cannot be applied when clbits outside the enclosing circuit are referred.

Refer: Raises CircuitError

@SaashaJoshi
Copy link
Owner Author

The EstimatorQNN doesn't allow measurements. Therefore, the current QuantumPoolingLayer cannot be applied with the estimator primitive. One alternative could be to change the way the pooling layer is built, i.e. without using the dynamic circuits and (perhaps) using some operator to replicate the results of a controlled-phase shift. Else, searching into the primitives could help find a way around this.

@SaashaJoshi
Copy link
Owner Author

Searching into primitives - primitives currently do not support dynamic circuits. In order to apply these mid-circuit measurements, a simple backend.run() should be used. However, this does not support a runtime behaviour (i.e. a cyclic run of the circuit on the hardware without facing the queue more than once).
Refer: How do Qiskit Runtime primitives differ from backend.run?

@SaashaJoshi SaashaJoshi merged commit e733722 into main Nov 23, 2023
0 of 8 checks passed
@SaashaJoshi SaashaJoshi deleted the qcnn branch November 29, 2023 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant