Example #1
0
    def test_uniform(self):
        """Test the circuit of the uniform distribution is a simple layer of Hadamards."""
        circuit = UniformDistribution(3)
        expected = QuantumCircuit(3)
        expected.h([0, 1, 2])

        self.assertEqual(circuit.decompose(), expected)
Example #2
0
    def setUp(self):
        super().setUp()

        self.seed = 7
        algorithm_globals.random_seed = self.seed
        # Number training data samples
        n_v = 5000
        # Load data samples from log-normal distribution with mean=1 and standard deviation=1
        m_u = 1
        sigma = 1
        self._real_data = algorithm_globals.random.lognormal(mean=m_u,
                                                             sigma=sigma,
                                                             size=n_v)
        # Set upper and lower data values as list of k
        # min/max data values [[min_0,max_0],...,[min_k-1,max_k-1]]
        self._bounds = [0., 3.]
        # Set number of qubits per data dimension as list of k qubit values[#q_0,...,#q_k-1]
        num_qubits = [2]
        # Batch size
        batch_size = 100
        # Set number of training epochs
        # num_epochs = 10
        num_epochs = 5

        # Initialize qGAN
        self.qgan = QGAN(self._real_data,
                         self._bounds,
                         num_qubits,
                         batch_size,
                         num_epochs,
                         snapshot_dir=None)
        self.qgan.seed = 7
        # Set quantum instance to run the quantum generator
        self.qi_statevector = QuantumInstance(
            backend=BasicAer.get_backend('statevector_simulator'),
            seed_simulator=2,
            seed_transpiler=2)
        self.qi_qasm = QuantumInstance(
            backend=BasicAer.get_backend('qasm_simulator'),
            shots=1000,
            seed_simulator=2,
            seed_transpiler=2)
        # Set entangler map
        entangler_map = [[0, 1]]

        qc = UniformDistribution(sum(num_qubits))

        ansatz = RealAmplitudes(sum(num_qubits),
                                reps=1,
                                entanglement=entangler_map)
        qc.compose(ansatz, inplace=True)
        self.generator_circuit = qc
Example #3
0
# Initialize qGAN
iqgan = IQGAN(
    real_data,
    target_rel_ent,
    num_qubits,
    bounds,
    batch_size,
    freq_storage=freq_storage,
    verbose=False,
    max_data_length=max_data_length,
    prob_data_real=unknown_target_data_prob,
    quantum_instance=quantum_instance
)

# Set an initial state for the generator circuit
init_dist = UniformDistribution(sum(num_qubits))
# Generator's depth
k = 2
# Set the ansatz circuit
var_form = TwoLocal(int(np.sum(num_qubits)), 'ry', 'cz', reps=k)
# Generator's initial parameters
#init_params = [0.02789928, 0.02950349, 0.35598046, 0.24428748, 0.02875957, 0.02955343] #lognormal 1 1 (ent=0.001)
#init_params = [0.01436921, 0.02010115, 0.45493457, 0.32251614, 0.0178407,  0.02214568] #lognormal 1 1 (ent=0.1)
init_params = np.zeros(np.sum(num_qubits)*(k+1))
# Set generator circuit by adding the initial distribution infront of the ansatz
g_circuit = var_form.compose(init_dist, front=True)

print('Generator circuit:')
print(g_circuit)
print('')