qiskit.aqua.algorithms.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)[código fonte]¶ 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 discriminativeDiscriminativeNetwork
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
- Parâmetros
data (
Union
[ndarray
,List
]) – Training data of dimension kbounds (
Union
[ndarray
,List
,None
]) – k min/max data values [[min_0,max_0],…,[min_k-1,max_k-1]] if univariate data: [min_0,max_0]num_qubits (
Union
[ndarray
,List
,None
]) – 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 epochsseed (
int
) – Random number seeddiscriminator (
Optional
[DiscriminativeNetwork
]) – Discriminates between real and fake data samplesgenerator (
Optional
[GenerativeNetwork
]) – Generates ‘fake’ data samplestol_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
,Backend
,BaseBackend
,None
]) – Quantum Instance or Backend
- Levanta
AquaError – invalid input
-
__init__
(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)[código fonte]¶ - Parâmetros
data (
Union
[ndarray
,List
]) – Training data of dimension kbounds (
Union
[ndarray
,List
,None
]) – k min/max data values [[min_0,max_0],…,[min_k-1,max_k-1]] if univariate data: [min_0,max_0]num_qubits (
Union
[ndarray
,List
,None
]) – 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 epochsseed (
int
) – Random number seeddiscriminator (
Optional
[DiscriminativeNetwork
]) – Discriminates between real and fake data samplesgenerator (
Optional
[GenerativeNetwork
]) – Generates ‘fake’ data samplestol_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
,Backend
,BaseBackend
,None
]) – Quantum Instance or Backend
- Levanta
AquaError – invalid input
Methods
__init__
(data[, bounds, num_qubits, …])- type data
Union
[ndarray
,List
]
Get relative entropy between target and trained distribution
run
([quantum_instance])Execute the algorithm with selected backend.
set_backend
(backend, **kwargs)Sets backend with configuration.
set_discriminator
([discriminator])Initialize discriminator.
set_generator
([generator_circuit, …])Initialize generator.
train
()Train the qGAN
Attributes
Returns backend.
Returns discriminator loss
Returns discriminator
Returns generator loss
Returns generator
Returns quantum instance.
Return a numpy random.
Returns relative entropy between target and trained distribution
Returns random seed
Returns tolerance for relative entropy
-
property
backend
¶ Returns backend.
- Tipo de retorno
Union
[Backend
,BaseBackend
]
-
property
d_loss
¶ Returns discriminator loss
- Tipo de retorno
List
[float
]
-
property
discriminator
¶ Returns discriminator
-
property
g_loss
¶ Returns generator loss
- Tipo de retorno
List
[float
]
-
property
generator
¶ Returns generator
-
get_rel_entr
()[código fonte]¶ Get relative entropy between target and trained distribution
- Tipo de retorno
float
-
property
quantum_instance
¶ Returns quantum instance.
- Tipo de retorno
Optional
[QuantumInstance
]
-
property
random
¶ Return a numpy random.
-
property
rel_entr
¶ Returns relative entropy between target and trained distribution
- Tipo de retorno
List
[float
]
-
run
(quantum_instance=None, **kwargs)¶ Execute the algorithm with selected backend.
- Parâmetros
quantum_instance (
Union
[QuantumInstance
,Backend
,BaseBackend
,None
]) – the experimental setting.kwargs (dict) – kwargs
- Retorna
results of an algorithm.
- Tipo de retorno
dict
- Levanta
AquaError – If a quantum instance or backend has not been provided
-
property
seed
¶ Returns random seed
-
set_backend
(backend, **kwargs)¶ Sets backend with configuration.
- Tipo de retorno
None
-
set_discriminator
(discriminator=None)[código fonte]¶ Initialize discriminator.
- Parâmetros
discriminator (Discriminator) – discriminator
-
set_generator
(generator_circuit=None, generator_init_params=None, generator_optimizer=None, generator_gradient=None)[código fonte]¶ Initialize generator.
- Parâmetros
generator_circuit (
Union
[UnivariateVariationalDistribution
,MultivariateVariationalDistribution
,QuantumCircuit
,None
]) – parameterized quantum circuit which sets the structure of the quantum generatorgenerator_init_params (
Optional
[ndarray
]) – initial parameters for the generator circuitgenerator_optimizer (
Optional
[Optimizer
]) – optimizer to be used for the training of the generatorgenerator_gradient (
Union
[Callable
,Gradient
,None
]) – A Gradient object, or a function returning partial derivatives of the loss function w.r.t. the generator variational params.
- Levanta
AquaError – invalid input
-
property
tol_rel_ent
¶ Returns tolerance for relative entropy
-
train
()[código fonte]¶ Train the qGAN
- Levanta
AquaError – Batch size bigger than the number of items in the truncated data set