qiskit.aqua.components.neural_networks.QuantumGenerator¶
-
class
QuantumGenerator
(bounds, num_qubits, generator_circuit=None, init_params=None, optimizer=None, snapshot_dir=None)[소스]¶ Quantum Generator.
The quantum generator is a parametrized quantum circuit which can be trained with the
QGAN
algorithm to generate a quantum state which approximates the probability distribution of given training data. At the beginning of the training the parameters will be set randomly, thus, the output will is random. Throughout the training the quantum generator learns to represent the target distribution. Eventually, the trained generator can be used for state preparation e.g. in QAE.- 매개변수
bounds (
ndarray
) – k min/max data values [[min_1,max_1],…,[min_k,max_k]], given input data dim knum_qubits (
List
[int
]) – k numbers of qubits to determine representation resolution, i.e. n qubits enable the representation of 2**n values [n_1,…, n_k]generator_circuit (
Union
[UnivariateVariationalDistribution
,MultivariateVariationalDistribution
,QuantumCircuit
,None
]) – a UnivariateVariationalDistribution for univariate data, a MultivariateVariationalDistribution for multivariate data, or a QuantumCircuit implementing the generator.init_params (
Union
[List
[float
],ndarray
,None
]) – 1D numpy array or list, Initialization for the generator’s parameters.optimizer (
Optional
[Optimizer
]) – optimizer to be used for the training of the generatorsnapshot_dir (
Optional
[str
]) – str or None, if not None save the optimizer’s parameter after every update step to the given directory
- 예외
AquaError – Set multivariate variational distribution to represent multivariate data
-
__init__
(bounds, num_qubits, generator_circuit=None, init_params=None, optimizer=None, snapshot_dir=None)[소스]¶ - 매개변수
bounds (
ndarray
) – k min/max data values [[min_1,max_1],…,[min_k,max_k]], given input data dim knum_qubits (
List
[int
]) – k numbers of qubits to determine representation resolution, i.e. n qubits enable the representation of 2**n values [n_1,…, n_k]generator_circuit (
Union
[UnivariateVariationalDistribution
,MultivariateVariationalDistribution
,QuantumCircuit
,None
]) – a UnivariateVariationalDistribution for univariate data, a MultivariateVariationalDistribution for multivariate data, or a QuantumCircuit implementing the generator.init_params (
Union
[List
[float
],ndarray
,None
]) – 1D numpy array or list, Initialization for the generator’s parameters.optimizer (
Optional
[Optimizer
]) – optimizer to be used for the training of the generatorsnapshot_dir (
Optional
[str
]) – str or None, if not None save the optimizer’s parameter after every update step to the given directory
- 예외
AquaError – Set multivariate variational distribution to represent multivariate data
Methods
__init__
(bounds, num_qubits[, …])- type bounds
ndarray
construct_circuit
([params])Construct generator circuit.
get_output
(quantum_instance[, params, shots])Get classical data samples from the generator.
loss
(x, weights)Loss function for training the generator’s parameters.
set_discriminator
(discriminator)Set discriminator network.
set_seed
(seed)Set seed.
train
([quantum_instance, shots])Perform one training step w.r.t to the generator’s parameters
-
construct_circuit
(params=None)[소스]¶ Construct generator circuit.
- 매개변수
params (list | dict) – parameters which should be used to run the generator.
- 반환값
construct the quantum circuit and return as gate
- 반환 형식
-
get_output
(quantum_instance, params=None, shots=None)[소스]¶ Get classical data samples from the generator. Running the quantum generator circuit results in a quantum state. To train this generator with a classical discriminator, we need to sample classical outputs by measuring the quantum state and mapping them to feature space defined by the training data.
- 매개변수
quantum_instance (QuantumInstance) – Quantum Instance, used to run the generator circuit.
params (numpy.ndarray) – array or None, parameters which should be used to run the generator, if None use self._params
shots (int) – if not None use a number of shots that is different from the number set in quantum_instance
- 반환값
generated samples, array: sample occurrence in percentage
- 반환 형식
list
-
loss
(x, weights)[소스]¶ Loss function for training the generator’s parameters.
- 매개변수
x (numpy.ndarray) – sample label (equivalent to discriminator output)
weights (numpy.ndarray) – probability for measuring the sample
- 반환값
loss function
- 반환 형식
float
-
set_discriminator
(discriminator)[소스]¶ Set discriminator network.
- 매개변수
discriminator (Discriminator) – Discriminator used to compute the loss function.
-
train
(quantum_instance=None, shots=None)[소스]¶ Perform one training step w.r.t to the generator’s parameters
- 매개변수
quantum_instance (QuantumInstance) – used to run the generator circuit.
shots (int) – Number of shots for hardware or qasm execution.
- 반환값
generator loss(float) and updated parameters (array).
- 반환 형식
dict