pyGSTi 0.9.12.1__cp38-cp38-win32.whl → 0.9.13__cp38-cp38-win32.whl
Sign up to get free protection for your applications and to get access to all the features.
- pyGSTi-0.9.13.dist-info/METADATA +185 -0
- {pyGSTi-0.9.12.1.dist-info → pyGSTi-0.9.13.dist-info}/RECORD +207 -217
- {pyGSTi-0.9.12.1.dist-info → pyGSTi-0.9.13.dist-info}/WHEEL +1 -1
- pygsti/_version.py +2 -2
- pygsti/algorithms/contract.py +1 -1
- pygsti/algorithms/core.py +42 -28
- pygsti/algorithms/fiducialselection.py +17 -8
- pygsti/algorithms/gaugeopt.py +2 -2
- pygsti/algorithms/germselection.py +87 -77
- pygsti/algorithms/mirroring.py +0 -388
- pygsti/algorithms/randomcircuit.py +165 -1333
- pygsti/algorithms/rbfit.py +0 -234
- pygsti/baseobjs/basis.py +94 -396
- pygsti/baseobjs/errorgenbasis.py +0 -132
- pygsti/baseobjs/errorgenspace.py +0 -10
- pygsti/baseobjs/label.py +52 -168
- pygsti/baseobjs/opcalc/fastopcalc.cp38-win32.pyd +0 -0
- pygsti/baseobjs/opcalc/fastopcalc.pyx +2 -2
- pygsti/baseobjs/polynomial.py +13 -595
- pygsti/baseobjs/statespace.py +1 -0
- pygsti/circuits/__init__.py +1 -1
- pygsti/circuits/circuit.py +682 -505
- pygsti/circuits/circuitconstruction.py +0 -4
- pygsti/circuits/circuitlist.py +47 -5
- pygsti/circuits/circuitparser/__init__.py +8 -8
- pygsti/circuits/circuitparser/fastcircuitparser.cp38-win32.pyd +0 -0
- pygsti/circuits/circuitstructure.py +3 -3
- pygsti/circuits/cloudcircuitconstruction.py +1 -1
- pygsti/data/datacomparator.py +2 -7
- pygsti/data/dataset.py +46 -44
- pygsti/data/hypothesistest.py +0 -7
- pygsti/drivers/bootstrap.py +0 -49
- pygsti/drivers/longsequence.py +2 -1
- pygsti/evotypes/basereps_cython.cp38-win32.pyd +0 -0
- pygsti/evotypes/chp/opreps.py +0 -61
- pygsti/evotypes/chp/statereps.py +0 -32
- pygsti/evotypes/densitymx/effectcreps.cpp +9 -10
- pygsti/evotypes/densitymx/effectreps.cp38-win32.pyd +0 -0
- pygsti/evotypes/densitymx/effectreps.pyx +1 -1
- pygsti/evotypes/densitymx/opreps.cp38-win32.pyd +0 -0
- pygsti/evotypes/densitymx/opreps.pyx +2 -2
- pygsti/evotypes/densitymx/statereps.cp38-win32.pyd +0 -0
- pygsti/evotypes/densitymx/statereps.pyx +1 -1
- pygsti/evotypes/densitymx_slow/effectreps.py +7 -23
- pygsti/evotypes/densitymx_slow/opreps.py +16 -23
- pygsti/evotypes/densitymx_slow/statereps.py +10 -3
- pygsti/evotypes/evotype.py +39 -2
- pygsti/evotypes/stabilizer/effectreps.cp38-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/effectreps.pyx +0 -4
- pygsti/evotypes/stabilizer/opreps.cp38-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/opreps.pyx +0 -4
- pygsti/evotypes/stabilizer/statereps.cp38-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/statereps.pyx +1 -5
- pygsti/evotypes/stabilizer/termreps.cp38-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/termreps.pyx +0 -7
- pygsti/evotypes/stabilizer_slow/effectreps.py +0 -22
- pygsti/evotypes/stabilizer_slow/opreps.py +0 -4
- pygsti/evotypes/stabilizer_slow/statereps.py +0 -4
- pygsti/evotypes/statevec/effectreps.cp38-win32.pyd +0 -0
- pygsti/evotypes/statevec/effectreps.pyx +1 -1
- pygsti/evotypes/statevec/opreps.cp38-win32.pyd +0 -0
- pygsti/evotypes/statevec/opreps.pyx +2 -2
- pygsti/evotypes/statevec/statereps.cp38-win32.pyd +0 -0
- pygsti/evotypes/statevec/statereps.pyx +1 -1
- pygsti/evotypes/statevec/termreps.cp38-win32.pyd +0 -0
- pygsti/evotypes/statevec/termreps.pyx +0 -7
- pygsti/evotypes/statevec_slow/effectreps.py +0 -3
- pygsti/evotypes/statevec_slow/opreps.py +0 -5
- pygsti/extras/__init__.py +0 -1
- pygsti/extras/drift/stabilityanalyzer.py +3 -1
- pygsti/extras/interpygate/__init__.py +12 -0
- pygsti/extras/interpygate/core.py +0 -36
- pygsti/extras/interpygate/process_tomography.py +44 -10
- pygsti/extras/rpe/rpeconstruction.py +0 -2
- pygsti/forwardsims/__init__.py +1 -0
- pygsti/forwardsims/forwardsim.py +14 -55
- pygsti/forwardsims/mapforwardsim.py +69 -18
- pygsti/forwardsims/mapforwardsim_calc_densitymx.cp38-win32.pyd +0 -0
- pygsti/forwardsims/mapforwardsim_calc_densitymx.pyx +65 -66
- pygsti/forwardsims/mapforwardsim_calc_generic.py +91 -13
- pygsti/forwardsims/matrixforwardsim.py +63 -15
- pygsti/forwardsims/termforwardsim.py +8 -110
- pygsti/forwardsims/termforwardsim_calc_stabilizer.cp38-win32.pyd +0 -0
- pygsti/forwardsims/termforwardsim_calc_statevec.cp38-win32.pyd +0 -0
- pygsti/forwardsims/termforwardsim_calc_statevec.pyx +0 -651
- pygsti/forwardsims/torchfwdsim.py +265 -0
- pygsti/forwardsims/weakforwardsim.py +2 -2
- pygsti/io/__init__.py +1 -2
- pygsti/io/mongodb.py +0 -2
- pygsti/io/stdinput.py +6 -22
- pygsti/layouts/copalayout.py +10 -12
- pygsti/layouts/distlayout.py +0 -40
- pygsti/layouts/maplayout.py +103 -25
- pygsti/layouts/matrixlayout.py +99 -60
- pygsti/layouts/prefixtable.py +1534 -52
- pygsti/layouts/termlayout.py +1 -1
- pygsti/modelmembers/instruments/instrument.py +3 -3
- pygsti/modelmembers/instruments/tpinstrument.py +2 -2
- pygsti/modelmembers/modelmember.py +0 -17
- pygsti/modelmembers/operations/__init__.py +2 -4
- pygsti/modelmembers/operations/affineshiftop.py +1 -0
- pygsti/modelmembers/operations/composederrorgen.py +1 -1
- pygsti/modelmembers/operations/composedop.py +1 -24
- pygsti/modelmembers/operations/denseop.py +5 -5
- pygsti/modelmembers/operations/eigpdenseop.py +2 -2
- pygsti/modelmembers/operations/embeddederrorgen.py +1 -1
- pygsti/modelmembers/operations/embeddedop.py +0 -1
- pygsti/modelmembers/operations/experrorgenop.py +2 -2
- pygsti/modelmembers/operations/fullarbitraryop.py +1 -0
- pygsti/modelmembers/operations/fullcptpop.py +2 -2
- pygsti/modelmembers/operations/fulltpop.py +28 -6
- pygsti/modelmembers/operations/fullunitaryop.py +5 -4
- pygsti/modelmembers/operations/lindbladcoefficients.py +93 -78
- pygsti/modelmembers/operations/lindbladerrorgen.py +268 -441
- pygsti/modelmembers/operations/linearop.py +7 -27
- pygsti/modelmembers/operations/opfactory.py +1 -1
- pygsti/modelmembers/operations/repeatedop.py +1 -24
- pygsti/modelmembers/operations/staticstdop.py +1 -1
- pygsti/modelmembers/povms/__init__.py +3 -3
- pygsti/modelmembers/povms/basepovm.py +7 -36
- pygsti/modelmembers/povms/complementeffect.py +4 -9
- pygsti/modelmembers/povms/composedeffect.py +0 -320
- pygsti/modelmembers/povms/computationaleffect.py +1 -1
- pygsti/modelmembers/povms/computationalpovm.py +3 -1
- pygsti/modelmembers/povms/effect.py +3 -5
- pygsti/modelmembers/povms/marginalizedpovm.py +0 -79
- pygsti/modelmembers/povms/tppovm.py +74 -2
- pygsti/modelmembers/states/__init__.py +2 -5
- pygsti/modelmembers/states/composedstate.py +0 -317
- pygsti/modelmembers/states/computationalstate.py +3 -3
- pygsti/modelmembers/states/cptpstate.py +4 -4
- pygsti/modelmembers/states/densestate.py +6 -4
- pygsti/modelmembers/states/fullpurestate.py +0 -24
- pygsti/modelmembers/states/purestate.py +1 -1
- pygsti/modelmembers/states/state.py +5 -6
- pygsti/modelmembers/states/tpstate.py +28 -10
- pygsti/modelmembers/term.py +3 -6
- pygsti/modelmembers/torchable.py +50 -0
- pygsti/modelpacks/_modelpack.py +1 -1
- pygsti/modelpacks/smq1Q_ZN.py +3 -1
- pygsti/modelpacks/smq2Q_XXYYII.py +2 -1
- pygsti/modelpacks/smq2Q_XY.py +3 -3
- pygsti/modelpacks/smq2Q_XYI.py +2 -2
- pygsti/modelpacks/smq2Q_XYICNOT.py +3 -3
- pygsti/modelpacks/smq2Q_XYICPHASE.py +3 -3
- pygsti/modelpacks/smq2Q_XYXX.py +1 -1
- pygsti/modelpacks/smq2Q_XYZICNOT.py +3 -3
- pygsti/modelpacks/smq2Q_XYZZ.py +1 -1
- pygsti/modelpacks/stdtarget.py +0 -121
- pygsti/models/cloudnoisemodel.py +1 -2
- pygsti/models/explicitcalc.py +3 -3
- pygsti/models/explicitmodel.py +3 -13
- pygsti/models/fogistore.py +5 -3
- pygsti/models/localnoisemodel.py +1 -2
- pygsti/models/memberdict.py +0 -12
- pygsti/models/model.py +800 -65
- pygsti/models/modelconstruction.py +4 -4
- pygsti/models/modelnoise.py +2 -2
- pygsti/models/modelparaminterposer.py +1 -1
- pygsti/models/oplessmodel.py +1 -1
- pygsti/models/qutrit.py +15 -14
- pygsti/objectivefns/objectivefns.py +73 -138
- pygsti/objectivefns/wildcardbudget.py +2 -7
- pygsti/optimize/__init__.py +1 -0
- pygsti/optimize/arraysinterface.py +28 -0
- pygsti/optimize/customcg.py +0 -12
- pygsti/optimize/customlm.py +129 -323
- pygsti/optimize/customsolve.py +2 -2
- pygsti/optimize/optimize.py +0 -84
- pygsti/optimize/simplerlm.py +841 -0
- pygsti/optimize/wildcardopt.py +19 -598
- pygsti/protocols/confidenceregionfactory.py +28 -14
- pygsti/protocols/estimate.py +31 -14
- pygsti/protocols/gst.py +142 -68
- pygsti/protocols/modeltest.py +6 -10
- pygsti/protocols/protocol.py +9 -37
- pygsti/protocols/rb.py +450 -79
- pygsti/protocols/treenode.py +8 -2
- pygsti/protocols/vb.py +108 -206
- pygsti/protocols/vbdataframe.py +1 -1
- pygsti/report/factory.py +0 -15
- pygsti/report/fogidiagram.py +1 -17
- pygsti/report/modelfunction.py +12 -3
- pygsti/report/mpl_colormaps.py +1 -1
- pygsti/report/plothelpers.py +8 -2
- pygsti/report/reportables.py +41 -37
- pygsti/report/templates/offline/pygsti_dashboard.css +6 -0
- pygsti/report/templates/offline/pygsti_dashboard.js +12 -0
- pygsti/report/workspace.py +2 -14
- pygsti/report/workspaceplots.py +326 -504
- pygsti/tools/basistools.py +9 -36
- pygsti/tools/edesigntools.py +124 -96
- pygsti/tools/fastcalc.cp38-win32.pyd +0 -0
- pygsti/tools/fastcalc.pyx +35 -81
- pygsti/tools/internalgates.py +151 -15
- pygsti/tools/jamiolkowski.py +5 -5
- pygsti/tools/lindbladtools.py +19 -11
- pygsti/tools/listtools.py +0 -114
- pygsti/tools/matrixmod2.py +1 -1
- pygsti/tools/matrixtools.py +173 -339
- pygsti/tools/nameddict.py +1 -1
- pygsti/tools/optools.py +154 -88
- pygsti/tools/pdftools.py +0 -25
- pygsti/tools/rbtheory.py +3 -320
- pygsti/tools/slicetools.py +64 -12
- pyGSTi-0.9.12.1.dist-info/METADATA +0 -155
- pygsti/algorithms/directx.py +0 -711
- pygsti/evotypes/qibo/__init__.py +0 -33
- pygsti/evotypes/qibo/effectreps.py +0 -78
- pygsti/evotypes/qibo/opreps.py +0 -376
- pygsti/evotypes/qibo/povmreps.py +0 -98
- pygsti/evotypes/qibo/statereps.py +0 -174
- pygsti/extras/rb/__init__.py +0 -13
- pygsti/extras/rb/benchmarker.py +0 -957
- pygsti/extras/rb/dataset.py +0 -378
- pygsti/extras/rb/io.py +0 -814
- pygsti/extras/rb/simulate.py +0 -1020
- pygsti/io/legacyio.py +0 -385
- pygsti/modelmembers/povms/denseeffect.py +0 -142
- {pyGSTi-0.9.12.1.dist-info → pyGSTi-0.9.13.dist-info}/LICENSE +0 -0
- {pyGSTi-0.9.12.1.dist-info → pyGSTi-0.9.13.dist-info}/top_level.txt +0 -0
pygsti/evotypes/qibo/__init__.py
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
An evolution type that uses the 3rd-party 'qibo' package.
|
3
|
-
"""
|
4
|
-
#***************************************************************************************************
|
5
|
-
# Copyright 2015, 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
6
|
-
# Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights
|
7
|
-
# in this software.
|
8
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
9
|
-
# in compliance with the License. You may obtain a copy of the License at
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0 or in the LICENSE file in the root pyGSTi directory.
|
11
|
-
#***************************************************************************************************
|
12
|
-
|
13
|
-
densitymx_mode = False
|
14
|
-
nshots = 1000
|
15
|
-
|
16
|
-
|
17
|
-
def _get_densitymx_mode():
|
18
|
-
return densitymx_mode
|
19
|
-
|
20
|
-
|
21
|
-
def _get_nshots():
|
22
|
-
return nshots
|
23
|
-
|
24
|
-
|
25
|
-
def _get_minimal_space():
|
26
|
-
return minimal_space
|
27
|
-
|
28
|
-
|
29
|
-
minimal_space = 'Hilbert'
|
30
|
-
from .povmreps import *
|
31
|
-
from .effectreps import *
|
32
|
-
from .opreps import *
|
33
|
-
from .statereps import *
|
@@ -1,78 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
POVM effect representation classes for the `qibo` evolution type.
|
3
|
-
"""
|
4
|
-
#***************************************************************************************************
|
5
|
-
# Copyright 2015, 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
6
|
-
# Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights
|
7
|
-
# in this software.
|
8
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
9
|
-
# in compliance with the License. You may obtain a copy of the License at
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0 or in the LICENSE file in the root pyGSTi directory.
|
11
|
-
#***************************************************************************************************
|
12
|
-
import numpy as _np
|
13
|
-
|
14
|
-
from .. import basereps as _basereps
|
15
|
-
from pygsti.baseobjs.statespace import StateSpace as _StateSpace
|
16
|
-
|
17
|
-
from . import _get_densitymx_mode, _get_nshots
|
18
|
-
|
19
|
-
|
20
|
-
class EffectRep(_basereps.EffectRep):
|
21
|
-
def __init__(self, state_space):
|
22
|
-
self.state_space = _StateSpace.cast(state_space)
|
23
|
-
|
24
|
-
@property
|
25
|
-
def nqubits(self):
|
26
|
-
return self.state_space.num_qubits
|
27
|
-
|
28
|
-
|
29
|
-
class EffectRepComputational(EffectRep):
|
30
|
-
def __init__(self, zvals, basis, state_space):
|
31
|
-
self.zvals = zvals
|
32
|
-
self.basis = basis
|
33
|
-
super(EffectRepComputational, self).__init__(state_space)
|
34
|
-
|
35
|
-
|
36
|
-
class EffectRepConjugatedState(EffectRep):
|
37
|
-
|
38
|
-
def __init__(self, state_rep):
|
39
|
-
self.state_rep = state_rep
|
40
|
-
super(EffectRepConjugatedState, self).__init__(state_rep.state_space)
|
41
|
-
|
42
|
-
def probability(self, state):
|
43
|
-
# compute <s2|s1>
|
44
|
-
assert(_get_densitymx_mode() is True), "Can only use EffectRepConjugatedState when densitymx_mode == True!"
|
45
|
-
|
46
|
-
initial_state = state.qibo_state
|
47
|
-
effect_state = self.state_rep.qibo_state
|
48
|
-
if effect_state.ndim == 1: # b/c qibo_state can be either a vector or density mx
|
49
|
-
#Promote this state vector to a density matrix to use it as a POVM effect
|
50
|
-
effect_state = _np.kron(effect_state[:, None], effect_state.conjugate()[None, :])
|
51
|
-
assert(effect_state.ndim == 2) # density matrices
|
52
|
-
|
53
|
-
qibo_circuit = state.qibo_circuit
|
54
|
-
results = qibo_circuit(initial_state)
|
55
|
-
return _np.real_if_close(_np.dot(effect_state.flatten().conjugate(), results.state().flatten()))
|
56
|
-
|
57
|
-
def to_dense(self, on_space):
|
58
|
-
return self.state_rep.to_dense(on_space)
|
59
|
-
|
60
|
-
@property
|
61
|
-
def basis(self):
|
62
|
-
# (all qibo effect reps need to have a .basis property)
|
63
|
-
return self.state_rep.basis
|
64
|
-
|
65
|
-
|
66
|
-
class EffectRepComposed(EffectRep):
|
67
|
-
def __init__(self, op_rep, effect_rep, op_id, state_space):
|
68
|
-
self.op_rep = op_rep
|
69
|
-
self.effect_rep = effect_rep
|
70
|
-
self.op_id = op_id
|
71
|
-
|
72
|
-
self.state_space = _StateSpace.cast(state_space)
|
73
|
-
assert(self.state_space.is_compatible_with(effect_rep.state_space))
|
74
|
-
|
75
|
-
super(EffectRepComposed, self).__init__(effect_rep.state_space)
|
76
|
-
|
77
|
-
def probability(self, state):
|
78
|
-
return self.effect_rep.probability(self.op_rep.acton(state))
|
pygsti/evotypes/qibo/opreps.py
DELETED
@@ -1,376 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Operation representation classes for the `qibo` evolution type.
|
3
|
-
"""
|
4
|
-
#***************************************************************************************************
|
5
|
-
# Copyright 2015, 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
6
|
-
# Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights
|
7
|
-
# in this software.
|
8
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
9
|
-
# in compliance with the License. You may obtain a copy of the License at
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0 or in the LICENSE file in the root pyGSTi directory.
|
11
|
-
#***************************************************************************************************
|
12
|
-
|
13
|
-
import itertools as _itertools
|
14
|
-
import copy as _copy
|
15
|
-
from functools import partial as _partial
|
16
|
-
|
17
|
-
import numpy as _np
|
18
|
-
from scipy.sparse.linalg import LinearOperator
|
19
|
-
from numpy.random import RandomState as _RandomState
|
20
|
-
|
21
|
-
from . import _get_minimal_space
|
22
|
-
from .statereps import StateRep as _StateRep
|
23
|
-
from .. import basereps as _basereps
|
24
|
-
from pygsti.baseobjs.statespace import StateSpace as _StateSpace
|
25
|
-
from pygsti.baseobjs.basis import Basis as _Basis
|
26
|
-
from ...tools import jamiolkowski as _jt
|
27
|
-
from ...tools import basistools as _bt
|
28
|
-
from ...tools import internalgates as _itgs
|
29
|
-
from ...tools import optools as _ot
|
30
|
-
|
31
|
-
|
32
|
-
try:
|
33
|
-
import qibo as _qibo
|
34
|
-
|
35
|
-
std_qibo_creation_fns = { # functions that create the desired op given qubit indices & gate args
|
36
|
-
'Gi': _qibo.gates.I,
|
37
|
-
'Gxpi2': _partial(_qibo.gates.RX, theta=_np.pi / 2, trainable=False),
|
38
|
-
'Gypi2': _partial(_qibo.gates.RY, theta=_np.pi / 2, trainable=False),
|
39
|
-
'Gzpi2': _partial(_qibo.gates.RZ, theta=_np.pi / 2, trainable=False),
|
40
|
-
'Gxpi': _qibo.gates.X,
|
41
|
-
'Gypi': _qibo.gates.Y,
|
42
|
-
'Gzpi': _qibo.gates.Z,
|
43
|
-
'Gxmpi2': _partial(_qibo.gates.RX, theta=-_np.pi / 2, trainable=False),
|
44
|
-
'Gympi2': _partial(_qibo.gates.RY, theta=-_np.pi / 2, trainable=False),
|
45
|
-
'Gzmpi2': _partial(_qibo.gates.RZ, theta=-_np.pi / 2, trainable=False),
|
46
|
-
'Gh': _qibo.gates.H,
|
47
|
-
'Gp': _qibo.gates.S,
|
48
|
-
'Gpdag': _partial(_qibo.gates.U1, theta=-_np.pi / 2, trainable=False),
|
49
|
-
'Gt': _qibo.gates.T,
|
50
|
-
'Gtdag': _partial(_qibo.gates.U1, theta=-_np.pi / 4, trainable=False),
|
51
|
-
'Gcphase': _qibo.gates.CZ,
|
52
|
-
'Gcnot': _qibo.gates.CNOT,
|
53
|
-
'Gswap': _qibo.gates.SWAP,
|
54
|
-
#'Gzr': _qibo.gates.RZ, # takes (q, theta)
|
55
|
-
#'Gczr': _qibo.gates.CRZ, # takes (q0, q1, theta)
|
56
|
-
'Gx': _partial(_qibo.gates.RX, theta=_np.pi / 2, trainable=False),
|
57
|
-
'Gy': _partial(_qibo.gates.RY, theta=_np.pi / 2, trainable=False),
|
58
|
-
'Gz': _partial(_qibo.gates.RZ, theta=_np.pi / 2, trainable=False)
|
59
|
-
}
|
60
|
-
except (ImportError, AttributeError): # AttributeError if an early version of qibo without some of the above gates
|
61
|
-
_qibo = None
|
62
|
-
|
63
|
-
|
64
|
-
class OpRep(_basereps.OpRep):
|
65
|
-
def __init__(self, state_space):
|
66
|
-
self.state_space = state_space
|
67
|
-
|
68
|
-
@property
|
69
|
-
def dim(self):
|
70
|
-
return self.state_space.udim
|
71
|
-
|
72
|
-
def create_qibo_ops_on(self, qubit_indices):
|
73
|
-
raise NotImplementedError("Derived classes must implement this!")
|
74
|
-
|
75
|
-
def acton(self, state):
|
76
|
-
c = state.qibo_circuit.copy()
|
77
|
-
# TODO: change below to: sole_tensor_product_block_labels
|
78
|
-
for qibo_op in self.create_qibo_ops_on(self.state_space.tensor_product_block_labels(0)):
|
79
|
-
c.add(qibo_op)
|
80
|
-
return _StateRep(c, state.qibo_state.copy(), state.state_space)
|
81
|
-
|
82
|
-
def adjoint_acton(self, state):
|
83
|
-
raise NotImplementedError()
|
84
|
-
|
85
|
-
def acton_random(self, state, rand_state):
|
86
|
-
return self.acton(state) # default is to ignore rand_state
|
87
|
-
|
88
|
-
def adjoint_acton_random(self, state, rand_state):
|
89
|
-
return self.adjoint_acton(state) # default is to ignore rand_state
|
90
|
-
|
91
|
-
# def aslinearoperator(self):
|
92
|
-
# def mv(v):
|
93
|
-
# if v.ndim == 2 and v.shape[1] == 1: v = v[:, 0]
|
94
|
-
# in_state = _StateRepDensePure(_np.ascontiguousarray(v, complex), self.state_space, basis=None)
|
95
|
-
# return self.acton(in_state).to_dense('Hilbert')
|
96
|
-
#
|
97
|
-
# def rmv(v):
|
98
|
-
# if v.ndim == 2 and v.shape[1] == 1: v = v[:, 0]
|
99
|
-
# in_state = _StateRepDensePure(_np.ascontiguousarray(v, complex), self.state_space, basis=None)
|
100
|
-
# return self.adjoint_acton(in_state).to_dense('Hilbert')
|
101
|
-
# return LinearOperator((self.dim, self.dim), matvec=mv, rmatvec=rmv) # transpose, adjoint, dot, matmat?
|
102
|
-
|
103
|
-
def copy(self):
|
104
|
-
return _copy.deepcopy(self)
|
105
|
-
|
106
|
-
|
107
|
-
class OpRepDenseUnitary(OpRep):
|
108
|
-
def __init__(self, mx, basis, state_space):
|
109
|
-
state_space = _StateSpace.cast(state_space)
|
110
|
-
if mx is None:
|
111
|
-
mx = _np.identity(state_space.udim, complex)
|
112
|
-
assert(mx.ndim == 2 and mx.shape[0] == state_space.udim)
|
113
|
-
self.basis = basis
|
114
|
-
self.base = _np.require(mx, requirements=['OWNDATA', 'C_CONTIGUOUS'])
|
115
|
-
super(OpRepDenseUnitary, self).__init__(state_space)
|
116
|
-
|
117
|
-
def create_qibo_ops_on(self, qubit_indices):
|
118
|
-
return [_qibo.gates.UnitaryChannel([1.0], [(qubit_indices, self.base)], seed=None)]
|
119
|
-
|
120
|
-
def base_has_changed(self):
|
121
|
-
pass # nothing needed
|
122
|
-
|
123
|
-
def to_dense(self, on_space):
|
124
|
-
if on_space == 'Hilbert' or (on_space == 'minimal' and _get_minimal_space() == 'Hilbert'):
|
125
|
-
return self.base
|
126
|
-
elif on_space == 'HilbertSchmidt' or (on_space == 'minimal' and _get_minimal_space() == 'HilbertSchmidt'):
|
127
|
-
return _ot.unitary_to_superop(self.base, self.basis)
|
128
|
-
else:
|
129
|
-
raise ValueError("Invalid `on_space` argument: %s" % str(on_space))
|
130
|
-
|
131
|
-
def __str__(self):
|
132
|
-
return "OpRepDenseUnitary:\n" + str(self.base)
|
133
|
-
|
134
|
-
|
135
|
-
class OpRepDenseSuperop(OpRep):
|
136
|
-
def __init__(self, mx, basis, state_space):
|
137
|
-
state_space = _StateSpace.cast(state_space)
|
138
|
-
if mx is None:
|
139
|
-
mx = _np.identity(state_space.dim, 'd')
|
140
|
-
assert(mx.ndim == 2 and mx.shape[0] == state_space.dim)
|
141
|
-
self.basis = basis
|
142
|
-
assert(self.basis is not None), "Qibo evotype requires OpRepDenseSuperop be given a basis (to get Kraus ops!)"
|
143
|
-
|
144
|
-
self.base = _np.require(mx, requirements=['OWNDATA', 'C_CONTIGUOUS'])
|
145
|
-
super(OpRepDenseSuperop, self).__init__(state_space)
|
146
|
-
self.base_has_changed() # sets self.kraus_ops
|
147
|
-
|
148
|
-
def base_has_changed(self):
|
149
|
-
#recompute Kraus ops for creating qibo op
|
150
|
-
superop_mx = self.base; d = int(_np.round(_np.sqrt(superop_mx.shape[0])))
|
151
|
-
std_basis = _Basis.cast('std', superop_mx.shape[0])
|
152
|
-
choi_mx = _jt.jamiolkowski_iso(superop_mx, self.basis, std_basis) * d # see NOTE below
|
153
|
-
evals, evecs = _np.linalg.eig(choi_mx)
|
154
|
-
assert(all([ev > -1e-7 for ev in evals])), \
|
155
|
-
"Cannot compute Kraus decomposition of non-positive-definite superoperator (within OpRepDenseSuperop!)"
|
156
|
-
self.kraus_ops = [evecs[:, i].reshape(d, d) * _np.sqrt(ev) for i, ev in enumerate(evals) if abs(ev) > 1e-7]
|
157
|
-
|
158
|
-
def to_dense(self, on_space):
|
159
|
-
if not (on_space == 'HilbertSchmidt' or (on_space == 'minimal' and _get_minimal_space() == 'HilbertSchmidt')):
|
160
|
-
raise ValueError("'densitymx_slow' evotype cannot produce Hilbert-space ops!")
|
161
|
-
return self.base
|
162
|
-
|
163
|
-
def create_qibo_ops_on(self, qubit_indices):
|
164
|
-
return [_qibo.gates.KrausChannel([(qubit_indices, Ki) for Ki in self.kraus_ops])]
|
165
|
-
|
166
|
-
def __str__(self):
|
167
|
-
return "OpRepDenseSuperop:\n" + str(self.base)
|
168
|
-
|
169
|
-
def copy(self):
|
170
|
-
return OpRepDenseSuperop(self.base.copy(), self.basis, self.state_space)
|
171
|
-
|
172
|
-
|
173
|
-
class OpRepStandard(OpRep):
|
174
|
-
def __init__(self, name, basis, state_space):
|
175
|
-
self.name = name
|
176
|
-
if self.name not in std_qibo_creation_fns:
|
177
|
-
raise ValueError("Standard name '%s' is not available in 'qibo' evotype" % self.name)
|
178
|
-
|
179
|
-
self.basis = basis # used anywhere?
|
180
|
-
self.creation_fn = std_qibo_creation_fns[name]
|
181
|
-
# create the desired op given qubit indices & gate args
|
182
|
-
|
183
|
-
super(OpRepStandard, self).__init__(state_space)
|
184
|
-
|
185
|
-
def create_qibo_ops_on(self, qubit_indices):
|
186
|
-
return [self.creation_fn(*qubit_indices)]
|
187
|
-
|
188
|
-
|
189
|
-
#class OpRepStochastic(OpRepDense):
|
190
|
-
# - maybe we could add this, but it wouldn't be a "dense" op here,
|
191
|
-
# perhaps we need to change API?
|
192
|
-
|
193
|
-
|
194
|
-
class OpRepComposed(OpRep):
|
195
|
-
# exactly the same as densitymx case
|
196
|
-
def __init__(self, factor_op_reps, state_space):
|
197
|
-
#assert(len(factor_op_reps) > 0), "Composed gates must contain at least one factor gate!"
|
198
|
-
self.factor_reps = factor_op_reps
|
199
|
-
super(OpRepComposed, self).__init__(state_space)
|
200
|
-
|
201
|
-
def create_qibo_ops_on(self, qubit_indices):
|
202
|
-
return list(_itertools.chain(*[f.create_qibo_ops_on(qubit_indices) for f in self.factor_reps]))
|
203
|
-
|
204
|
-
def reinit_factor_op_reps(self, new_factor_op_reps):
|
205
|
-
self.factors_reps = new_factor_op_reps
|
206
|
-
|
207
|
-
|
208
|
-
# This might work, but we won't need it unless we get OpRepExpErrorgen, etc, working.
|
209
|
-
#class OpRepSum(OpRep):
|
210
|
-
# # exactly the same as densitymx case
|
211
|
-
# def __init__(self, factor_reps, state_space):
|
212
|
-
# #assert(len(factor_reps) > 0), "Composed gates must contain at least one factor gate!"
|
213
|
-
# self.factor_reps = factor_reps
|
214
|
-
# super(OpRepSum, self).__init__(state_space)
|
215
|
-
#
|
216
|
-
# def acton(self, state):
|
217
|
-
# """ Act this gate map on an input state """
|
218
|
-
# output_state = _StateRepDensePure(_np.zeros(state.data.shape, complex), state.state_space, state.basis)
|
219
|
-
# for f in self.factor_reps:
|
220
|
-
# output_state.data += f.acton(state).data
|
221
|
-
# return output_state
|
222
|
-
#
|
223
|
-
# def adjoint_acton(self, state):
|
224
|
-
# """ Act the adjoint of this operation matrix on an input state """
|
225
|
-
# output_state = _StateRepDensePure(_np.zeros(state.data.shape, complex), state.state_space, state.basis)
|
226
|
-
# for f in self.factor_reps:
|
227
|
-
# output_state.data += f.adjoint_acton(state).data
|
228
|
-
# return output_state
|
229
|
-
#
|
230
|
-
# def acton_random(self, state, rand_state):
|
231
|
-
# """ Act this gate map on an input state """
|
232
|
-
# output_state = _StateRepDensePure(_np.zeros(state.data.shape, complex), state.state_space, state.basis)
|
233
|
-
# for f in self.factor_reps:
|
234
|
-
# output_state.data += f.acton_random(state, rand_state).data
|
235
|
-
# return output_state
|
236
|
-
#
|
237
|
-
# def adjoint_acton_random(self, state, rand_state):
|
238
|
-
# """ Act the adjoint of this operation matrix on an input state """
|
239
|
-
# output_state = _StateRepDensePure(_np.zeros(state.data.shape, complex), state.state_space, state.basis)
|
240
|
-
# for f in self.factor_reps:
|
241
|
-
# output_state.data += f.adjoint_acton_random(state, rand_state).data
|
242
|
-
# return output_state
|
243
|
-
|
244
|
-
|
245
|
-
class OpRepEmbedded(OpRep):
|
246
|
-
|
247
|
-
def __init__(self, state_space, target_labels, embedded_rep):
|
248
|
-
self.target_labels = target_labels
|
249
|
-
self.embedded_rep = embedded_rep
|
250
|
-
super(OpRepEmbedded, self).__init__(state_space)
|
251
|
-
|
252
|
-
def create_qibo_ops_on(self, qubit_indices):
|
253
|
-
# TODO: change below to: sole_tensor_product_block_labels
|
254
|
-
assert(qubit_indices == self.state_space.tensor_product_block_labels(0))
|
255
|
-
return self.embedded_rep.create_qibo_ops_on(self.target_labels)
|
256
|
-
|
257
|
-
|
258
|
-
#REMOVE
|
259
|
-
#class OpRepExpErrorgen(OpRep):
|
260
|
-
#
|
261
|
-
# def __init__(self, errorgen_rep):
|
262
|
-
# state_space = errorgen_rep.state_space
|
263
|
-
# self.errorgen_rep = errorgen_rep
|
264
|
-
# super(OpRepExpErrorgen, self).__init__(state_space)
|
265
|
-
#
|
266
|
-
# def errgenrep_has_changed(self, onenorm_upperbound):
|
267
|
-
# pass
|
268
|
-
#
|
269
|
-
# def acton(self, state):
|
270
|
-
# raise AttributeError("Cannot currently act with statevec.OpRepExpErrorgen - for terms only!")
|
271
|
-
#
|
272
|
-
# def adjoint_acton(self, state):
|
273
|
-
# raise AttributeError("Cannot currently act with statevec.OpRepExpErrorgen - for terms only!")
|
274
|
-
|
275
|
-
|
276
|
-
class OpRepRepeated(OpRep):
|
277
|
-
def __init__(self, rep_to_repeat, num_repetitions, state_space):
|
278
|
-
state_space = _StateSpace.cast(state_space)
|
279
|
-
self.repeated_rep = rep_to_repeat
|
280
|
-
self.num_repetitions = num_repetitions
|
281
|
-
super(OpRepRepeated, self).__init__(state_space)
|
282
|
-
|
283
|
-
def create_qibo_ops_on(self, qubit_indices):
|
284
|
-
return [self.repeated_rep.create_qibo_ops_on(qubit_indices)] * self.num_repetitions
|
285
|
-
|
286
|
-
|
287
|
-
#REMOVE
|
288
|
-
#class OpRepLindbladErrorgen(OpRep):
|
289
|
-
# def __init__(self, lindblad_coefficient_blocks, state_space):
|
290
|
-
# super(OpRepLindbladErrorgen, self).__init__(state_space)
|
291
|
-
# self.Lterms = None
|
292
|
-
# self.Lterm_coeffs = None
|
293
|
-
# self.lindblad_coefficient_blocks = lindblad_coefficient_blocks
|
294
|
-
|
295
|
-
|
296
|
-
class OpRepKraus(OpRep):
|
297
|
-
def __init__(self, basis, kraus_reps, state_space):
|
298
|
-
self.basis = basis
|
299
|
-
self.kraus_reps = kraus_reps # superop reps in this evotype (must be reps of *this* evotype)
|
300
|
-
assert(all([isinstance(rep, OpRepDenseUnitary) for rep in kraus_reps]))
|
301
|
-
state_space = _StateSpace.cast(state_space)
|
302
|
-
assert(self.basis.dim == state_space.dim)
|
303
|
-
super(OpRepKraus, self).__init__(state_space)
|
304
|
-
|
305
|
-
def create_qibo_ops_on(self, qubit_indices):
|
306
|
-
kraus_ops = [Krep.base for Krep in self.kraus_reps]
|
307
|
-
kraus_norms = list(map(_np.linalg.norm, kraus_ops))
|
308
|
-
return [_qibo.gates.KrausChannel([(qubit_indices, Ki)
|
309
|
-
for Ki, nrm in zip(kraus_ops, kraus_norms) if nrm > 1e-7])]
|
310
|
-
|
311
|
-
def __str__(self):
|
312
|
-
return "OpRepKraus with ops\n" + str(self.kraus_reps)
|
313
|
-
|
314
|
-
def copy(self):
|
315
|
-
return OpRepKraus(self.basis, list(self.kraus_reps), None, self.state_space)
|
316
|
-
|
317
|
-
def to_dense(self, on_space):
|
318
|
-
assert(on_space == 'HilbertSchmidt' or (on_space == 'minimal' and _get_minimal_space() == 'HilbertSchmidt')), \
|
319
|
-
'Can only compute OpRepKraus.to_dense on HilbertSchmidt space!'
|
320
|
-
return sum([rep.to_dense(on_space) for rep in self.kraus_reps])
|
321
|
-
|
322
|
-
|
323
|
-
class OpRepRandomUnitary(OpRep):
|
324
|
-
def __init__(self, basis, unitary_rates, unitary_reps, seed_or_state, state_space):
|
325
|
-
self.basis = basis
|
326
|
-
self.unitary_reps = unitary_reps
|
327
|
-
self.unitary_rates = unitary_rates.copy()
|
328
|
-
|
329
|
-
if isinstance(seed_or_state, _RandomState):
|
330
|
-
self.rand_state = seed_or_state
|
331
|
-
else:
|
332
|
-
self.rand_state = _RandomState(seed_or_state)
|
333
|
-
|
334
|
-
self.state_space = _StateSpace.cast(state_space)
|
335
|
-
assert(self.basis.dim == self.state_space.dim)
|
336
|
-
super(OpRepRandomUnitary, self).__init__(state_space)
|
337
|
-
|
338
|
-
def create_qibo_ops_on(self, qubit_indices):
|
339
|
-
return [_qibo.gates.UnitaryChannel(self.unitary_rates, [(qubit_indices, Uk.to_dense('Hilbert'))
|
340
|
-
for Uk in self.unitary_reps],
|
341
|
-
seed=self.rand_state.randint(0, 2**30))] # HARDCODED 2**30!! (max seed)
|
342
|
-
|
343
|
-
def __str__(self):
|
344
|
-
return "OpRepRandomUnitary:\n" + " rates: " + str(self.unitary_rates) # maybe show ops too?
|
345
|
-
|
346
|
-
def copy(self):
|
347
|
-
return OpRepRandomUnitary(self.basis, self.unitary_rates, list(self.unitary_reps),
|
348
|
-
self.rand_state, self.state_space)
|
349
|
-
|
350
|
-
def update_unitary_rates(self, rates):
|
351
|
-
self.unitary_rates[:] = rates
|
352
|
-
|
353
|
-
def to_dense(self, on_space):
|
354
|
-
assert(on_space == 'HilbertSchmidt') # below code only works in this case
|
355
|
-
return sum([rate * rep.to_dense(on_space) for rate, rep in zip(self.unitary_rates, self.unitary_reps)])
|
356
|
-
|
357
|
-
|
358
|
-
class OpRepStochastic(OpRepRandomUnitary):
|
359
|
-
|
360
|
-
def __init__(self, stochastic_basis, basis, initial_rates, seed_or_state, state_space):
|
361
|
-
self.rates = initial_rates
|
362
|
-
self.stochastic_basis = stochastic_basis
|
363
|
-
rates = [1 - sum(initial_rates)] + list(initial_rates)
|
364
|
-
reps = [OpRepDenseUnitary(bel, basis, state_space) for bel in stochastic_basis.elements]
|
365
|
-
assert(len(reps) == len(rates))
|
366
|
-
|
367
|
-
state_space = _StateSpace.cast(state_space)
|
368
|
-
assert(basis.dim == state_space.dim)
|
369
|
-
self.basis = basis
|
370
|
-
|
371
|
-
super(OpRepStochastic, self).__init__(basis, _np.array(rates, 'd'), reps, seed_or_state, state_space)
|
372
|
-
|
373
|
-
def update_rates(self, rates):
|
374
|
-
unitary_rates = [1 - sum(rates)] + list(rates)
|
375
|
-
self.rates[:] = rates
|
376
|
-
self.update_unitary_rates(unitary_rates)
|
pygsti/evotypes/qibo/povmreps.py
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
POVM representation classes for the `qibo` evolution type.
|
3
|
-
"""
|
4
|
-
#***************************************************************************************************
|
5
|
-
# Copyright 2015, 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
6
|
-
# Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights
|
7
|
-
# in this software.
|
8
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
9
|
-
# in compliance with the License. You may obtain a copy of the License at
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0 or in the LICENSE file in the root pyGSTi directory.
|
11
|
-
#***************************************************************************************************
|
12
|
-
|
13
|
-
import os as _os
|
14
|
-
import re as _re
|
15
|
-
import subprocess as _sp
|
16
|
-
import tempfile as _tf
|
17
|
-
import numpy as _np
|
18
|
-
|
19
|
-
from .. import basereps as _basereps
|
20
|
-
from . import _get_densitymx_mode, _get_nshots
|
21
|
-
from pygsti.baseobjs.statespace import StateSpace as _StateSpace
|
22
|
-
from pygsti.baseobjs.outcomelabeldict import OutcomeLabelDict as _OutcomeLabelDict
|
23
|
-
|
24
|
-
try:
|
25
|
-
import qibo as _qibo
|
26
|
-
except ImportError:
|
27
|
-
_qibo = None
|
28
|
-
|
29
|
-
|
30
|
-
class POVMRep(_basereps.POVMRep):
|
31
|
-
def __init__(self):
|
32
|
-
super(POVMRep, self).__init__()
|
33
|
-
|
34
|
-
|
35
|
-
class ComputationalPOVMRep(POVMRep):
|
36
|
-
def __init__(self, nqubits, qubit_filter):
|
37
|
-
self.nqubits = nqubits
|
38
|
-
self.qubit_filter = qubit_filter
|
39
|
-
super(ComputationalPOVMRep, self).__init__()
|
40
|
-
|
41
|
-
#REMOVE
|
42
|
-
#def sample_outcome(self, state, rand_state):
|
43
|
-
# chp_ops = state.chp_ops
|
44
|
-
#
|
45
|
-
# povm_qubits = _np.array(range(self.nqubits))
|
46
|
-
# for iqubit in povm_qubits:
|
47
|
-
# if self.qubit_filter is None or iqubit in self.qubit_filter:
|
48
|
-
# chp_ops.append(f'm {iqubit}')
|
49
|
-
#
|
50
|
-
# # TODO: Make sure this handles intermediate measurements
|
51
|
-
# outcomes, _ = self._run_chp_ops(chp_ops)
|
52
|
-
# outcome = ''.join(outcomes)
|
53
|
-
# outcome_label = _OutcomeLabelDict.to_outcome(outcome)
|
54
|
-
# return outcome_label
|
55
|
-
|
56
|
-
def probabilities(self, state, rand_state, effect_labels):
|
57
|
-
qibo_circuit = state.qibo_circuit
|
58
|
-
initial_state = state.qibo_state
|
59
|
-
# TODO: change below to: sole_tensor_product_block_labels
|
60
|
-
qubits_to_measure = state.state_space.tensor_product_block_labels(0) \
|
61
|
-
if (self.qubit_filter is None) else self.qubit_filter
|
62
|
-
|
63
|
-
gatetypes_requiring_shots = set(('UnitaryChannel', 'PauliNoiseChannel',
|
64
|
-
'ResetChannel', 'ThermalRelaxationChannel'))
|
65
|
-
circuit_requires_shots = len(gatetypes_requiring_shots.intersection(set(qibo_circuit.gate_types.keys()))) > 0
|
66
|
-
if _get_densitymx_mode() or circuit_requires_shots is False:
|
67
|
-
#then we can use QIBO's exact .probabilities call:
|
68
|
-
results = qibo_circuit(initial_state)
|
69
|
-
prob_tensor = results.probabilities(qubits_to_measure)
|
70
|
-
|
71
|
-
probs = [prob_tensor[tuple(map(int, effect_lbl))] for effect_lbl in effect_labels]
|
72
|
-
# Above map & int converts, e.g., '01' -> (0,1)
|
73
|
-
else:
|
74
|
-
#we must use built-in weak fwdsim
|
75
|
-
qibo_circuit.add(_qibo.gates.M(*qubits_to_measure))
|
76
|
-
nshots = _get_nshots()
|
77
|
-
results = qibo_circuit(initial_state, nshots=nshots)
|
78
|
-
freqs = results.frequencies(binary=True)
|
79
|
-
probs = [freqs[effect_lbl] / nshots for effect_lbl in effect_labels]
|
80
|
-
|
81
|
-
return probs
|
82
|
-
|
83
|
-
|
84
|
-
class ComposedPOVMRep(POVMRep):
|
85
|
-
def __init__(self, errmap_rep, base_povm_rep, state_space):
|
86
|
-
self.errmap_rep = errmap_rep
|
87
|
-
self.base_povm_rep = base_povm_rep
|
88
|
-
self.state_space = state_space
|
89
|
-
super(ComposedPOVMRep, self).__init__()
|
90
|
-
|
91
|
-
#REMOVE
|
92
|
-
# def sample_outcome(self, state, rand_state):
|
93
|
-
# state = self.errmap_rep.acton_random(state, rand_state)
|
94
|
-
# return self.base_povm_rep.sample_outcome(state)
|
95
|
-
|
96
|
-
def probabilities(self, state, rand_state, effect_labels):
|
97
|
-
state = self.errmap_rep.acton_random(state, rand_state)
|
98
|
-
return self.base_povm_rep.probabilities(state, rand_state, effect_labels)
|