-
Notifications
You must be signed in to change notification settings - Fork 2
/
vqd.wl
2840 lines (2546 loc) · 98.9 KB
/
vqd.wl
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* ::Package:: *)
(* @file
* Virtual quantum device package.
* Requires QuESTlink
* @author Cica Gustiani
*)
BeginPackage["VQD`"];
(*
NOTE&TODO
1) Pausing the process does not always give the correct behaviour for the following reasons:
a) it doesn't remember previous circuit
b) the time starts from 0. Solution: use globaltime
2) Write assertions + formatter for the Options on each device
*)
(** Devices **)
(*silicon devices*)
(*
SiliconDelft2::usage = "Returns device specification of a Silicon device with twice error severity of SiliconDelft.";
*)
SiliconDelft::usage = "Returns device specification of a Silicon device based on the device built by the University of Delft.";
(*
SiliconHub::usage = "Returns devices specification of a Silicon device based on the device built by the QCSHub.";
*)
(*superconducting qubit devices*)
(*
SuperconductingFZJ::usage = "Returns device specification of a Superconducting qubit device based on the device built by Forschungzentrum Juelich.";
*)
SuperconductingHub::usage = "Returns device specification of a Superconducting qubit device based on the device built by the QCSHub.";
(*trapped ion devices*)
TrappedIonOxford::usage = "Returns device specification of a multi-nodes Trapped ions based on the device built by the Oxford/Hub.";
(*
TrappedIonInnsbruck::usage = "Returns device specification of a string of Trapped ions base on the device built by the University of Innsbruck.";
*)
(*rydberg quantum devices/neutral atoms*)
RydbergHub::usage = "Returns device specification of a Rydberg/Neutral Atom device based on the device built by the QCSHub.";
(*
RydbergWisconsin::usage = "Returns device specification of a Rydberg/Neutral Atom device based on the device built by the University of Wisconsin.";
*)
(* nuclear-vacancy center devices *)
NVCenterDelft::usage = "Returns device specification of a Nitrogen-Vacancy diamond center device based on the device built by the University of Delft. This device explicitly using electron spin (qubit 0) and 13C spins (qubits j>=1).";
NVCenterDelftN::usage = "Returns device specification of a Nitrogen-Vacancy diamond center device based on the device built by the University of Delft. This device explicitly using electron spin (qubit 0), Nitrogen spin (qubit 1), and 13C spins (qubits j>=2).";
(*
NVCenterHub::usage = "Returns device specification of a Nitrogen-Vacancy diamond center device based on the device built by the QCSHub.";
*)
(* toy device
ToyDevice::usage = "Return a specification with simple standard model.";
*)
(** General functions **)
CalcFidelityDensityMatrices::usage = "CalcFidelityDensityMatrices[\[Rho],\[Sigma]] fidelity of two density matrices, \[Rho] and \[Sigma] can be density matrix of Quregs. Fidelity of two density matrices.";
PartialTrace::usage = "PartialTrace[qureg/density matrix, tracedoutqubits_List]. Return the partial trace as a matrix.";
RandomMixState::usage = "RandomMixState[nqubits, nsamples:None]. Return a random mixed quantum density state matrix.";
(*
Information keys
*)
Connectivity::usage = "Show the connectivity graph of a Superconducting qubit device, where the arrow show possible direction of the cross-resonant ZX gates.";
DeviceType::usage = "The type of device. Normally, the name of the function that generates it.";
LossAtoms::usage = "Device key in the RydbergHub device that identifies atoms lost to the environment.";
LossAtomsProbability::usage = "Device ket in the RydbergHub device that shows the accumulation of probability of atom loss due to measurements.";
OptionsUsed::usage = "Show all options used in a virtual device specification instance.";
QMap::usage = "Show maps from nodes in trapped ions to the actual emulated qubits";
ShowNodes::usage = "Draw all Ions on every nodes within the zones";
HighlightAtoms::usage = "Options in plot atoms, to highlight atoms.";
(*
Visualisations functions and keys
*)
PlotAtoms::usage = "PlotAtoms[rydberg_device]. Plot the neutral atoms. Set ShowBlockade->{atoms} to visualise the blockade radii. Set ShowLossAtoms->True, to show the atoms that are loss as well (grey color). It also receives options of Graphic function to style the visualisation.";
PlotAtoms::error = "`1`";
Options[PlotAtoms] = {ShowBlockade -> {}, ShowLossAtoms -> False, HighlightAtoms -> {}};
ShowBlockade::usage = "List the qubits to draw the blockade radius.";
ShowLossAtoms::usage = "Set true to show the atoms lost into the evironment. This shows the last coordinate before being lost.";
(*
Circuit arrangements
*)
CircTrappedIons::usage = "CircTrappedIons[circuit, device, MapQubits->True, Parallel->False]. Circuit arrangement according to the device. Note that Parallle->True is not available yet.";
CircTrappedIons::error = "`1`";
Options[CircTrappedIons] = {MapQubits -> True, Parallel -> False};
CircSiliconDelft::usage = "CircSiliconDelft[circuit, device, Parallel->False]. Circuit arrangement according to the device. Note that Parallle->True is not available yet.";
CircSiliconDelft::error = "`1`";
Options[CircSiliconDelft] = {Parallel -> False};
CircRydbergHub::usage = "CircRydbergHub[circuit, device, Parallel->(False, True)]";
CircRydbergHub::error = "`1`";
Options[CircRydbergHub] = {Parallel -> True};
Serialize::usage = "Serialize circuit. Every quantum operation is done without concurency.";
Serialize::error = "`1`";
(* options *)
Parallel::usage = "Parallel options in arrangement of gates: False, Default, All. False: serial, default: parallel according to the device specification, and All: full quantum parallel";
MapQubits::usage = "Options in the CircTrappedIons[] that maps the local qubits (\[Rho]A) into the total qubits of the total (large) density matrix (\[Rho]AB).";
(** Custom gates, used in Aliases **)
BeginPackage["`CustomGates`"];
SWAPLoc::usage = "Swap the spatial locations of two qubits. This is implemented in neutral atoms and trapped ions.";
SWAPLoc::error = "`1`";
SWAPLoc::warning = "`1`";
ShiftLoc::usage = "ShiftLoc[v] the physical coordinate of a qubit by some vector v. This is implemented in neutral atoms.";
ShiftLoc::error = "`1`";
ShiftLoc::warning = "`1`";
Wait::usage = "Wait[\[CapitalDelta]t] gate, doing nothing/identity operation for duration \[CapitalDelta]t.";
Wait::error="`1`";
CZ::usage = "Controlled-Z operation.";
CZ::error="`1`";
CRx::usage = "Conditional Rx[\[Theta]] rotation on the nuclear 13C NV-center qubit, conditioned on the electron spin state.";
CRx::error="`1`";
CRy::usage = "Conditional Ry[\[Theta]] rotation on the nuclear 13C NV-center qubit, conditioned on the electron spin state.";
CRy::error="`1`";
CRot::usage = "Conditional rotation in Silicon spin qubit; this effectively implements CNOT gate.";
CRot::error="`1`";
Ent::usage = "Remote entanglement operation on multi-node trapped ions.";
Ent::error="`1`";
Splz::usage = "Splz[node, zone_destination]. Split a string of ions in a zone of a trapped-ion Oxford device";
Splz::error="`1`";
Shutl::usage = "Shutl[node,zone_destination]. Shuttle the qubit(s) to the destination zone";
Shutl::error="`1`";
Comb::usage = "Comb[node, zone_destination]. Combine a string of ions to a zone of a trapped-ion Oxford device";
Comb::error="`1`";
PSW::usage = "PSW[\[Theta]], parameterised swaps";
PSW::error="`1`";
SRot::usage = "Single qubit gate realised by driving a Rydberg atom via two-photon Raman transition. Usage: SRot[\[Phi],\[CapitalDelta],t] where \[Phi] is laser phase, \[CapitalDelta] is detuning, t is laser duration.";
SRot::error="`1`";
Init::usage = "Initialise qubit to its fiducial state; typically to state |0>";
Init::error="`1`";
ZZ::usage = "The siZZle (Stark-induced ZZ by level excursion) gate on Superconducting device. Implemented by operator Exp[-(i\[Theta]/2) ZZ].";
ZZ::error="`1`";
ZX::usage = "Cross-resonance gate on a Superconducting device. Implemented by Exp[-(i\[Theta]/2) ZX].";
ZX::error="`1`";
MeasP::usage = "Perform parity measurement for two qubits that projects them into even (00,11) subspace and odd (01,10) subspace. In the case of Silicon qubit, state 01 decays to 10.";
MeasP::error="`1`";
EndPackage[]
(** All parameters used in virtual device configuration **)
BeginPackage["`ParameterDevices`"];
(* future features
MoveSpeed : "The speed of moving atom \[Mu]m/\[Mu]s in Neutral Atom systems. This will affect the heat factor";
GlobalField: "Global magnetic field fluctuation in NV-center due to C13 bath. It causes dephasing on the electron in 4\[Mu]s.";
*)
AtomLocations::usage = "Three-dimensional physical locations of each atom/qubit.";
AtomLocations::error="`1`";
Anharmonicity::usage = "The anharmonicity in the Superconducting device capturing the capacitor property.";
Anharmonicity::error="`1`";
BlockadeRadius::usage = "Short-range dipole-dipole interaction of Rydberg atoms in \[Mu]s. This allows multi-qubit gates.";
BlockadeRadius::error="`1`";
DurMeas::usage = "Duration of measurement";
DurMeas::error="`1`";
DurInit::usage = "Duration of initialisation";
DurInit::error="`1`";
DurRead::usage = "Readout duration in \[Mu]s";
DurRead::error="`1`";
DurMove::usage = "Duration for physically moving operation in Trapped Ions: Splz, Comb, Shuttle, and SWAPLoc.";
DurMove::error="`1`";
DurRxRy::usage = "Duration to run the rotation gates Rx and Ry on the Superconducting device; the value is fixed regardless the angle.";
DurRxRy::error="`1`";
DurZX::usage="Duration of the cross-resonance ZX gate on the Superconducting device; this is fixed regardless the angle.";
DurZX::error="`1`";
DurZZ::usage="Duration of the siZZle ZZ gate on the Superconducting device; this is fixed regardless the angle.";
DurZZ::error="`1`";
EFSingleXY::usage = "Error fraction/ratio, {depolarising, dephasing} of the single qubit X and Y rotations. Sum of the ratio must be 1 or 0 (off).";
EFSingleXY::error="`1`";
EFCZ::usage = "Error fraction/ratio, {depolarising, dephasing} of the controlled-Z gates in Silicon and Trapped ions. Sum of the ratio must be 1 or 0 (off).";
EFCZ::error="`1`";
EFCRot::usage = "Error fraction/ratio, {depolarising, dephasing} of conditional-rotation in NV-center. Sum of the ratio must be 1 or 0 (off).";
EFCRot::error="`1`";
EFEnt::usage = "Error fraction/ratio {depolarising, dephasing} of remote entanglement in Trapped Ions. Sum of the ratio must be 1 or 0 (off).";
EFEnt::error="`1`";
ExchangeRotOn::usage = "Maximum interaction j on the passive qubit crosstalk when applying CZ gates on Silicon qubit device; The noise form is C[Rz[j.\[Theta]]] It must be a square matrix with size (nqubit-2)x(nqubit-2).";
ExchangeRotOn::error="`1`";
ExchangeRotOff::usage = "Crosstalks error C-Rz[ex] on the passive qubits when not applying two-qubit gates on Silicon qubit device.";
ExchangeRotOff::error="`1`";
ExcitedInit::usage = "The probability/fraction of the population excited in the thermal state; this also constitute the initial state in the superconducting qubit device.";
ExcitedInit::error="`1`";
ExchangeCoupling::usage = "The exchange coupling strength of resonators in Superconducting devices";
ExchangeCoupling::error="`1`";
(* fidelities has warning because of upper bound on error parameters *)
FidCRot::usage = "Fidelity of conditional rotation in NV-center obtained by dynamical decoupling and RF pulse or the Controlled-X180 in the Silicon qubits that is used in readout/measurement.";
FidCRot::error="`1`";
FidCRot::warning="`1`";
FidCZ::usage = "Fidelity(ies) of the CZ gates.";
FidCZ::error="`1`";
FidCZ::warning="`1`";
FidEnt::usage = "Fidelity of remote entanglement operation on trapped ions.";
FidEnt::error="`1`";
FidEnt::warning="`1`";
FidInit::usage = "Fidelity of qubit initialisation";
FidInit::error="`1`";
FidInit::warning="`1`";
(* meas vs read *)
FidMeas::usage = "Fidelity of measurement";
FidMeas::error="`1`";
FidMeas::warning="`1`";
FidRead::usage = "Readout fidelity";
FidRead::error="`1`";
FidRead::warning="`1`";
FidCRx::usage = "Fidelity of controlled-Rx[\[Theta]]";
FidCRx::error="`1`";
FidCRx::warning="`1`";
FidSingleXY::usage = "Fidelity of single Rx[\[Theta]] and Ry[\[Theta]] rotations obtained by random benchmarking.";
FidSingleXY::error="`1`";
FidSingleXY::warning="`1`";
FidSingleZ::usage = "Fidelity of single Rz[\[Theta]] rotation obtained by random benchmarking.";
FidSingleZ::error="`1`";
FidSingleZ::warning="`1`";
FreqCRot::usage = "Frequency of conditional rotation in NV-center obtained by dynamical decoupling and RF pulse.";
FreqCRot::error="`1`";
FreqCRx::usage="Frequency of controlled-x rotation.";
FreqCRx::error="`1`";
FreqCZ::usage = "Rabi frequency for the CZ gate with unit MHz.";
FreqCZ::error="`1`";
FreqEnt::usage = "Frequency of remote entanglement.";
FreqEnt::error="`1`";
FreqSingleXY::usage = "Rabi frequency(ies) for the single X- and Y- rotations with unit MHz";
FreqSingleXY::error="`1`";
FreqSingleZ::usage = "Rabi frequency(ies) for the single Z- rotations with unit MHz";
FreqSingleZ::error="`1`";
FreqWeakZZ::usage = "Frequency of coherent cross-talk noise in form of ZZ-coupling that slowly entangle the nuclear qubits to each other in NV-center.";
FreqWeakZZ::error="`1`";
HeatFactor::usage = "The constant >=1 that enhance dephasing process in neutral atoms when moving the atoms.";
HeatFactor::error="`1`";
Nodes::usage = "Specify the node names and number of ions in ions traps with format <|node1 -> number_of_qubits_1, ... |>.";
Nodes::error="`1`";
OffResonantRabi::usage = "Put the noise due to off-resonant Rabi oscillation when applying single qubit rotations.";
OffResonantRabi::error="`1`";
OverRotation::usage = "Over rotation \[Delta] in radian when implementing physical single-qubit rotation, e.g., noisy version of Rx(\[Theta]) is Rx(\[Theta]+\[Delta]).";
OverRotation::error="`1`";
OverRotation2::usage = "Over rotation \[Delta] in radian when implementing two-qubit rotations, e.g., noisy version of CRx(\[Theta]) is CRx(\[Theta]+\[Delta]). For the association entry, the keys indicate the target qubits.";
OverRotation2::error="`1`";
ProbBFRead::usage = "Probability of bit-flip error in readout";
ProbBFRead::error="`1`";
ProbBFRot::usage = "Assymetric Bit-flip probability on single-qubit rotation . {01->p1, 10->p2}.";
ProbBFRead::error="`1`";
ProbLeakCZ::usage = "Leakage probability in executing multi-controlled-Z on neutral atoms.";
ProbLeakCZ::error="`1`";
ProbLeakInit::usage = "Leakage probability in the Rydberg initialisation. The noise is decribed with non-trace-preserving map.";
ProbLeakInit::error="`1`";
ProbLossMeas::usage = "Probability of phyiscal atom loss due to measurement in neutral atoms.";
ProbLossMeas::error="`1`";
QubitFreq::usage = "The fundamental qubit frequency for each qubit with unit MHz.";
QubitFreq::error="`1`";
QubitNum::usage = "The number of physical active qubits for computations.";
QubitNum::error="`1`";
RabiFreq::usage = "The Rabi frequency with unit MHz.";
RabiFreq::error="`1`";
StdPassiveNoise::usage = "Option eather to apply the standard passive noise that involves T1, T2 or T2s inputs. Set it to True/False.";
StdPassiveNoise::error="`1`";
T1::usage = "T1 duration(s) in \[Mu]s; characterising an exponential decay.";
T1::error="`1`";
T2::usage = "T2 duration(s) in \[Mu]s; characterising an exponential decay.";
T2::error="`1`";
T2s::usage = "T2* duration(s) in \[Mu]s; characterising a Gaussian decay ";
T2s::error="`1`";
UnitLattice::usage = "The unit lattice AtomLocations in \[Mu]s. This also gives access to internal device parameter in RydbergHub device.";
UnitLattice::error="`1`";
VacLifeTime::usage = "The lifetime of the neutral atoms in the array of traps in vacuum chamber.";
VacLifeTime::error="`1`";
ZZPassiveNoise::usage = "The switch (True/False) for ZZ interaction passive noise in the Superconducting device.";
ZZPassiveNoise::error="`1`";
EndPackage[];
(*******All definitions of modules****)
Begin["`Private`"];
Needs["QuEST`"];
Needs["QuEST`Option`"];
Needs["QuEST`Gate`"];
Needs["QuEST`DeviceSpec`"];
(*Validate expression, throw error if false*)
validate[value_, expr_, err_, msg_, format_:Identity] :=
(
If[expr[format[value]],
format[value]
,
Throw[Message[err::error, msg]]
]
)
(* check if it's an association with length len. *)
checkAss[ass_, len_] :=
AssociationQ[ass] && Length[ass] === len && And @@ NumberQ /@ Values @ ass
checkAss[ass_, len_, f_] :=
AssociationQ[ass] && Length[ass] === len && And @@ f /@ Values @ ass
(* convert number to association *)
num2Ass[arg_Real, len_Integer] :=
<|Table[i -> arg, {i, 0, -1 + len}]|>
num2Ass[arg_Integer, len_Integer] :=
<|Table[i -> arg, {i, 0, -1 + len}]|>
num2Ass[arg_Association, len_Integer] :=
arg
(* TODO *)
numass[len_]:="not a number or association of numbers with length "<>ToString[len]
fidass[len_]:="not a fidelity number or association of fidelities with length "<>ToString[len]
(* convenient functions *)
(* check if it is a probability number *)
isProbability[p_ ]:=If[0 <= p <= 1, True, False]
(*
fid2DepolDeph[fidelity, {ratio.Depol,ratio.Deph}, nqubits, error_variable, is_average_fidelity:True].
Return the parameter for depolarizing and dephasing noise that gives the total fidelity totFid [0,1],
where totFid is the average fidelity obtained from random benchmarking (set avgfid:False if it's the worst fidelity)
correction is a constant adjusted to params of dephasing to get average fidelity from the worst fidelity.
*)
fid2DepolDeph[totfid_, errratio_, nqerr_, errval_, avgfid_:True] := Module[
{sol, rate, pdepol, pdeph, entfid, d, p},
(*set to perfect fidelity of zero error *)
If[(totfid == 1 || 0 == Total @ errratio),
{pdepol, pdeph} = {0, 0}
,
(* 1-qubit error case *)
If[nqerr === 1,
sol = If[avgfid,
(* estimate parameters from entanglement fidelity *)
entfid = (3 totfid - 1)/2; Solve[1 - rate * errratio[[1]] - rate * errratio[[2]] + 4/3 errratio[[1]] * errratio[[2]] * rate^2 == entfid,
{rate}]
,
(*estimate parameters from the worst fidelity: from + state *)
Solve[1 - 2 errratio[[1]] * rate/3 - errratio[[2]] * rate + 4 * errratio[[1]] * errratio[[2]] * rate^2/3 == totfid, {rate}]
];
(* check validity of numbers and set it to the worst parameter if exceeds *)
{pdepol, pdeph} = errratio * Min @ Abs[rate /. sol];
If[pdepol > 0.75, Message[errval::warning, StringForm["(warning) fidelity is too low; 1-qubit depolarization parameter is ``. Set it to 3/4.",
pdepol]]; pdepol = 0.75;];
If[pdeph > 0.5, Message[errval::warning, StringForm["(warning) fidelity is too low; 1-qubit dephasing parameter is ``. Set it to 1/2.",
pdeph]]; pdeph = 0.5;];
,
(* 2-qubit error case*)
sol = If[avgfid,
(*estimate parameters from entanglement fidelity*)
entfid = (5 * totfid - 1)/4; Solve[1 - rate * errratio[[1]] - rate * errratio[[2]] + 16/15 * rate^2 * errratio[[1]] * errratio[[2]] == entfid, {rate}]
,
(*estimate parameters from the worst fidelity: from ++ state *)
Solve[1 - errratio[[2]] * rate - errratio[[1]] * rate * 4/5 + errratio[[1]] * errratio[[2]] * rate^2 * 16/15 == totfid, {rate}]
];
(* check validity of numbers, set it to the worst if exceeds *)
{pdepol, pdeph} = errratio * Min @ Abs[rate /. sol];
If[pdepol > 15/16, Message[errval::warning, StringForm["(warning) Fidelity might be too low; 2-qubit depolarization parameter is ``. Set it to 15/16.",
pdepol]]; pdepol = 15/16;];
If[pdeph > 3/4, Message[errval::warning, StringForm["(warning) Fidelity might be too low; 2-qubit dephasing parameter is ``. Set it to 3/4.",
pdeph]]; pdeph = 3/4;];
];
];
{pdepol, pdeph}
]
(*
Obtain the error parameters given entanglement fidelity. This works only for the trapped ion network fidelity.
This is obtained by calculating <\[CapitalPsi]^+|Subscript[Depol, 0,1](d)Subscript[Deph, 0,1](p)|\!\(
\*SuperscriptBox[\(\[CapitalPsi]\), \(+\)]
\*SubscriptBox[\(>\), \(0, 1\)]\)
*)
entFid2DepolDeph[entfid_, errratio_, errval_:FidEnt] := Module[
{pdepol, pdeph, sol, rate}
,
sol = Solve[1 - rate * errratio[[1]] * 4/5 - rate * errratio[[2]] * 2/3 + rate^2 * errratio[[1]] * errratio[[2]] * 32/45 == entfid,
{rate}];
{pdepol, pdeph} = errratio * Min @ Abs[rate /. sol];
If[pdepol > 15/16,
Message[errval::warning, StringForm["(warning) Fidelity might be too low; 2-qubit depolarization parameter is ``. Set it to 15/16.",
pdepol]]; pdepol = 15/16;
];
If[pdeph > 3 / 4,
Message[errval::warning, StringForm["(warning) Fidelity might be too low; 2-qubit dephasing parameter is ``. Set it to 3/4.",
pdeph]]; pdeph = 3/4;
];
{pdepol, pdeph}
]
(** Error channels expressed as a list of matrices **)
(* 1-qubit bit-flip error *)
bitFlip1[fid_] :=
With[{e = 1 - fid},
{Sqrt[1 - e] * {{1, 0}, {0, 1}}, Sqrt[e] * {{0, 1}, {1, 0}}}
]
(* 2-qubit bit-flip error *)
bitFlip2[fid_] :=
With[{e = 1 - fid},
{Sqrt[1 - e] * {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}},
Sqrt[e/3] * {{0, 1, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}},
Sqrt[e/3] * {{0, 0, 1, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}, {0, 1, 0, 0}},
Sqrt[e/3] * {{0, 0, 0, 1}, {0, 0, 1, 0}, {0, 1, 0, 0}, {1, 0, 0, 0}}}
]
(*
Generalised amplitude damping (Nielsen&Chuang, P.382).
Common description of T1 decay, by setting gamma(t)=1-Exp[-t/T1],
which describes the shrinking Bloch sphere into the ground state zero,
with probability p.
*)
(* Rho_infty = p|0X0|+(1-p)|1X1|; this returns the operator *)
Subscript[gAmp, q_][gamma_, p_] :=
Subscript[Kraus, q][
{
Sqrt[p]*{{1, 0}, {0, Sqrt[1 - gamma]}}
,
Sqrt[p]*{{0, Sqrt[gamma]}, {0, 0}}
,
Sequence @@
If[p < 1,
{Sqrt[1 - p]*{{Sqrt[1 - gamma], 0}, {0, 1}}, Sqrt[1 - p] * {{0, 0}, {Sqrt[gamma], 0}}}
,
{}
]
}
]
(* Off-resonant Rabi oscillation.
omega: Rabi frequency
delta: detuning frequency
dt: time duration of the pulse
*)
offresonantRabi[omega_, delta_, dt_] :=
With[{omegaR = Sqrt[omega^2 + delta^2]},
E^(I * delta * dt/2)*
{{Cos[omegaR * dt/2] - I * Sin[omegaR * dt/2] * delta/omegaR, -I * Sin[omegaR * dt/2] * omega/omegaR},
{-I * Sin[omegaR * dt/2]*omega/omegaR, Cos[omegaR * dt/2] + I * Sin[omegaR * dt/2] * delta/omegaR}}
]
(** Custom gates definitions **)
(* Unitary driven by laser detuning *)
unitaryDetuning[phi_, delta_, dt_, rabi_] :=
Module[{vdelta, vt, omega},
FullSimplify[
{{Cos[omega * vt/2] - I * Sin[omega * vt/2] * vdelta/omega, -I * E^(I*phi) Sin[omega * vt/2]* rabi/omega},
{-I * E ^ (-I * phi) * Sin[omega * vt/2] * rabi/omega, Cos[omega vt/2] + I * Sin[omega * vt/2] * delta/omega}} //.
{vdelta -> delta, omega -> Sqrt[rabi^2 + vdelta^2], vt -> dt}
, {rabi >= 0, vdelta >= 0}]
]
(************ VIRTUAL_DEVICES *************)
(* DEVICE_TOY *)
ToyDevice[OptionsPattern[]] := With[
{
qubitnum = OptionValue @ QubitNum,
t1 = OptionValue @ T1,
t2 = OptionValue @ T2,
stdpassivenoise = OptionValue @ StdPassiveNoise,
fidsingle = OptionValue @ FidSingle,
fidtwo = OptionValue @ FidTwo,
efsingle = OptionValue @ EFSingle,
eftwo = OptionValue @ EFTwo,
rabifreq = OptionValue @ RabiFreq,
twogatefreq = OptionValue @ FreqTwoGate
},
Module[{deltaT, erone, ertwo},
erone = fid2DepolDeph[fidsingle, efsingle, 1, FidSingle, True];
ertwo = fid2DepolDeph[fidtwo, eftwo, 2, FidTwo, True];
<|
(*no hidden qubits/ancilla here *)
DeviceType -> "Toy"
,
OptionsUsed -> {
QubitNum -> qubitnum,
T1 -> t1,
T2 -> t2,
StdPassiveNoise -> stdpassivenoise,
FidSingle -> fidsingle,
FidTwo -> fidtwo,
EFSingle -> efsingle,
EFTwo -> eftwo,
RabiFreq -> rabifreq,
FreqTwoGate -> twogatefreq
}
,
DeviceDescription -> "Toy device with " <> ToString[qubitnum] <> "-qubits arranged as a linear array with nearest-neighbor connectivity."
,
NumAccessibleQubits -> qubitnum
,
NumTotalQubits -> qubitnum
,
Aliases -> {
(* parameterised swap *)
Subscript[PSW, p_, q_][theta_] :> Subscript[U, p, q][
{{1, 0, 0, 0}, {0, E^((I theta)/2) Cos[theta/2], -I E^((I theta)/2) Sin[theta/2], 0},
{0, -I E ^ ((I theta)/2) Sin[theta/2], E ^ ((I theta)/2) Cos[theta/2], 0}, {0, 0, 0, 1}}]
}
,
Gates ->
{
(* Singles *)
Subscript[Rx, q_][theta_] :>
<|
NoisyForm -> Flatten @ {Subscript[Rx, q][theta], Subscript[Depol, q][erone[[1]]], Subscript[Deph, q][erone[[2]]]},
GateDuration -> Abs[theta]/rabifreq
|>
,
Subscript[Ry, q_][theta_] :>
<|
NoisyForm -> Flatten @ {Subscript[Ry, q][theta], Subscript[Depol, q][erone[[1]]], Subscript[Deph, q][erone[[2]]]},
GateDuration -> Abs[theta]/rabifreq
|>
,
Subscript[Rz, q_][theta_] :>
<|
NoisyForm -> Flatten @ {Subscript[Rz, q][theta], Subscript[Depol, q][erone[[1]]], Subscript[Deph, q][erone[[2]]]},
GateDuration -> Abs[theta]/rabifreq
|>
,
(* Twos *)
Subscript[C, p_][Subscript[Rx, q_][theta_]] /; Abs[q - p] === 1 :>
<|
NoisyForm -> {Subscript[C, p][Subscript[Rx, q][theta]], Subscript[Depol, p, q][Min[ertwo[[1]] * Abs[theta/Pi], 15/16]], Subscript[Deph, p, q][Min[ertwo[[2]] * Abs[theta/Pi], 3/4]]},
GateDuration -> Abs[theta]/twogatefreq
|>
,
Subscript[C, p_][Subscript[Ry, q_][theta_]] /; Abs[q - p] === 1 :>
<|
NoisyForm -> {Subscript[C, p][Subscript[Ry, q][theta]], Subscript[Depol, p, q][Min[ertwo[[1]] * Abs[theta/Pi], 15/16]], Subscript[Deph, p, q][Min[ertwo[[2]] * Abs[theta/Pi], 3/4]]},
GateDuration -> Abs[theta]/twogatefreq
|>
,
Subscript[C, p_][Subscript[Rz, q_][theta_]] /; Abs[q - p] === 1 :>
<|
NoisyForm -> {Subscript[C, p][Subscript[Rz, q][theta]], Subscript[Depol, p, q][Min[ertwo[[1]] * Abs[theta/Pi], 15/16]], Subscript[Deph, p, q][Min[ertwo[[2]] * Abs[theta/Pi], 3/4]]},
GateDuration -> Abs[theta]/twogatefreq
|>
,
(* parameterised swap*)
Subscript[PSW, p_, q_][theta_] /; Abs[q - p] === 1 :>
<|
NoisyForm -> {Subscript[PSW, p, q][theta], Subscript[Depol, p, q][ertwo[[1]]], Subscript[Deph, p, q][ertwo[[2]]]},
GateDuration -> Abs[theta]/twogatefreq
|>
}
,
(* Declare that deltaT will refer to the duration of the current gate/channel. *)
DurationSymbol -> deltaT
,
(* Passive noise *)
Qubits :>
{
q_Integer :>
<|
PassiveNoise ->
(* standard passive noise on *)
If[stdpassivenoise,
{Subscript[Depol, q][0.75 (1 - E ^ (-deltaT / t1))], Subscript[Deph, q][0.5 (1 - E ^ (-deltaT / t2))]}
,
{}
]
|>
}
|>
]
]
(* DEVICE_SUPERCONDUCTING_QUBITS *)
(*
construct graph that shows connectivity of the corss-resonance gate (ZX) in SQC based on the value of qubit frequencies
*)
graphConnectivityFromQubitFreq[nqubit_, coupling_, qubitFreq_] :=
Module[
{g, dedge}
,
(*directed edges, control->target*)
dedge =
If[qubitFreq[#[[1]]] > qubitFreq[#[[2]]],
#[[1]] -> #[[2]]
,
#[[2]] -> #[[1]]
]& /@ Keys[coupling];
(* basic graph *)
g = Graph[Range[0, nqubit - 1], dedge, VertexWeight -> Values @ qubitFreq, EdgeWeight -> Values @ coupling];
(* the final graph with a visualisation format*)
DirectedGraph[g, VertexSize -> 0.5, BaseStyle -> {15, Bold, FontFamily -> "Serif"},
VertexLabels -> {v_ :> Placed[{AnnotationValue[{g, v}, VertexWeight], "Q" <> ToString[v]}, {Center, {After, Above}}]},
EdgeLabels -> "EdgeWeight", GraphLayout -> "SpringEmbedding", EdgeStyle -> {Thick}, VertexStyle -> {Yellow, EdgeForm[None]}
]
]
(*
device description of superconducting qubits
*)
SuperconductingHub[OptionsPattern[]] :=
With[{
qubitsnum = OptionValue @ QubitNum,
t1 = OptionValue @ T1,
t2 = OptionValue @ T2,
excitedinit = OptionValue @ ExcitedInit,
qubitfreq = OptionValue @ QubitFreq,
exchangecoupling = OptionValue @ ExchangeCoupling,
anharmonicity = OptionValue @ Anharmonicity,
fidread = OptionValue @ FidRead,
durmeas = OptionValue @ DurMeas,
durrxry = OptionValue @ DurRxRy,
durzx = OptionValue @ DurZX,
durzz = OptionValue @ DurZZ,
stdpassivenoise=OptionValue @ StdPassiveNoise,
zzpassivenoise=OptionValue @ ZZPassiveNoise
},
(* some assertions to check the inputted parameters.
TODO: distinct when coupled
*)
(*Catch @ If[CountDistinct[Values@qubitfreq]==Length@qubitfreq,
Throw @ Message[QubitFreq::error, "Every qubit frequency value given in QubitFreq must be distinct."]
];*)
Module[{ccv, ug, stdpn, zzInteraction, zzPN, lessNeighbor, zzon, passivenoise, deltaT, activeq, counter=0, init=True}
,
(* cross-resonance connectivity *)
ccv = graphConnectivityFromQubitFreq[qubitsnum, exchangecoupling, qubitfreq];
(* undirected graph *)
ug = UndirectedGraph[ccv];
(* track the active qubit for passive noice application *)
activeq = <|Table[q -> False, {q, Range[0, qubitsnum - 1]}]|>;
(* track if a there is ZZ-gate (siZZler) applied *)
zzon = False;
(* Free-induction T1- T2- passive noise decays *)
Subscript[stdpn, q_][dur_] := If[stdpassivenoise && \[Not]activeq[q] && dur > 0,
{Subscript[gAmp, q][(1 - E ^ (-dur/t1[q])), 1 - excitedinit[q]], Subscript[Deph, q][0.5 (1 - E ^ (-dur / t2[q]))]}
,
{}
];
(* Fixed ZZ-interaction on passive noise, where c is the first/control and t is the later/target *)
Subscript[zzInteraction, c_, t_] := With[{
deltact = Abs[qubitfreq[c] - qubitfreq[t]]
,
alphat = anharmonicity[t]
,
alphac = anharmonicity[c]
,
jc = If[KeyExistsQ[exchangecoupling, c \[UndirectedEdge] t],
exchangecoupling[c \[UndirectedEdge] t]
,
exchangecoupling[t \[UndirectedEdge] c]
]
},
R[jc^2 (1 / (deltact - alphat) - 1 / (deltact + alphat)), Subscript[Z, c] Subscript[Z, t]]
];
(* list neighbor qubits with ordering less than q in graph g. *)
lessNeighbor[q_] := List @@@ Select[EdgeList[NeighborhoodGraph[ccv, q]], q > First @ DeleteElements[List @@ #, {q}]&];
(* zz-crosstalk as passive noise which is off when a siZZle is on *)
Subscript[zzPN, q_][dur_] := Module[{ng = lessNeighbor[q], noise},
noise = If[zzpassivenoise,
(* a siZZle gate is active in a parallel column *)
If[\[Not]zzon,
(
If[dur > 0 && And[\[Not]activeq[#[[1]]], \[Not]activeq[#[[2]]]],
Subscript[zzInteraction, #[[1]], #[[2]]]
,
{}
]
)& /@ ng
,
{}
]
,
{}
];
noise
];
<|
(* store the option that is initially used here *)
OptionsUsed ->
{
QubitNum -> qubitsnum,
T1 -> t1,
T2 -> t2,
ExcitedInit -> excitedinit,
QubitFreq -> qubitfreq,
ExchangeCoupling -> exchangecoupling,
Anharmonicity -> anharmonicity,
FidRead -> fidread,
DurMeas -> durmeas,
DurRxRy -> durrxry,
DurZX -> durzx,
DurZZ -> durzz,
StdPassiveNoise -> stdpassivenoise,
ZZPassiveNoise -> zzpassivenoise
}
,
DeviceType -> "Superconducting"
,
DeviceDescription -> ToString[qubitsnum]<>"-qubit of Superconducting transmon qubits based on Josephson junctions"
,
NumAccessibleQubits -> qubitsnum
,
NumTotalQubits -> qubitsnum
,
Connectivity -> ccv
,
Aliases ->
{
Subscript[ZZ, p_,q_] :> {R[Pi/2,Subscript[Z, p] Subscript[Z, q]]}
,
Subscript[ZX, p_,q_] :> {R[Pi/2,Subscript[Z, p] Subscript[X, q]]}
,
(* in practice, it is a decay to the thermal state *)
Subscript[Init, q__] :> {}
,
Subscript[Wait, q_] :> {}
},
Gates ->
{
(*
init can be done once, entirely, in the beginning.
the process uses generalised amplitude damping to describe the decay to the thermal state.
*)
Subscript[Init, q__] /; And[init === True, ContainsExactly[{q}, Range[0, qubitsnum - 1]] ] :>
<|
NoisyForm -> Table[Subscript[gAmp, j][1, 1 - excitedinit[j]], {j, Range[0, qubitsnum - 1]}],
GateDuration -> 0,
UpdateVariables -> Function[
(activeq[#] = True)& /@ Range[0, qubitsnum - 1];
]
|>
,
Subscript[M, q_] :>
<|
(* depolarise up the final result as well *)
NoisyForm -> {Subscript[gAmp, q][(1 - E ^ (-durmeas/t1[q]))],Subscript[Depol, q][1 - fidread[q]], Subscript[M, q], Subscript[Depol, q][1-fidread[q]]},
GateDuration -> durmeas,
UpdateVariables -> Function[
activeq[q] = True;
init = False;
]
|>
,
(* doing nothing, is equivalent to being passive *)
Subscript[Wait, q_][dur_]:>
<|
NoisyForm -> Flatten @ {Subscript[stdpn, q][dur], Subscript[zzPN, q][dur]},
GateDuration -> dur,
UpdateVariables -> Function[ activeq[q] = False ]
|>
,
(* single-qubit gates *)
Subscript[Rx, q_][theta_] /; If[NumberQ@theta,(-Pi <= theta <= Pi), True] :>
<|
NoisyForm -> {Subscript[Rx, q][theta]},
GateDuration -> durrxry,
UpdateVariables -> Function[
activeq[q] = True;
init = False;
]
|>
,
Subscript[Ry, q_][theta_] /; If[NumberQ@theta,(-Pi <= theta <= Pi), True] :>
<|
NoisyForm -> {Subscript[Ry, q][theta]},
GateDuration -> durrxry,
UpdateVariables -> Function[
activeq[q] = True;
init = False;
]
|>
,
(* virtual gate *)
Subscript[Rz,q_][theta_] :>
<|
NoisyForm -> Flatten@{Subscript[Rz, q][theta]},
GateDuration -> 0
|>
,
(* siZZle gates *)
Subscript[ZZ, p_, q_] /; EdgeQ[ug, p\[UndirectedEdge]q] :>
<|
NoisyForm -> {Subscript[ZZ, p, q]},
GateDuration -> durzz,
UpdateVariables -> Function[
init = False;
zzon = True;
activeq[q] = True;
activeq[p] = True;
]
|>
,
(* cross-resonance gate *)
Subscript[ZX, p_, q_] /; EdgeQ[ccv, p\[DirectedEdge]q] :>
<|
NoisyForm -> {Subscript[ZX, p, q]},
GateDuration -> durzx,
UpdateVariables -> Function[
init = False;
activeq[q] = True;
activeq[p] = True;
]
|>
}
,
(*TODO: option to activate/deactivate this. Re-initialized when invoking InsertCircuitNoise *)
InitVariables ->
Function[
activeq = Association[ # -> False & /@ Range[0, qubitsnum - 1]];
zzon = False;
init = True;
]
,
(* Passive noise *)
(* Declare that deltaT will refer to the duration of the current gate/channel. *)
DurationSymbol -> deltaT
,
Qubits :> {
q_ :> <|
(* reset the zzon here *)
PassiveNoise -> Flatten @ {Subscript[stdpn, q][deltaT], Subscript[zzPN, q][deltaT]}
,
UpdateVariables -> Function[
counter++;
If[counter == qubitsnum,
zzon = False;
Table[activeq[j] = False, {j, Keys @ activeq}];
counter = 0;
]
]
|>
}
|>
]
]
(* DEVICE_NVCENTER_DELFT *)
NVCenterDelft[OptionsPattern[]] := With[
{
qubitnum = OptionValue @ QubitNum,
t1 = OptionValue @ T1,
t2 = OptionValue @ T2,
freqcrot = OptionValue @ FreqCRot,
freqsinglexy = OptionValue @ FreqSingleXY,
freqsinglez = OptionValue @ FreqSingleZ,
fidcrot = OptionValue @ FidCRot,
fidsinglexy = OptionValue @ FidSingleXY,
fidsinglez = OptionValue @ FidSingleZ,
efsinglexy = OptionValue @ EFSingleXY,
efcrot = OptionValue @ EFCRot,
fidinit = OptionValue @ FidInit,
fidmeas = OptionValue @ FidMeas,
durmeas = OptionValue @ DurMeas,
durinit = OptionValue @ DurInit,
freqweakzz = OptionValue @ FreqWeakZZ
},
Module[
{dt, stdpn, passivenoise, ersinglexy, ersinglez, ercrot, nuclearq, weakzz}
,
(* standard passive noise *)
stdpn[q_, dur_] :=
{Subscript[Depol, q][0.75 (1 - E^(-dur/t1[q]))], Subscript[Deph, q][0.5 (1 - E^(-dur/t2[q]))]};
(*
Note: cross-talk ZZ-coupling in order of Hz on passive noise, Phase entanglement among nuclear spins
Subscript[C, n1][Subscript[Rz, n2][dt]], weak rotation for all combinations of n1,n2, few Hz.
implement: Exp[-i dur ZZ]
*)
weakzz[q_, dur_] :=
R[dur/freqweakzz, Subscript[Z, #]Subscript[Z, #2]]& @@@ Subsets[DeleteCases[Range[1, qubitnum - 1], q], {2}];
passivenoise[q_, dur_] :=
If[NumberQ @ freqweakzz,
Flatten @ {stdpn[q, dur], weakzz[q, dur]}
,
stdpn[q, dur]
];
(* error parameters (depolarising and dephasing) *)
ersinglexy = fid2DepolDeph[#, efsinglexy, 1, FidSingleXY]& /@ fidsinglexy;
ersinglez = fid2DepolDeph[#, {0, 1}, 1, FidSingleZ]& /@ fidsinglez;
ercrot = fid2DepolDeph[#, efcrot, 2, FidCRot]& /@ fidcrot;
<|
DeviceDescription ->"One node of an NV center, where qubit 0 is the electronic spin. It has start connectivity with qubit 0 at the center.",
(* The number of accessible qubits. This informs the qubits that a user's circuit can target *)
NumAccessibleQubits -> qubitnum,
(* The total number of qubits which would be needed to simulate a circuit prescribed by this device.
* This is > NumAccessibleQubits only when the spec uses hidden qubits for advanced noise modelling *)
NumTotalQubits -> qubitnum,
(* Aliases are useful for declaring custom events. At this stage the specification is noise-free (but see later) *)
Aliases -> {
Subscript[Init, q_] :> {Subscript[Damp, q][1.]}
,
Subscript[Wait, q__][t_] :> {}
,
Subscript[CRx, e_, n_][theta_] :> {Subscript[U, e, n][
{{Cos[theta/2], 0, -I Sin[theta/2], 0}, {0, Cos[theta/2], 0, I Sin[theta/2]},
{-I Sin[theta/2], 0, Cos[theta/2], 0}, {0, I Sin[theta/2], 0, Cos[theta/2]}}]}
,
Subscript[CRy, e_, n_][theta_] :> {Subscript[U, e, n][
{{Cos[theta/2], 0, -Sin[theta/2], 0}, {0, Cos[theta/2], 0, Sin[theta/2]},
{Sin[theta/2], 0, Cos[theta/2], 0},{0, -Sin[theta/2], 0, Cos[theta/2]}}]}
}
,
Gates ->
{
(* exclusively on ELECTRON SPIN, q===0 *)
Subscript[Init, q_] /; q === 0 :>