示例#1
0
from effective_dimension import Model, EffectiveDimension, QuantumNeuralNetwork
from qiskit.circuit.library import ZZFeatureMap, RealAmplitudes
import numpy as np

# this code generates the data for the quantum neural network model's effective dimension in the main text figure

n = [1000, 2000, 8000, 10000, 40000, 60000, 100000, 150000, 200000, 500000, 1000000]
blocks = 9
###################################################################################
num_qubits = 4
num_inputs = 100
num_thetas = 100
fm = ZZFeatureMap(feature_dimension=num_qubits, reps=2)
circ = RealAmplitudes(num_qubits, reps=blocks)
qnet = QuantumNeuralNetwork(var_form=circ, feature_map=fm)
ed = EffectiveDimension(qnet, num_thetas=num_thetas, num_inputs=num_inputs)
f, trace = ed.get_fhat()
effdim = ed.eff_dim(f, n)
np.save("4qubits_9layer_f_hats_dep2.npy", f)
np.save("4qubits_9layer_effective_dimension_dep2.npy", effdim)
示例#2
0
from effective_dimension import Model, EffectiveDimension, ClassicalNeuralNetwork
import numpy as np

# this code generates the data for the classical model's fisher information eigenvalue distribution plot \
# in the main figure

nnsize = [4, 4, 4, 2]
cnet = ClassicalNeuralNetwork(nnsize)
num_inputs = 100
num_thetas = 100
ed = EffectiveDimension(cnet, num_thetas=num_thetas, num_inputs=num_inputs)
f, trace = ed.get_fhat()
np.save("fhat4_[4 4 4 2]_fisher.npy", f)
]

size4 = [4, 4, 4, 2]

size6 = [6, 7, 2, 2]

size8 = [8, 8, 2]

size10 = [10, 8, 1, 4, 2]

seeds = [1, 200, 300, 400, 500, 600, 700, 800, 900, 1000]

for j, k in enumerate(seeds):
    for i in range(10, 110, 10):
        cnet = ClassicalNeuralNetwork(size=size4, samples=i)
        ed = EffectiveDimension(cnet, num_thetas=i, num_inputs=i, seed=k)
        f, trace, fishers = ed.get_fhat()
        effdims = ed.eff_dim(f, n)
        np.save(
            "4in_depth9_effective_dimension_samples_%i_seed_%i.npy" % (i, k),
            effdims)
        np.save("4in_depth9_f_hats_samples_%i_seed_%i.npy" % (i, k), f)
        np.save("4in_depth9_trace_samples_%i_seed_%i.npy" % (i, k), trace)
    print("status: model 1 of 4, seed ", j + 1, " of 10 completed")

for j, k in enumerate(seeds):
    for i in range(10, 110, 10):
        cnet = ClassicalNeuralNetwork(size=size6, samples=i)
        ed = EffectiveDimension(cnet, num_thetas=i, num_inputs=i, seed=k)
        f, trace, fishers = ed.get_fhat()
        effdims = ed.eff_dim(f, n)