Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBM not learning anything - 4 qubit state #145

Open
silvio-sjsj opened this issue Feb 9, 2023 · 0 comments
Open

RBM not learning anything - 4 qubit state #145

silvio-sjsj opened this issue Feb 9, 2023 · 0 comments

Comments

@silvio-sjsj
Copy link

Hi, I am new very new to qucumber, and I was trying to fir a nn_state to a 4qubit state:

GHZ_state_target_real.txt:

0.49999040999999994 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.49999040999999994
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0    
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.49999040999999994 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.49999040999999994

The GHZ_state_target_imag.txt is just a bunch of 0: a 16x16 matrix filled only with zero.

I was following this tutorial on how to reconstruct a density matrix: tutorial density matrix and I just followed it step by step, copying and pasting the code:

#Local path:
local_path = "testes/%s"

train_path = local_path % "train_1x100.txt"
train_bases_path = local_path % "train_bases_1x100.txt"
matrix_path_real = local_path % "GHZ_state_target_real.txt"
matrix_path_imag = local_path % "GHZ_state_target_imag.txt"
bases_path = local_path % "bases_1x100.txt"

train_samples, true_matrix, train_bases, bases = data.load_data_DM(
    train_path, matrix_path_real, matrix_path_imag, train_bases_path, bases_path
) 

unitary_dict = unitaries.create_dict()

nv = train_samples.shape[-1]
nh = na = nv

nn_state = DensityMatrix(
    num_visible=nv, num_hidden=nh, num_aux=na, unitary_dict=unitary_dict, gpu=True
)

period = 100
space = nn_state.generate_hilbert_space()

callbacks = [
    MetricEvaluator(
        period,
        {
            "Fidelity": ts.fidelity,
            "KL": ts.KL,
         },
        target=true_matrix,
        bases=bases,
        verbose=True,
        space=space,
    )
]

epochs = 2500
pbs = 1  # pos_batch_size
nbs = pbs  # neg_batch_size
lr = 0.0001
k = 10
lr_drop_epoch = 125
lr_drop_factor = 0.5

nn_state.fit(
    data=train_samples,
    input_bases=train_bases,
    epochs=epochs,
    pos_batch_size=pbs,
    neg_batch_size=nbs,
    lr=lr,
    k=k,
    bases=bases,
    callbacks=callbacks,
    time=True,
    optimizer=torch.optim.Adadelta,
    scheduler=torch.optim.lr_scheduler.StepLR,
    scheduler_args={"step_size": lr_drop_epoch, "gamma": lr_drop_factor},
)

Just like in the tutorial, except for some parameters like learning rate and all that stuff.

A sample of my data:

train_1x100.txt:
0 0 0 0
0 0 0 0
0 0 0 0
...
1 1 1 1
1 1 1 1 
0 0 0 0

train_bases_1x100.txt:
ZZZZ
ZZZZ
....
ZZZZ
ZZZZ
ZZZZ

bases_1x100.txt:
ZZZZ

I am using only ZZZZ bases for now, but I tried with some different ones. My problem is: the network is not learning!

The output of the training:

Epoch: 100	Fidelity = 0.102745	KL = 2.229425
Epoch: 200	Fidelity = 0.102765	KL = 2.229175
Epoch: 300	Fidelity = 0.102770	KL = 2.229112
Epoch: 400	Fidelity = 0.102771	KL = 2.229096
Epoch: 500	Fidelity = 0.102771	KL = 2.229093
Epoch: 600	Fidelity = 0.102772	KL = 2.229092
Epoch: 700	Fidelity = 0.102772	KL = 2.229091
Epoch: 800	Fidelity = 0.102772	KL = 2.229091
Epoch: 900	Fidelity = 0.102772	KL = 2.229091
Epoch: 1000	Fidelity = 0.102772	KL = 2.229091
....
Epoch: 2300	Fidelity = 0.102772	KL = 2.229091
Epoch: 2400	Fidelity = 0.102772	KL = 2.229091 
Epoch: 2500	Fidelity = 0.102772	KL = 2.229091

I tried epochs = 2500, 5000, 10000 but it always converges very first to a very low Fidelity and stuck with it til the end.
I also tried different lr, k, pbs etc but it is always the same thing.

The tutorial that I am following is for a 2 qubit state, but now I am trying to learn a 4 qubit and I am not sure if I need to change something in the code. If so: what? if not: what am I doing wrong.

Any help will very, very useful! Really.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant