QGAN
class QGAN(data, bounds=None, num_qubits=None, batch_size=500, num_epochs=3000, seed=7, discriminator=None, generator=None, tol_rel_ent=None, snapshot_dir=None, quantum_instance=None)
The Quantum Generative Adversarial Network algorithm.
The qGAN [1] is a hybrid quantum-classical algorithm used for generative modeling tasks.
This adaptive algorithm uses the interplay of a generative GenerativeNetwork
and a discriminative DiscriminativeNetwork
network to learn the probability distribution underlying given training data.
These networks are trained in alternating optimization steps, where the discriminator tries to differentiate between training data samples and data samples from the generator and the generator aims at generating samples which the discriminator classifies as training data samples. Eventually, the quantum generator learns the training data’s underlying probability distribution. The trained quantum generator loads a quantum state which is a model of the target distribution.
References:
[1] Zoufal et al.,
Quantum Generative Adversarial Networks for learning and loading random distributions
Parameters
- data (
ndarray
) – Training data of dimension k - bounds (
Optional
[ndarray
]) – k min/max data values [[min_0,max_0],…,[min_k-1,max_k-1]] if univariate data: [min_0,max_0] - num_qubits (
Optional
[ndarray
]) – k numbers of qubits to determine representation resolution, i.e. n qubits enable the representation of 2**n values [num_qubits_0,…, num_qubits_k-1] - batch_size (
int
) – Batch size, has a min. value of 1. - num_epochs (
int
) – Number of training epochs - seed (
int
) – Random number seed - discriminator (
Optional
[DiscriminativeNetwork
]) – Discriminates between real and fake data samples - generator (
Optional
[GenerativeNetwork
]) – Generates ‘fake’ data samples - tol_rel_ent (
Optional
[float
]) – Set tolerance level for relative entropy. If the training achieves relative entropy equal or lower than tolerance it finishes. - snapshot_dir (
Optional
[str
]) – Directory in to which to store cvs file with parameters, if None (default) then no cvs file is created. - quantum_instance (
Union
[QuantumInstance
,BaseBackend
,None
]) – Quantum Instance or Backend
Raises
AquaError – invalid input
Attributes
backend
d_loss
Returns discriminator loss
discriminator
Returns discriminator
g_loss
Returns generator loss
generator
Returns generator
quantum_instance
Type: Union[None, qiskit.aqua.quantum_instance.QuantumInstance]
Returns quantum instance.
Return type
Optional
[QuantumInstance
]
random
Return a numpy random.
rel_entr
Returns relative entropy between target and trained distribution
seed
Returns random seed
tol_rel_ent
Returns tolerance for relative entropy
Methods
get_rel_entr
QGAN.get_rel_entr()
Get relative entropy between target and trained distribution
run
QGAN.run(quantum_instance=None, **kwargs)
Execute the algorithm with selected backend.
Parameters
- quantum_instance (
Union
[QuantumInstance
,BaseBackend
,None
]) – the experimental setting. - kwargs (dict) – kwargs
Returns
results of an algorithm.
Return type
dict
Raises
AquaError – If a quantum instance or backend has not been provided
set_backend
QGAN.set_backend(backend, **kwargs)
Sets backend with configuration.
Return type
None
set_discriminator
QGAN.set_discriminator(discriminator=None)
Initialize discriminator.
Parameters
discriminator (Discriminator) – discriminator
set_generator
QGAN.set_generator(generator_circuit=None, generator_init_params=None, generator_optimizer=None)
Initialize generator.
Parameters
- generator_circuit (
Union
[UnivariateVariationalDistribution
,MultivariateVariationalDistribution
,QuantumCircuit
,None
]) – parameterized quantum circuit which sets the structure of the quantum generator - generator_init_params (
Optional
[ndarray
]) – initial parameters for the generator circuit - generator_optimizer (
Optional
[Optimizer
]) – optimizer to be used for the training of the generator
train
QGAN.train()
Train the qGAN