-
Notifications
You must be signed in to change notification settings - Fork 56
/
basic.py
executable file
·50 lines (41 loc) · 1.52 KB
/
basic.py
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
#!/usr/bin/env python3
from pygsti.algorithms import gaugeopt_to_target, contract
from pygsti.tools import timed_block
from pygsti.construction import std2Q_XYICNOT
import pickle
from contextlib import contextmanager
from mpi4py import MPI
comm = MPI.COMM_WORLD
#comm = None
def main():
gs_target = std2Q_XYICNOT.gs_target
gs = gs_target.depolarize(gate_noise=0.1, spam_noise=0.001).rotate(0.1)
gs = gs.kick(0.1, seed=1234)
gs_target.set_all_parameterizations("TP")
gs = contract(gs, "TP")
gs.set_all_parameterizations("TP")
#del gs.spamdefs['11']
#del gs_target.spamdefs['11']
#del gs.preps['rho0']
#del gs_target.preps['rho0']
#envSettings = dict(MKL_NUM_THREADS=1, NUMEXPR_NUM_THREADS=1, OMP_NUM_THREADS=1)
print(gs.get_prep_labels())
print(gs.get_effect_labels())
print(gs.num_elements(include_povm_identity=True))
print(gs.spamdefs)
with timed_block('Basic gauge opt:'):
gs_gaugeopt = gaugeopt_to_target(
gs, gs_target,
#method="L-BFGS-B",
method="auto",
itemWeights={'spam' : 0.0001, 'gates':1.0},
spamMetric='frobenius',
gatesMetric='frobenius',
cptp_penalty_factor=1.0,
spam_penalty_factor=1.0,
comm=comm, verbosity=3, checkJac=True)
if comm is None or comm.Get_rank() == 0:
print("Final Diff = ", gs_gaugeopt.frobeniusdist(gs_target, None, 1.0, 0.0001))
print(gs_gaugeopt.strdiff(gs_target))
if __name__ == '__main__':
main()