paddle_quantum.qml.qcaan

Quantum-circuit associative adversarial network (QCAAN) model

paddle_quantum.qml.qcaan.Data_Load()

Load the MNIST dataset

Returns:

MNIST dataset

Return type:

MNIST

class paddle_quantum.qml.qcaan.ConvBlock(shape, in_channels, out_channels, kernel_size=3, stride=1, padding=1, activation=None, normalize=True)

Bases: Layer

Convolution block for building neural networks.

Each ConvBlock consists of several convolution, Silu and layer normalization layers. And ConvBlock keeps the spatial dimensions unchanged, i.e., height and weight.

Parameters:
  • shape (List[int]) – The required shape for layer normalization.

  • in_channels (int) – The number of input channels in the input.

  • out_channels (int) – The number of output channels produced by the convolution.

  • kernel_size (int) – The size of the convolution kernel.

  • stride (int) – The stride size.

  • padding (int) – The padding size.

  • activation (Layer) – Activation function.

  • normalize (bool) – A symbol indicating whether layer normalization is needed.

forward(x)

The ConvBlock’s forward function

Parameters:

x (Tensor) – The input tensor

Returns:

The output tensor

Return type:

Tensor

class paddle_quantum.qml.qcaan.Generator(latent_dim=16)

Bases: Layer

The Generator network

Parameters:

latent_dim (int) – Latent feature numbers which represents the input dimension of the Generator.

forward(x)

The Generator’s forward function

Parameters:

x (Tensor) – The input tensor

Returns:

The output tensor

Return type:

Tensor

class paddle_quantum.qml.qcaan.Discriminator(latent_dim=16)

Bases: Layer

The Discriminator network

Parameters:

latent_dim (int) – Latent feature numbers which represents the input dimension of the Generator.

forward(x)

The Discriminator’s forward function

Parameters:

x (Tensor) – The input tensor

Returns:

The output tensor

Return type:

Tuple[Tensor, Tensor]

paddle_quantum.qml.qcaan.generate_pauli_string_list(num_qubits, num_terms)

Generate the Pauli string list. :param num_qubits: The number of the qubits. :param num_terms: The number of the generated observables.

Returns:

Return the generated Pauli string list.

Return type:

List[list]

class paddle_quantum.qml.qcaan.QCBM(num_qubits, num_depths, latent_dim=16)

Bases: Layer

Quantum Circuit Boltzmann Machine, which is exactly a quantum neural network here.

Parameters:
  • num_qubits (int) – The number of qubits which the quantum circuit contains.

  • num_depths (int) – The number of depths of complex entangled layers which the quantum circuit contains.

  • latent_dim (int) – Latent feature numbers which represents the input dimension of the generator.

forward()

The forward function of QCBM

Returns:

A series of expectation values on Z0, Z1, …, X0, X1, …, Y0, Y1, …

Return type:

Tensor

paddle_quantum.qml.qcaan.prior_sampling(expec_obs, batch_size)

Simulate the sampling process of the prior distribution, from QCBM.

Parameters:
  • expec_obs (Tensor) – The vector of expectation values whose length is the same as ‘latent_dim’.

  • batch_size (int) – The number of samples in a batch.

Returns:

The sampling results, values in {-1, 1}.

Return type:

Tensor

paddle_quantum.qml.qcaan.train(num_qubits=8, num_depths=4, lr_qnn=0.005, batch_size=128, latent_dim=16, epochs=21, lr_g=0.0002, lr_d=0.0002, beta1=0.5, beta2=0.9, manual_seed=888)

The training function of QCAAN model

Parameters:
  • num_qubits (int) – The number of qubits which the quantum circuit contains.

  • num_depths (int) – The number of depths of complex entangled layers which the quantum circuit contains.

  • lr_qnn (paddle.float32) – The learning rate used to update the QNN parameters, default to 0.005.

  • batch_size (int) – The batch size in each iteration.

  • latent_dim (int) – Latent feature numbers which represents the input dimension of the generator.

  • epochs (int) – The number of epochs to train the model.

  • lr_g (paddle.float32) – The learning rate used to update the generator parameters, default to 0.0002.

  • lr_d (paddle.float32) – The learning rate used to update the discriminator parameters, default to 0.0002.

  • beta1 (paddle.float32) – The beta1 used in Adam optimizer of generator and discriminator, default to 0.5.

  • beta2 (paddle.float32) – The beta2 used in Adam optimizer of generator and discriminator, default to 0.9.

  • manual_seed (int) – The manual seed for reproducibility.

Returns:

The parameters of QNN, Generator and Discriminator are saved.

Return type:

None

paddle_quantum.qml.qcaan.model_test(model_name='qcaan-model', latent_dim=16, params_path='params', num_qubits=8, num_depths=4, manual_seed=20230313)

Load the saved model parameters, and generate some pictures. Finally save these pictures.

Parameters:
  • model_name (str) – The name of the model, which is used to save the model.

  • latent_dim (int) – Latent feature numbers which represents the input dimension of the generator.

  • params_path (str) – The path to load the parameters of the trained model. Both relative and absolute paths are allowed.

  • num_qubits (int) – The number of qubits which the quantum circuit contains.

  • num_depths (int) – The number of depths of complex entangled layers which the quantum circuit contains.

  • manual_seed (int) – The manual seed for reproducibility.

Returns:

The generated pictures are saved to a .png file.

Return type:

None