%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from qiskit import Aer
from qiskit.aqua import QuantumInstance
from qiskit.aqua.algorithms import QGAN

np.random.seed(2020)
N = 1000

real_data = np.random.binomial(3,0.5,N)
plt.hist(real_data, bins = 4);

n = 2
num_qubits = [n]
num_epochs = 100
batch_size = 100
bounds = [0,3]
qgan = QGAN(data = real_data, 
            num_qubits = num_qubits, 
            batch_size = batch_size, 
            num_epochs = num_epochs,
            bounds = bounds,
            seed = 2020)
quantum_instance = QuantumInstance(backend=Aer.get_backend('statevector_simulator'))
result = qgan.run(quantum_instance)
samples_g, prob_g = qgan.generator.get_output(qgan.quantum_instance, shots=10000)
plt.hist(range(4), weights = prob_g, bins = 4);

plt.title("Loss function evolution")
plt.plot(range(num_epochs), qgan.g_loss, label='Generator')
plt.plot(range(num_epochs), qgan.d_loss, label='Discriminator')
plt.legend()
plt.show()

plt.title('Relative entropy evolution')
plt.plot(qgan.rel_entr)
plt.show()

import qiskit
qiskit.__qiskit_version__