Commit 2421f6a2 authored by Paul's avatar Paul
Browse files

adding python file to collect phase diagram and annealing schedule from DW

parent d3eb1eed
Loading
Loading
Loading
Loading
+402 −0
Original line number Diff line number Diff line
s	A(s) (GHz)	B(s) (GHz)	C (normalized)
0.000	10.3214800	0.4927432	0.0000000
0.003	10.1947600	0.4988469	0.0078662
0.005	10.0735300	0.5048283	0.0152582
0.008	9.9566560	0.5107309	0.0223571
0.010	9.8419060	0.5166607	0.0292755
0.013	9.7299380	0.5225796	0.0359539
0.015	9.6234840	0.5283326	0.0423123
0.018	9.5186060	0.5341243	0.0485244
0.020	9.4187370	0.5397574	0.0543493
0.023	9.3202780	0.5454268	0.0600967
0.025	9.2256720	0.5509864	0.0655595
0.028	9.1328000	0.5565538	0.0709139
0.030	9.0429910	0.5620444	0.0760155
0.033	8.9550300	0.5675262	0.0810330
0.035	8.8707240	0.5728801	0.0857985
0.038	8.7867280	0.5783139	0.0905454
0.040	8.7069360	0.5835709	0.0949790
0.043	8.6267100	0.5889521	0.0994126
0.045	8.5498400	0.5942003	0.1036648
0.048	8.4735050	0.5995038	0.1078385
0.050	8.3983200	0.6048189	0.1119649
0.053	8.3261550	0.6100082	0.1158929
0.055	8.2536330	0.6153119	0.1198209
0.058	8.1842350	0.6204723	0.1235809
0.060	8.1165870	0.6255852	0.1271923
0.063	8.0486250	0.6308054	0.1308036
0.065	7.9838530	0.6358603	0.1342642
0.068	7.9199730	0.6409239	0.1376382
0.070	7.8558140	0.6460896	0.1410122
0.073	7.7943690	0.6511133	0.1442520
0.075	7.7343550	0.6560944	0.1473755
0.078	7.6740970	0.6611712	0.1504991
0.080	7.6148570	0.6662370	0.1535837
0.083	7.5582940	0.6711451	0.1565006
0.085	7.5015150	0.6761433	0.1594175
0.088	7.4445170	0.6812341	0.1623343
0.090	7.3906850	0.6861107	0.1651024
0.093	7.3380650	0.6909439	0.1677727
0.095	7.2852580	0.6958612	0.1704430
0.098	7.2322640	0.7008645	0.1731133
0.100	7.1815560	0.7057176	0.1756723
0.103	7.1313460	0.7105879	0.1781808
0.105	7.0809670	0.7155403	0.1806892
0.108	7.0304200	0.7205770	0.1831977
0.110	6.9816250	0.7255042	0.1856278
0.113	6.9338150	0.7303957	0.1879854
0.115	6.8858540	0.7353671	0.1903429
0.118	6.8377420	0.7404202	0.1927005
0.120	6.7902810	0.7454705	0.1950433
0.123	6.7457760	0.7502671	0.1972252
0.125	6.7011420	0.7551376	0.1994071
0.128	6.6563790	0.7600837	0.2015890
0.130	6.6114860	0.7651071	0.2037709
0.133	6.5674150	0.7701008	0.2059119
0.135	6.5248620	0.7749826	0.2079538
0.138	6.4821940	0.7799378	0.2099957
0.140	6.4394100	0.7849677	0.2120376
0.143	6.3965090	0.7900741	0.2140795
0.145	6.3544380	0.7951435	0.2160938
0.148	6.3148290	0.7999737	0.2179743
0.150	6.2751220	0.8048725	0.2198547
0.153	6.2353170	0.8098413	0.2217352
0.155	6.1954140	0.8148814	0.2236157
0.158	6.1554130	0.8199943	0.2254961
0.160	6.1165320	0.8250227	0.2273273
0.163	6.0780810	0.8300538	0.2291269
0.165	6.0395400	0.8351556	0.2309266
0.168	6.0009100	0.8403294	0.2327262
0.170	5.9621910	0.8455767	0.2345259
0.173	5.9233820	0.8508989	0.2363255
0.175	5.8870220	0.8559427	0.2380224
0.178	5.8509180	0.8610079	0.2396936
0.180	5.8147370	0.8661411	0.2413649
0.183	5.7784800	0.8713435	0.2430361
0.185	5.7421480	0.8766163	0.2447073
0.188	5.7057400	0.8819610	0.2463785
0.190	5.6703590	0.8872142	0.2480009
0.193	5.6356530	0.8924250	0.2495823
0.195	5.6008800	0.8977042	0.2511638
0.198	5.5660400	0.9030528	0.2527452
0.200	5.5311330	0.9084723	0.2543266
0.203	5.4961590	0.9139638	0.2559080
0.205	5.4611470	0.9195242	0.2574894
0.208	5.4273370	0.9249541	0.2590164
0.210	5.3935110	0.9304472	0.2605394
0.213	5.3596250	0.9360118	0.2620623
0.215	5.3256790	0.9416490	0.2635853
0.218	5.2916730	0.9473603	0.2651082
0.220	5.2576090	0.9531468	0.2666312
0.223	5.2236700	0.9589777	0.2681491
0.225	5.1912230	0.9646152	0.2695952
0.228	5.1587240	0.9703241	0.2710413
0.230	5.1261720	0.9761056	0.2724873
0.233	5.0935700	0.9819608	0.2739334
0.235	5.0609160	0.9878911	0.2753795
0.238	5.0282120	0.9938976	0.2768256
0.240	4.9954590	0.9999817	0.2782716
0.243	4.9637460	1.0059390	0.2796707
0.245	4.9321630	1.0119370	0.2810605
0.248	4.9005360	1.0180100	0.2824503
0.250	4.8688640	1.0241600	0.2838401
0.253	4.8371490	1.0303880	0.2852299
0.255	4.8053910	1.0366950	0.2866196
0.258	4.7735900	1.0430820	0.2880094
0.260	4.7420410	1.0494900	0.2893872
0.263	4.7110580	1.0558550	0.2907384
0.265	4.6800370	1.0622980	0.2920895
0.268	4.6489780	1.0688230	0.2934407
0.270	4.6178820	1.0754300	0.2947919
0.273	4.5867490	1.0821200	0.2961430
0.275	4.5555810	1.0888940	0.2974942
0.278	4.5243770	1.0957550	0.2988454
0.280	4.4935540	1.1026100	0.3001779
0.283	4.4630100	1.1094800	0.3014965
0.285	4.4324350	1.1164370	0.3028152
0.288	4.4018280	1.1234810	0.3041338
0.290	4.3711930	1.1306130	0.3054524
0.293	4.3405280	1.1378350	0.3067710
0.295	4.3098340	1.1451490	0.3080896
0.298	4.2791140	1.1525550	0.3094082
0.300	4.2486060	1.1599960	0.3107171
0.303	4.2182150	1.1674960	0.3120205
0.305	4.1877990	1.1750910	0.3133239
0.308	4.1573600	1.1827810	0.3146273
0.310	4.1268980	1.1905690	0.3159307
0.313	4.0964150	1.1984560	0.3172342
0.315	4.0659120	1.2064430	0.3185376
0.318	4.0353890	1.2145320	0.3198410
0.320	4.0049470	1.2226970	0.3211393
0.323	3.9745540	1.2309490	0.3224344
0.325	3.9441450	1.2393050	0.3237294
0.328	3.9137210	1.2477690	0.3250245
0.330	3.8832840	1.2563410	0.3263196
0.333	3.8528330	1.2650220	0.3276147
0.335	3.8223720	1.2738150	0.3289098
0.338	3.7918990	1.2827210	0.3302049
0.340	3.7613730	1.2917560	0.3315022
0.343	3.7307940	1.3009200	0.3328014
0.345	3.7002100	1.3102020	0.3341005
0.348	3.6696200	1.3196060	0.3353997
0.350	3.6390270	1.3291310	0.3366988
0.353	3.6084310	1.3387800	0.3379980
0.355	3.5778340	1.3485540	0.3392971
0.358	3.5472390	1.3584560	0.3405963
0.360	3.5165650	1.3685120	0.3418990
0.363	3.4857980	1.3787330	0.3432055
0.365	3.4550360	1.3890880	0.3445120
0.368	3.4242810	1.3995790	0.3458185
0.370	3.3935360	1.4102080	0.3471249
0.373	3.3628000	1.4209760	0.3484314
0.375	3.3320770	1.4318850	0.3497379
0.378	3.3013680	1.4429380	0.3510444
0.380	3.2704340	1.4542240	0.3523621
0.383	3.2392060	1.4657750	0.3536914
0.385	3.2079990	1.4774820	0.3550207
0.388	3.1768140	1.4893440	0.3563500
0.390	3.1456540	1.5013640	0.3576792
0.393	3.1145210	1.5135450	0.3590085
0.395	3.0834180	1.5258880	0.3603378
0.398	3.0523450	1.5383950	0.3616671
0.400	3.0209480	1.5512150	0.3630137
0.403	2.9893160	1.5643210	0.3643706
0.405	2.9577240	1.5776040	0.3657275
0.408	2.9261740	1.5910660	0.3670843
0.410	2.8946700	1.6047090	0.3684412
0.413	2.8632140	1.6185350	0.3697981
0.415	2.8318090	1.6325470	0.3711550
0.418	2.8004570	1.6467460	0.3725118
0.420	2.7684270	1.6614730	0.3739021
0.423	2.7363310	1.6764620	0.3752953
0.425	2.7043010	1.6916550	0.3766884
0.428	2.6723400	1.7070530	0.3780815
0.430	2.6404510	1.7226600	0.3794747
0.433	2.6086380	1.7384770	0.3808678
0.435	2.5769030	1.7545050	0.3822609
0.438	2.5449410	1.7709070	0.3836708
0.440	2.5124920	1.7878310	0.3851042
0.443	2.4801380	1.8049850	0.3865376
0.445	2.4478810	1.8223700	0.3879710
0.448	2.4157260	1.8399890	0.3894044
0.450	2.3836780	1.8578440	0.3908378
0.453	2.3517390	1.8759350	0.3922712
0.455	2.3198460	1.8943030	0.3937107
0.458	2.2869850	1.9135560	0.3951947
0.460	2.2542360	1.9330810	0.3966787
0.463	2.2216220	1.9528660	0.3981627
0.465	2.1891500	1.9729140	0.3996468
0.468	2.1568230	1.9932250	0.4011308
0.470	2.1246460	2.0138010	0.4026148
0.473	2.0925850	2.0346680	0.4041024
0.475	2.0597630	2.0564170	0.4056350
0.478	2.0270840	2.0784720	0.4071675
0.480	1.9945860	2.1008110	0.4087000
0.483	1.9622730	2.1234350	0.4102325
0.485	1.9301510	2.1463440	0.4117650
0.488	1.8982260	2.1695380	0.4132975
0.490	1.8663370	2.1931400	0.4148415
0.493	1.8338860	2.2176170	0.4164195
0.495	1.8016600	2.2423950	0.4179975
0.498	1.7696660	2.2674730	0.4195755
0.500	1.7379080	2.2928510	0.4211536
0.503	1.7063930	2.3185260	0.4227316
0.505	1.6751260	2.3444970	0.4243096
0.508	1.6435430	2.3712470	0.4259201
0.510	1.6117570	2.3987160	0.4275499
0.513	1.5802540	2.4264940	0.4291797
0.515	1.5490410	2.4545790	0.4308095
0.518	1.5181220	2.4829680	0.4324394
0.520	1.4875040	2.5116570	0.4340692
0.523	1.4570350	2.5407910	0.4357125
0.525	1.4258920	2.5711990	0.4374065
0.528	1.3950910	2.6019160	0.4391004
0.530	1.3646390	2.6329390	0.4407944
0.533	1.3345400	2.6642610	0.4424883
0.535	1.3048000	2.6958770	0.4441823
0.538	1.2754020	2.7278050	0.4458787
0.540	1.2453150	2.7612010	0.4476399
0.543	1.2155630	2.7949730	0.4494012
0.545	1.1862200	2.8290340	0.4511624
0.548	1.1572910	2.8633760	0.4529236
0.550	1.1287820	2.8979900	0.4546848
0.553	1.1006620	2.9329080	0.4564503
0.555	1.0723690	2.9688530	0.4582539
0.558	1.0445080	3.0050810	0.4600576
0.560	1.0171020	3.0415550	0.4618613
0.563	0.9901544	3.0782650	0.4636649
0.565	0.9636674	3.1152000	0.4654686
0.568	0.9374440	3.1526330	0.4672911
0.570	0.9109903	3.1913170	0.4691569
0.573	0.8850369	3.2302070	0.4710228
0.575	0.8595852	3.2692890	0.4728886
0.578	0.8346360	3.3085520	0.4747544
0.580	0.8101895	3.3479820	0.4766203
0.583	0.7857143	3.3884510	0.4785347
0.585	0.7614481	3.4296150	0.4804700
0.588	0.7377197	3.4709180	0.4824053
0.590	0.7145274	3.5123450	0.4843406
0.593	0.6918690	3.5538830	0.4862759
0.595	0.6696426	3.5957060	0.4882234
0.598	0.6475893	3.6383210	0.4901996
0.600	0.6260833	3.6810100	0.4921758
0.603	0.6051205	3.7237590	0.4941521
0.605	0.5846962	3.7665550	0.4961283
0.608	0.5648035	3.8093880	0.4981049
0.610	0.5448362	3.8535890	0.5001497
0.613	0.5253721	3.8979230	0.5021946
0.615	0.5064591	3.9422540	0.5042394
0.618	0.4880901	3.9865680	0.5062842
0.620	0.4702570	4.0308530	0.5083290
0.623	0.4525460	4.0761470	0.5104273
0.625	0.4352829	4.1215380	0.5125321
0.628	0.4185607	4.1668460	0.5146369
0.630	0.4023698	4.2120850	0.5167417
0.633	0.3867000	4.2571210	0.5188464
0.635	0.3712140	4.3029840	0.5210031
0.638	0.3561886	4.3489930	0.5231640
0.640	0.3416782	4.3949360	0.5253249
0.643	0.3276712	4.4407970	0.5274859
0.645	0.3141369	4.4865250	0.5296526
0.648	0.3007151	4.5334710	0.5318817
0.650	0.2877687	4.5803880	0.5341108
0.653	0.2753064	4.6271820	0.5363399
0.655	0.2633152	4.6738420	0.5385690
0.658	0.2517204	4.7206060	0.5408142
0.660	0.2404393	4.7677980	0.5430841
0.663	0.2296051	4.8148240	0.5453540
0.665	0.2192040	4.8616770	0.5476239
0.668	0.2092226	4.9083510	0.5498938
0.670	0.1994386	4.9558690	0.5522203
0.673	0.1899745	5.0036670	0.5545620
0.675	0.1809147	5.0512630	0.5569037
0.678	0.1722451	5.0986530	0.5592455
0.680	0.1639106	5.1460710	0.5616045
0.683	0.1558090	5.1940910	0.5640001
0.685	0.1480724	5.2418940	0.5663956
0.688	0.1406869	5.2894790	0.5687911
0.690	0.1336391	5.3368480	0.5711867
0.693	0.1268121	5.3847390	0.5736242
0.695	0.1202899	5.4325380	0.5760636
0.698	0.1140775	5.4801160	0.5785031
0.700	0.1081621	5.5274770	0.5809425
0.703	0.1024473	5.5753310	0.5834259
0.705	0.0969532	5.6235150	0.5859309
0.708	0.0917335	5.6714770	0.5884359
0.710	0.0867762	5.7192210	0.5909408
0.713	0.0820268	5.7671830	0.5934752
0.715	0.0774584	5.8156180	0.5960395
0.718	0.0731289	5.8638350	0.5986038
0.720	0.0690270	5.9118370	0.6011681
0.723	0.0651172	5.9599310	0.6037548
0.725	0.0613651	6.0085030	0.6063726
0.728	0.0578174	6.0568630	0.6089904
0.730	0.0544639	6.1050140	0.6116082
0.733	0.0512729	6.1533280	0.6142530
0.735	0.0482116	6.2022340	0.6169344
0.738	0.0453226	6.2509230	0.6196158
0.740	0.0425985	6.2994070	0.6222972
0.743	0.0400106	6.3480640	0.6250053
0.745	0.0375467	6.3970660	0.6277376
0.748	0.0352277	6.4458660	0.6304699
0.750	0.0330457	6.4944700	0.6332021
0.753	0.0309659	6.5435320	0.6359792
0.755	0.0289935	6.5928730	0.6387756
0.758	0.0271417	6.6420180	0.6415721
0.760	0.0254036	6.6909700	0.6443685
0.763	0.0237493	6.7404390	0.6472116
0.765	0.0221947	6.7898550	0.6500566
0.768	0.0207381	6.8390800	0.6529017
0.770	0.0193701	6.8882470	0.6557603
0.773	0.0180720	6.9379130	0.6586532
0.775	0.0168580	6.9873910	0.6615461
0.778	0.0157228	7.0366830	0.6644389
0.780	0.0146484	7.0864100	0.6673768
0.783	0.0136352	7.1364760	0.6703369
0.785	0.0126898	7.1863560	0.6732969
0.788	0.0118067	7.2361260	0.6762659
0.790	0.0109681	7.2866580	0.6792913
0.793	0.0101864	7.3370710	0.6823167
0.795	0.0094589	7.3872990	0.6853420
0.798	0.0087767	7.4377400	0.6883970
0.800	0.0081385	7.4883230	0.6914659
0.803	0.0075456	7.5387230	0.6945348
0.805	0.0069934	7.5890610	0.6976180
0.808	0.0064736	7.6399370	0.7007396
0.810	0.0059915	7.6906310	0.7038612
0.813	0.0055445	7.7411440	0.7069828
0.815	0.0051228	7.7923900	0.7101693
0.818	0.0047307	7.8437080	0.7133612
0.820	0.0043679	7.8948450	0.7165531
0.823	0.0040302	7.9461250	0.7197715
0.825	0.0037164	7.9975340	0.7230044
0.828	0.0034265	8.0487620	0.7262374
0.830	0.0031572	8.1000990	0.7294980
0.833	0.0029051	8.1520370	0.7327979
0.835	0.0026728	8.2037930	0.7360978
0.838	0.0024583	8.2554710	0.7394109
0.840	0.0022581	8.3076730	0.7427647
0.843	0.0020739	8.3597110	0.7461185
0.845	0.0019042	8.4116260	0.7494798
0.848	0.0017459	8.4641530	0.7528931
0.850	0.0016004	8.5165730	0.7563064
0.853	0.0014667	8.5688440	0.7597239
0.855	0.0013421	8.6217790	0.7632026
0.858	0.0012278	8.6746440	0.7666813
0.860	0.0011229	8.7273420	0.7701624
0.863	0.0010260	8.7803800	0.7736815
0.865	0.0009373	8.8333100	0.7772005
0.868	0.0008560	8.8860980	0.7807252
0.870	0.0007806	8.9395110	0.7843094
0.873	0.0007116	8.9928380	0.7878936
0.875	0.0006486	9.0460600	0.7914884
0.878	0.0005903	9.0999000	0.7951353
0.880	0.0005370	9.1536210	0.7987822
0.883	0.0004885	9.2072460	0.8024415
0.885	0.0004439	9.2611900	0.8061296
0.888	0.0004033	9.3149490	0.8098177
0.890	0.0003662	9.3688210	0.8135369
0.893	0.0003321	9.4231720	0.8172915
0.895	0.0003011	9.4773340	0.8210462
0.898	0.0002727	9.5317580	0.8248419
0.900	0.0002469	9.5864020	0.8286568
0.903	0.0002234	9.6408540	0.8324717
0.905	0.0002020	9.6957280	0.8363384
0.908	0.0001825	9.7505800	0.8402083
0.910	0.0001648	9.8053540	0.8440944
0.913	0.0001487	9.8607450	0.8480320
0.915	0.0001340	9.9159820	0.8519697
0.918	0.0001208	9.9712720	0.8559327
0.920	0.0001088	10.0266900	0.8599140
0.923	0.0000980	10.0819200	0.8638953
0.925	0.0000881	10.1377600	0.8679458
0.928	0.0000791	10.1936200	0.8719994
0.930	0.0000711	10.2494400	0.8760729
0.933	0.0000638	10.3056300	0.8801795
0.935	0.0000572	10.3616200	0.8842861
0.938	0.0000513	10.4178300	0.8884311
0.940	0.0000460	10.4740400	0.8925840
0.943	0.0000412	10.5301900	0.8967583
0.945	0.0000368	10.5869000	0.9009797
0.948	0.0000329	10.6434100	0.9052011
0.950	0.0000294	10.7003500	0.9094815
0.953	0.0000262	10.7574100	0.9137736
0.955	0.0000234	10.8144000	0.9180851
0.958	0.0000208	10.8716900	0.9224256
0.960	0.0000186	10.9287700	0.9267661
0.963	0.0000165	10.9862000	0.9311582
0.965	0.0000147	11.0435400	0.9355507
0.968	0.0000131	11.1010600	0.9399859
0.970	0.0000116	11.1588400	0.9444484
0.973	0.0000103	11.2165000	0.9489248
0.975	0.0000091	11.2745400	0.9534390
0.978	0.0000081	11.3324000	0.9579532
0.980	0.0000072	11.3907800	0.9625390
0.983	0.0000064	11.4491500	0.9671284
0.985	0.0000056	11.5075700	0.9717468
0.988	0.0000050	11.5660400	0.9763794
0.990	0.0000044	11.6245100	0.9810431
0.993	0.0000039	11.6834600	0.9857505
0.995	0.0000034	11.7422500	0.9904692
0.998	0.0000030	11.8014400	0.9952346
1.000	0.0000026	11.8604700	1.0000000
+234 −0
Original line number Diff line number Diff line
from dwave.cloud import Client
from Embeddings import tilt_embedding, half_cell_embedding
from Drawing import *
from Drivers import *
from Analysis import *

import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.ticker import FormatStrFormatter
import seaborn as sns
import pandas as pd
import numpy as np
import pickle
import networkx as nx
from itertools import product
import os

import warnings
warnings.filterwarnings('ignore')

from concurrent.futures import as_completed, ProcessPoolExecutor

# Get the solver
#ep = '44.230.13.66/sapi'
ep = '54.201.1.180/sapi'
endpoint = 'https://{}/'.format(ep)

client = Client.from_config(endpoint=endpoint,permissive_ssl=True)
client.session.headers.update({'host': 'cloud.dwavesys.com'})
solver = client.get_solver('DW_2000Q_5')
client.close()

# Build the embedding

unpruned_embedding = half_cell_embedding(solver=solver, shift=0)
emb = prune_shastry_sutherland(unpruned_embedding)

ax, pos = draw_logical(emb, shift=0, reference='square')

initial_state = FM_initial_state(emb,solver)
init_state_name = 'FM'

J1_mag = 1
factor_step = 0.2
h_step = 0.04

factors = np.round(np.arange(0,3 + factor_step,factor_step),5)
h_targets = np.round(np.arange(-2,0 + h_step,h_step),5)

mesh_points = list(product(factors,h_targets))

raw_inputs = [(J1_mag,J1_mag*factor,-4,h) for factor,h in mesh_points]
chi = -0.03
inputs = [get_inputs_from_logical(J1, J2, J3, h, chi) for (J1,J2,J3,h) in raw_inputs]
check_inputs_ranges(inputs)

J_inputs = []
for (J1,J2,J3,h) in inputs:
    if (J1,J2,J3) in J_inputs:
        pass
    else:
        J_inputs.append((J1,J2,J3))

shift = 0
emb_name = 'halfcell'
sampling_parameters = {'annealing_time': 500,
                       'num_reads': 500,
                       'readout_thermalization': 500,
                       'answer_mode': 'histogram',
                       'auto_scale': False
                      }

fbos={}

t_pause=1998

def parameter_gen(s):
    
    return {'num_reads': 100,
                         'readout_thermalization': 100,
                         'answer_mode': 'raw', 
                         'reinitialize_state' : False,
                         'anneal_schedule' : [[0,1],[1, s],[t_pause+1,s],[t_pause+2,1]],
                         'initial_state' : initial_state,
                         'auto_scale': False}

s = 0.4
mode=2
field_steps = [*([0.04]*100), *([0.02]*100), *([0.01]*100)]
h_mags = [inp[3] for inp in inputs]
anneal_mode = 'quench' if mode==2 else 'ramp'
init_state_name = 'FM'


boundary_iters = 400
fbo_iters = 200

def run_save_fbo(J1,J2,J3):
    try:
        bias_df = pd.read_pickle('./fbo_data/Phase_Diagram/calibration_fbo_{J1}_{J2}_{J3}_{emb}_{shift}.p'.format(J1=J1, J2=J2, J3=J3,emb=emb_name, shift=shift))
        mag_df = pd.read_pickle('./fbo_data/Phase_Diagram/calibration_mag_{J1}_{J2}_{J3}_{emb}_{shift}.p'.format(J1=J1, J2=J2, J3=J3,emb=emb_name, shift=shift))
        fbo = bias_df.iloc[-1,:].values.tolist()
        del bias_df
        del mag_df
        return fbo
    except:
        pass
    
    with Client.from_config(endpoint=endpoint,connection_close=True,permissive_ssl=True,request_timeout=360) as client:
        client.session.headers.update({'host': 'cloud.dwavesys.com'})
        solver = client.get_solver('DW_2000Q_5')
        bias_df, mag_df, used_qubits = calibrate_offsets(emb, solver, sampling_parameters, J1, J2, J3, iters=fbo_iters)
        
    bias_df.to_pickle('./fbo_data/Phase_Diagram/calibration_fbo_{J1}_{J2}_{J3}_{emb}_{shift}.p'.format(J1=J1, J2=J2, J3=J3,emb=emb_name, shift=shift))
    mag_df.to_pickle('./fbo_data/Phase_Diagram/calibration_mag_{J1}_{J2}_{J3}_{emb}_{shift}.p'.format(J1=J1, J2=J2, J3=J3,emb=emb_name, shift=shift))
    
    fbo = bias_df.iloc[-1,:].values.tolist()
    del bias_df
    del mag_df
    del used_qubits
    return fbo

def run_boundary_shim(J1,J2,J3,h,fbos):
    
    savename = './RA_Data/Phase_Diagram/{J1}_{J2}_{J3}_{h}_{anneal_mode}_{s}_{init_state_name}_{emb_name}'.format(J1=J1,J2=J2, J3=J3, \
                                                                                                                  h=h, anneal_mode='quench',s=0.4, init_state_name='FM',\
                                                                                                                  emb_name='halfcell')
    directory_path = './RA_Data/Phase_Diagram/'
    basename = '{J1}_{J2}_{J3}_{h}_{anneal_mode}_{s}_{init_state_name}_{emb_name}.npz'.format(J1=J1,J2=J2, J3=J3, \
                                                                                                                h=h, anneal_mode='quench',s=0.4, init_state_name='FM',\
                                                                                                            emb_name='halfcell')
    savename = directory_path+basename
    print('({},{},{},{}) Boundary Shim Started'.format(J1,J2,J3,h))
    if basename in os.listdir(directory_path):
        return (0,0)
    
    
    
    with Client.from_config(endpoint=endpoint,connection_close=True,permissive_ssl=True,request_timeout=360) as client:
        client.session.headers.update({'host': 'cloud.dwavesys.com'})
        solver = client.get_solver('DW_2000Q_5')
        result = boundary_shim_driver(emb, solver, flux_biases=fbos, sampling_parameters=parameter_gen(s), \
                                      J1_mag=J1, J2_mag=J2, J3_mag=J3, h_mag = h, max_iters=boundary_iters, \
                                      field_steps=field_steps, burn_in=50, num_calls=10, num_final_calls=100, grad_tol=0.0005)
    
    np.savez(savename, fields=result[0].values, mags=result[1].values, qubits=result[2], solution_array=result[3])
    del result
    #print('saved')
    return (0,0)




if __name__ == '__main__':
   
    n_procs = len(J_inputs) if len(J_inputs)<10 else 10
    with ProcessPoolExecutor(n_procs) as executor:
        results = [executor.submit(run_save_fbo,*x) for x in J_inputs]
        print('Start FBO Calibration')
        print('--------------------------------\n')
        for (x,result) in zip(J_inputs,results):
            result._x = x
        for r in as_completed(results):
            if r.exception:
                print(r.exception())
            result = r.result()
            for h in h_mags:
                fbos[(*r._x,h)] = result
                
            print('{} FBO Calibration Completed'.format(r._x))
        print('--------------------------------\n')
        print('End FBO Calibration\n')
    
    n_procs = len(inputs) if len(inputs)<15 else 15
    with ProcessPoolExecutor(n_procs) as executor:
        results = [executor.submit(run_boundary_shim,*(*x,fbos[x])) for x in inputs]
        print('Start Boundary Shim')
        print('--------------------------------\n')
        for (x,result) in zip(inputs,results):
            result._x = x
        for r in as_completed(results):
            if r.exception():
                print(r.exception())
                print('Local Error')
            print('{} Boundary Shim Completed'.format(r._x))
        print('--------------------------------\n')
        print('End Boundary Shim\n')

#     for (J1,J2,J3,h), fbo in zip(inputs, fbos):
#         client = Client.from_config(connection_close=True)
#         solver = client.get_solver('DW_2000Q_5')
#         savename = './RA_Data/full_calibration/{J1}_{J2}_{J3}_{h}_{anneal_mode}_{s}_{init_state_name}_{emb_name}'.format(J1=J1_mag_target,J2=J2_mag_target, J3=J3_mag_target, \
#                                                                                                                 h=h_mag_target, anneal_mode=anneal_mode,s=s, init_state_name=init_state_name,\
#                                                                                                                 emb_name=emb_name)
#         print(savename.split('/')[-1]+'.npz' in os.listdir('./RA_Data/Phase_Diagram/'))
#         if savename.split('/')[-1]+'.npz' in os.listdir('./RA_Data/Phase_Diagram/'):
#             print(savename)
#             client.close()
#             continue

#         field_df, mag_df, qubits, solution = boundary_shim_driver(emb, solver, flux_biases=fbo, sampling_parameters=ra_sampling_parameters, \
#                                                           J1_mag=J1_mag_target, J2_mag=J2_mag_target, J3_mag=J3_mag_target, h_mag = h_mag_target, max_iters=400, \
#                                                           field_steps=field_steps, burn_in=50, num_calls=10, num_final_calls=200, grad_tol=0.0005)
#         client.close()
#         np.savez(savename, fields=field_df.values, mags=mag_df.values, qubits=qubits, solution_array=solution)

#     Sqs = {}

#     for J1_mag_target, J2_mag_target, J3_mag_target, h_mag_target in sorted(inputs):
#         basename = '{J1}_{J2}_{J3}_{h}_{anneal_mode}_{s}_{init_state_name}_{emb_name}'.format(J1=J1_mag_target,J2=J2_mag_target, J3=J3_mag_target, \
#                                                                                                                 h=h_mag_target, anneal_mode=anneal_mode,s=s, init_state_name=init_state_name,\
#                                                                                                                 emb_name=emb_name)
#         if savename.split('/')[-1]+'.npz' in os.listdir('./RA_Data/full_calibration/'):
#             file = np.load('./RA_Data/Phase_Diagram/' + basename + '.npz')
#         else:
#             print(f'{basename} Not Found')
#             continue
#         if  basename+'.npz' in os.listdir('./Sq_Data/RA/Phase_Diagram'):
#             Sqs[h_mag_target] = np.load('./Sq_Data/RA/Phase_Diagram/'+basename+'.npz')['Sq']
#             print('done')
#             continue
#         else:
#             print(f'{basename} Sq not found')
#         file = np.load('./RA_Data/full_calibration/' + basename + '.npz')
#         qubits = file['qubits']
#         field_df = pd.DataFrame(columns=qubits, data=file['fields'])
#         mag_df = pd.DataFrame(columns=qubits, data=file['mags'])
#         solution_array = file['solution_array']
#         file.close()
#         q1, q2, sq = get_structure_factor(emb, solution_array, positions=pos, num_q_points=100, burn_in=50)
#         Sqs[h_mag_target] = sq
#         print(basename)
#         np.savez_compressed('./Sq_Data/RA/full_calibration/'+basename+'.npz', q1=q1, q2=q2, Sq=sq)