Neural Network Layers

piqture.neural_networks.layers.base_layer module

Abstract Base Class for QNN Layers

class piqture.neural_networks.layers.base_layer.BaseLayer(num_qubits: int | None = None, circuit: QuantumCircuit = None, unmeasured_bits: list | None = None)

Bases: ABC

Abstract base class for layer structure in a quantum neural network.

abstractmethod build_layer()

Helps build the layer circuit.

property circuit

Returns a base_layer circuit.

property num_qubits

Returns number of qubits in base_layer circuit.

property unmeasured_bits

Returns number of unmeasured bits in base_layer circuit.

piqture.neural_networks.layers.convolutional_layer module

Quantum Convolutional Layer Structure

class piqture.neural_networks.layers.convolutional_layer.QuantumConvolutionalLayer(num_qubits: int | None = None, circuit: QuantumCircuit | None = None, unmeasured_bits: list | None = None, mera_args: dict | None = None)

Bases: BaseLayer

Builds a convolutional layer in the neural network with the help of the MERA tensor network.

MERA and the convolutional layer in a QCNN run in the opposite directions. However, for the sake of simplicity, this repository builds both in the same direction.

References:

[1] I. Cong, S. Choi, and M. D. Lukin, “Quantum convolutional neural networks,” Nature Physics, vol. 15, no. 12, pp. 1273–1278, Aug. 2019, doi: https://doi.org/10.1038/s41567-019-0648-8.

build_layer() tuple[QuantumCircuit, list]

Implements the MERA tensor network with a restriction on the depth of the layers, specified by a hyperparameter, layer_depth.

Returns:

circuit (QuantumCircuit): circuit with a convolutional layer.

unmeasured_bits (dict): a dictionary of unmeasured qubits and classical bits in the circuit.

piqture.neural_networks.layers.fully_connected_layer module

Quantum Fully Connected Layer Structure

class piqture.neural_networks.layers.fully_connected_layer.FullyConnectedLayer(num_qubits: int, circuit: QuantumCircuit, unmeasured_bits: list)

Bases: BaseLayer

Builds a fully-connected layer in the neural network with the help of controlled phase gates.

References:

[1] I. Cong, S. Choi, and M. D. Lukin, “Quantum convolutional neural networks,” Nature Physics, vol. 15, no. 12, pp. 1273–1278, Aug. 2019, doi: https://doi.org/10.1038/s41567-019-0648-8.

build_layer() tuple[QuantumCircuit, list]

Implements a fully connected layer with controlled phase gates on adjacent qubits followed by a measurement in X-basis.

Returns:

circuit (QuantumCircuit): circuit with a fully connected layer.

unmeasured_bits (dict): a dictionary of unmeasured qubits and classical bits in the circuit.

piqture.neural_networks.layers.pooling_layer module

Quantum Pooling Layer Structure

class piqture.neural_networks.layers.pooling_layer.QuantumPoolingLayer2(num_qubits: int, circuit: QuantumCircuit, unmeasured_bits: list, conditional: bool | None = False)

Bases: BaseLayer

Builds a Pooling Layer, performing measurements on one of the two adjacent qubits, with the help of controlled-phase gates (dynamic circuits).

References:

[1] I. Cong, S. Choi, and M. D. Lukin, “Quantum convolutional neural networks,” Nature Physics, vol. 15, no. 12, pp. 1273–1278, Aug. 2019, doi: https://doi.org/10.1038/s41567-019-0648-8.

build_layer() tuple[QuantumCircuit, list]

Implements a pooling layer with alternating phase flips on qubits when the adjacent qubits measured in X-basis result in X = -1.

Returns:

circuit (QuantumCircuit): circuit with a pooling layer.

unmeasured_bits (dict): a dictionary of unmeasured qubits and classical bits in the circuit.

class piqture.neural_networks.layers.pooling_layer.QuantumPoolingLayer3(num_qubits: int, circuit: QuantumCircuit, unmeasured_bits: list, conditional: bool | None = False)

Bases: BaseLayer

Builds a Pooling Layer, performing measurements on two of the three adjacent qubits, with the help of controlled-phase gates (dynamic circuits).

References:

[1] I. Cong, S. Choi, and M. D. Lukin, “Quantum convolutional neural networks,” Nature Physics, vol. 15, no. 12, pp. 1273–1278, Aug. 2019, doi: https://doi.org/10.1038/s41567-019-0648-8.

build_layer() tuple[QuantumCircuit, list]

Implements a pooling layer with alternating phase flips on qubits when the adjacent qubits measured in X-basis result in X = -1.

Returns:

circuit (QuantumCircuit): circuit with a pooling layer.

unmeasured_bits (dict): a dictionary of unmeasured qubits and classical bits in the circuit.