Ejemplo n.º 1
0
    return tf.nn.l2_loss(regularized_params)


X_train = np.array([[0, 1], [0, 2], [0, 3], [0, 4]])

hyperparams = {
    'circuit': circuit,
    'task': 'unsupervised',
    'optimizer': 'SGD',
    'init_learning_rate': 0.1,
    'loss': myloss,
    'regularizer': myregularizer,
    'regularization_strength': 0.1
}

learner = CircuitLearner(hyperparams=hyperparams)

learner.train_circuit(X=X_train, steps=steps)

outcomes = learner.run_circuit()
final_distribution = outcomes['outputs']

# Use a helper function to sample fock states from this state.
# They should show a similar distribution to the training data
for i in range(10):
    sample = sample_from_distribution(distribution=final_distribution)
    print("Fock state sample {}:{} \n".format(i, sample))

# Print out the final circuit parameters
learner.get_circuit_parameters(only_print=True)
Ejemplo n.º 2
0
 def test_samplefromdistr_returns_sample(self):
     desired_result = np.array([0, 1])
     self.assertAlmostEqualArray(
         sample_from_distribution(self.distribution), desired_result)