Validation Set Query
Spin-up/spin-down measurement probabilities on Y-rotated qubit
Spin-up/spin-down measurement probabilities on Y-rotated qubit
In[]:=
Pu[θ_]:=;Pd[θ_]:=1-Pu[θ]
2
Cos
θ
2
Probability normalization check
Probability normalization check
In[]:=
FullSimplify[Pu[θ]+Pd[θ]]
Out[]=
1
Discretize rotation values
Discretize rotation values
In[]:=
theta=Tableθ,θ,,π,
π
50
π
50
Out[]=
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,π
π
50
π
25
3π
50
2π
25
π
10
3π
25
7π
50
4π
25
9π
50
π
5
11π
50
6π
25
13π
50
7π
25
3π
10
8π
25
17π
50
9π
25
19π
50
2π
5
21π
50
11π
25
23π
50
12π
25
π
2
13π
25
27π
50
14π
25
29π
50
3π
5
31π
50
16π
25
33π
50
17π
25
7π
10
18π
25
37π
50
19π
25
39π
50
4π
5
41π
50
21π
25
43π
50
22π
25
9π
10
23π
25
47π
50
24π
25
49π
50
One-hot vectors from discretized theta values
One-hot vectors from discretized theta values
In[]:=
numBins=Length[theta];binToOneHot[bins_List,totalBins_Integer]:=Table[If[i==#,1,0],{i,1,totalBins}]&/@binsbins=Range[numBins];oneHotEncoded=binToOneHot[bins,Length[theta]];
In[]:=
Length[theta]
Out[]=
50
Evaluate measurement probabilities for each theta value
Evaluate measurement probabilities for each theta value
In[]:=
pr=TableList[N[FullSimplify[Re[Pu[θ]]]],N[FullSimplify[Re[Pd[θ]]]]],θ,,π,
π
50
π
50
Out[]=
{{0.999013,0.000986636},{0.996057,0.00394265},{0.991144,0.00885637},{0.984292,0.0157084},{0.975528,0.0244717},{0.964888,0.0351118},{0.952414,0.0475865},{0.938153,0.0618467},{0.922164,0.077836},{0.904508,0.0954915},{0.885257,0.114743},{0.864484,0.135516},{0.842274,0.157726},{0.818712,0.181288},{0.793893,0.206107},{0.767913,0.232087},{0.740877,0.259123},{0.71289,0.28711},{0.684062,0.315938},{0.654508,0.345492},{0.624345,0.375655},{0.593691,0.406309},{0.562667,0.437333},{0.531395,0.468605},{0.5,0.5},{0.468605,0.531395},{0.437333,0.562667},{0.406309,0.593691},{0.375655,0.624345},{0.345492,0.654508},{0.315938,0.684062},{0.28711,0.71289},{0.259123,0.740877},{0.232087,0.767913},{0.206107,0.793893},{0.181288,0.818712},{0.157726,0.842274},{0.135516,0.864484},{0.114743,0.885257},{0.0954915,0.904508},{0.077836,0.922164},{0.0618467,0.938153},{0.0475865,0.952414},{0.0351118,0.964888},{0.0244717,0.975528},{0.0157084,0.984292},{0.00885637,0.991144},{0.00394265,0.996057},{0.000986636,0.999013},{0.,1.}}
In[]:=
Length[pr]
Out[]=
50
Generate training measurement outcomes for each θj (with random number generator) - 1 represents spin-up outcome and 0 spin-down
Generate training measurement outcomes for each (with random number generator) - 1 represents spin-up outcome and 0 spin-down
θ
j
Number of measurements for each in (0,π)
θ
j
In[]:=
m=10000;
In[]:=
meas=Table[{},{Length[pr]}];Table[Do[b=ConstantArray[0,1];Clear[r];updateTally[]:=Block[{r},r=RandomReal[];If[r<pr[[j]][[1]],b[[1]]+=1,If[pr[[j]][[1]]<=r<pr[[j]][[1]]+pr[[j]][[2]],b[[1]]+=0]]];Do[updateTally[],{1}];AppendTo[meas[[j]],b],{i,1,m}],{j,Length[pr]}];
Generated training measurement outcomes for each
θ
j
In[]:=
meas=Partition[Flatten[meas],m];
In[]:=
(*Functiontocount1sand0s*)countOnesZeros[list_]:={Count[list,1],Count[list,0]}
Training data for neural network
Training data for neural network
Simulated Measurements Outcomes for each θj in (0,π)
Simulated Measurements Outcomes for each in (0,π)
θ
j
In[]:=
meas=Map[countOnesZeros,meas]
Out[]=
{{9988,12},{9956,44},{9900,100},{9846,154},{9762,238},{9642,358},{9519,481},{9378,622},{9222,778},{9060,940},{8876,1124},{8672,1328},{8403,1597},{8187,1813},{7955,2045},{7696,2304},{7410,2590},{7113,2887},{6789,3211},{6602,3398},{6226,3774},{5830,4170},{5728,4272},{5336,4664},{5043,4957},{4717,5283},{4349,5651},{4010,5990},{3720,6280},{3437,6563},{3124,6876},{2826,7174},{2621,7379},{2287,7713},{2101,7899},{1826,8174},{1599,8401},{1307,8693},{1178,8822},{910,9090},{784,9216},{651,9349},{477,9523},{343,9657},{241,9759},{168,9832},{93,9907},{38,9962},{10,9990},{0,10000}}
Plot of spin-up (blue) and spin-down (green) outcomes for each θj in (0,π)
Plot of spin-up (blue) and spin-down (green) outcomes for each in (0,π)
θ
j
In[]:=
Show[ListPlot[meas[[All,1]]],ListPlot[meas[[All,2]],PlotStyle->Green]]
Out[]=
In[]:=
trainingData=Rule@@@Transpose[{meas,oneHotEncoded}];
In[]:=
trainingData2=Thread[trainingData[[All,1]]->Range[50]]
Out[]=
{{9988,12}1,{9956,44}2,{9900,100}3,{9846,154}4,{9762,238}5,{9642,358}6,{9519,481}7,{9378,622}8,{9222,778}9,{9060,940}10,{8876,1124}11,{8672,1328}12,{8403,1597}13,{8187,1813}14,{7955,2045}15,{7696,2304}16,{7410,2590}17,{7113,2887}18,{6789,3211}19,{6602,3398}20,{6226,3774}21,{5830,4170}22,{5728,4272}23,{5336,4664}24,{5043,4957}25,{4717,5283}26,{4349,5651}27,{4010,5990}28,{3720,6280}29,{3437,6563}30,{3124,6876}31,{2826,7174}32,{2621,7379}33,{2287,7713}34,{2101,7899}35,{1826,8174}36,{1599,8401}37,{1307,8693}38,{1178,8822}39,{910,9090}40,{784,9216}41,{651,9349}42,{477,9523}43,{343,9657}44,{241,9759}45,{168,9832}46,{93,9907}47,{38,9962}48,{10,9990}49,{0,10000}50}
Neural network architecture
Neural network architecture
In[]:=
net2=NetChain[{LinearLayer[300],BatchNormalizationLayer[],ElementwiseLayer["ReLU"],LinearLayer[300],BatchNormalizationLayer[],ElementwiseLayer["ReLU"],LinearLayer[50],SoftmaxLayer[]}];
Training the network
Training the network
In[]:=
trainedNet=NetTrain[net2,trainingData2,MaxTrainingRounds->70000]
Out[]=
NetChain
A Reasonable Way To Implement ValidationSet In The Training Network
A Reasonable Way To Implement ValidationSet In The Training Network
In[]:=
(*trainedNet=NetTrain[net,trainingData2,MaxTrainingRounds->70000,ValidationSet->Scaled[.1]]*)
Example: training data through trained network
Example: training data through trained network
In[]:=
(*Thisisthetrainedmeasurementoutcomesgeneratedpreviously*)
In[]:=
tuplesLeft=Keys[trainingData2]
In[]:=
trainedNet/@tuplesLeft
In[]:=
positions=Range[50]
Out[]=
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50}
In[]:=
Dimensions[trainedNet/@tuplesLeft]
Out[]=
{50,50}
In[]:=
result=MapThread[#[[#2]]&,{trainedNet/@tuplesLeft,positions}]