pyGSTi 0.9.12.1__cp310-cp310-win32.whl → 0.9.13__cp310-cp310-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 +197 -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.cp310-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.cp310-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.cp310-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.cp310-win32.pyd +0 -0
- pygsti/evotypes/densitymx/effectreps.pyx +1 -1
- pygsti/evotypes/densitymx/opreps.cp310-win32.pyd +0 -0
- pygsti/evotypes/densitymx/opreps.pyx +2 -2
- pygsti/evotypes/densitymx/statereps.cp310-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.cp310-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/effectreps.pyx +0 -4
- pygsti/evotypes/stabilizer/opreps.cp310-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/opreps.pyx +0 -4
- pygsti/evotypes/stabilizer/statereps.cp310-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/statereps.pyx +1 -5
- pygsti/evotypes/stabilizer/termreps.cp310-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.cp310-win32.pyd +0 -0
- pygsti/evotypes/statevec/effectreps.pyx +1 -1
- pygsti/evotypes/statevec/opreps.cp310-win32.pyd +0 -0
- pygsti/evotypes/statevec/opreps.pyx +2 -2
- pygsti/evotypes/statevec/statereps.cp310-win32.pyd +0 -0
- pygsti/evotypes/statevec/statereps.pyx +1 -1
- pygsti/evotypes/statevec/termreps.cp310-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.cp310-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.cp310-win32.pyd +0 -0
- pygsti/forwardsims/termforwardsim_calc_statevec.cp310-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.cp310-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
@@ -99,7 +99,7 @@ def create_spam_vector(vec_expr, state_space, basis):
|
|
99
99
|
std_basis = basis.create_equivalent('std')
|
100
100
|
vecInSimpleStdBasis = _np.zeros(std_basis.elshape, 'd') # a matrix, but flattened it is our spamvec
|
101
101
|
vecInSimpleStdBasis[index, index] = 1.0 # now a matrix with just a single 1 on the diag
|
102
|
-
vecInReducedStdBasis =
|
102
|
+
vecInReducedStdBasis = std_basis.from_elementstd_transform_matrix @ vecInSimpleStdBasis.ravel()
|
103
103
|
# translates the density matrix / state vector to the std basis with our desired block structure
|
104
104
|
|
105
105
|
vec = _bt.change_basis(vecInReducedStdBasis, std_basis, basis)
|
@@ -752,7 +752,7 @@ def _create_explicit_model(processor_spec, modelnoise, custom_gates=None, evotyp
|
|
752
752
|
state_space = _statespace.QubitSpace(qudit_labels) if all([udim == 2 for udim in processor_spec.qudit_udims]) \
|
753
753
|
else _statespace.QuditSpace(qudit_labels, processor_spec.qudit_udims)
|
754
754
|
std_gate_unitaries = _itgs.standard_gatename_unitaries()
|
755
|
-
evotype = _Evotype.cast(evotype)
|
755
|
+
evotype = _Evotype.cast(evotype, state_space=state_space)
|
756
756
|
modelnoise = _OpModelNoise.cast(modelnoise)
|
757
757
|
modelnoise.reset_access_counters()
|
758
758
|
|
@@ -1676,7 +1676,7 @@ def _create_crosstalk_free_model(processor_spec, modelnoise, custom_gates=None,
|
|
1676
1676
|
qudit_labels = processor_spec.qudit_labels
|
1677
1677
|
state_space = _statespace.QubitSpace(qudit_labels) if all([udim == 2 for udim in processor_spec.qudit_udims]) \
|
1678
1678
|
else _statespace.QuditSpace(qudit_labels, processor_spec.qudit_udims)
|
1679
|
-
evotype = _Evotype.cast(evotype)
|
1679
|
+
evotype = _Evotype.cast(evotype, state_space=state_space)
|
1680
1680
|
modelnoise = _OpModelNoise.cast(modelnoise)
|
1681
1681
|
modelnoise.reset_access_counters()
|
1682
1682
|
|
@@ -1867,7 +1867,7 @@ def _create_cloud_crosstalk_model(processor_spec, modelnoise, custom_gates=None,
|
|
1867
1867
|
qudit_labels = processor_spec.qudit_labels
|
1868
1868
|
state_space = _statespace.QubitSpace(qudit_labels) if all([udim == 2 for udim in processor_spec.qudit_udims]) \
|
1869
1869
|
else _statespace.QuditSpace(qudit_labels, processor_spec.qudit_udims) # FUTURE: allow more types of spaces
|
1870
|
-
evotype = _Evotype.cast(evotype)
|
1870
|
+
evotype = _Evotype.cast(evotype, state_space=state_space)
|
1871
1871
|
modelnoise = _OpModelNoise.cast(modelnoise)
|
1872
1872
|
modelnoise.reset_access_counters()
|
1873
1873
|
printer = _VerbosityPrinter.create_printer(verbosity)
|
pygsti/models/modelnoise.py
CHANGED
@@ -799,7 +799,7 @@ class DepolarizationNoise(OpNoise):
|
|
799
799
|
|
800
800
|
# LindbladErrorgen with "depol" or "diagonal" param
|
801
801
|
basis_size = state_space.dim # e.g. 4 for a single qubit
|
802
|
-
basis = _BuiltinBasis('
|
802
|
+
basis = _BuiltinBasis('PP', basis_size)
|
803
803
|
rate_per_pauli = self.depolarization_rate / (basis_size - 1)
|
804
804
|
errdict = {('S', bl): rate_per_pauli for bl in basis.labels[1:]}
|
805
805
|
return _op.LindbladErrorgen.from_elementary_errorgens(
|
@@ -896,7 +896,7 @@ class StochasticNoise(OpNoise):
|
|
896
896
|
raise ValueError("Stochastic noise parameterization must be one of %s" % str(allowed_values))
|
897
897
|
|
898
898
|
basis_size = state_space.dim # e.g. 4 for a single qubit
|
899
|
-
basis = _BuiltinBasis('
|
899
|
+
basis = _BuiltinBasis('PP', basis_size)
|
900
900
|
errdict = {('S', bl): rate for bl, rate in zip(basis.labels[1:], sto_rates)}
|
901
901
|
return _op.LindbladErrorgen.from_elementary_errorgens(
|
902
902
|
errdict, "S", basis, mx_basis='pp',
|
@@ -77,7 +77,7 @@ class LinearInterposer(ModelParamsInterposer):
|
|
77
77
|
# This can and should be improved later - particularly this will be awful when labels (els of wl) are tuples.
|
78
78
|
ret = []
|
79
79
|
for irow in range(self.inv_transform_matrix.shape[0]):
|
80
|
-
lbl = ' + '.join(["%g%s" % (coeff, str(lbl)) for coeff, lbl in zip(self.inv_transform_matrix[irow, :], wl)])
|
80
|
+
lbl = ' + '.join(["%g%s" % (coeff, str(lbl)) for coeff, lbl in zip(self.inv_transform_matrix[irow, :], wl) if abs(coeff)>1e-10])
|
81
81
|
ret.append(lbl)
|
82
82
|
return ret
|
83
83
|
|
pygsti/models/oplessmodel.py
CHANGED
@@ -405,7 +405,7 @@ class ErrorRatesModel(SuccessFailModel):
|
|
405
405
|
return [g_inds[self._alias_dict.get(_Label(lbl.name, lbl.sslbls), _Label(lbl.name, lbl.sslbls))]]
|
406
406
|
else:
|
407
407
|
indices = []
|
408
|
-
assert(not lbl.is_simple
|
408
|
+
assert(not lbl.is_simple), "Cannot find error rate for label: %s" % str(lbl)
|
409
409
|
for component in lbl:
|
410
410
|
indices.extend(indices_for_label(component))
|
411
411
|
return indices
|
pygsti/models/qutrit.py
CHANGED
@@ -14,9 +14,10 @@ import numpy as _np
|
|
14
14
|
from scipy import linalg as _linalg
|
15
15
|
|
16
16
|
from pygsti.baseobjs import Basis as _Basis, statespace as _statespace
|
17
|
-
from pygsti.models.gaugegroup import
|
18
|
-
from pygsti.modelmembers.operations import
|
19
|
-
from pygsti.modelmembers.povms import
|
17
|
+
from pygsti.models.gaugegroup import TPGaugeGroup as _TPGaugeGroup
|
18
|
+
from pygsti.modelmembers.operations import FullTPOp as _FullTPOp
|
19
|
+
from pygsti.modelmembers.povms import TPPOVM as _TPPOVM
|
20
|
+
from pygsti.modelmembers.states import TPState as _TPState
|
20
21
|
from pygsti.models import ExplicitOpModel as _ExplicitOpModel
|
21
22
|
from pygsti.tools import unitary_to_superop, change_basis
|
22
23
|
|
@@ -32,7 +33,7 @@ Y = _np.array([[0, -1j], [1j, 0]])
|
|
32
33
|
|
33
34
|
|
34
35
|
def _x_2qubit(theta):
|
35
|
-
"""
|
36
|
+
r"""
|
36
37
|
Returns X(theta)^\otimes 2 (2-qubit 'XX' unitary)
|
37
38
|
|
38
39
|
Parameters
|
@@ -49,7 +50,7 @@ def _x_2qubit(theta):
|
|
49
50
|
|
50
51
|
|
51
52
|
def _y_2qubit(theta):
|
52
|
-
"""
|
53
|
+
r"""
|
53
54
|
Returns Y(theta)^\otimes 2 (2-qubit 'YY' unitary)
|
54
55
|
|
55
56
|
Parameters
|
@@ -282,14 +283,14 @@ def create_qutrit_model(error_scale, x_angle=_np.pi / 2, y_angle=_np.pi / 2,
|
|
282
283
|
|
283
284
|
state_space = _statespace.ExplicitStateSpace(['QT'], [3])
|
284
285
|
qutritMDL = _ExplicitOpModel(state_space, _Basis.cast(basis, 9), evotype=evotype)
|
285
|
-
qutritMDL.preps['rho0'] = rho0final
|
286
|
-
qutritMDL.povms['Mdefault'] =
|
287
|
-
|
288
|
-
|
289
|
-
qutritMDL.operations['Gi'] =
|
290
|
-
qutritMDL.operations['Gx'] =
|
291
|
-
qutritMDL.operations['Gy'] =
|
292
|
-
qutritMDL.operations['Gm'] =
|
293
|
-
qutritMDL.default_gauge_group =
|
286
|
+
qutritMDL.preps['rho0'] = _TPState(rho0final, evotype=evotype)
|
287
|
+
qutritMDL.povms['Mdefault'] = _TPPOVM([('0bright', E0final),
|
288
|
+
('1bright', E1final),
|
289
|
+
('2bright', E2final)], evotype=evotype)
|
290
|
+
qutritMDL.operations['Gi', 'QT'] = _FullTPOp(arrType(gateISOfinal), basis, evotype, state_space)
|
291
|
+
qutritMDL.operations['Gx', 'QT'] = _FullTPOp(arrType(gateXSOfinal), basis, evotype, state_space)
|
292
|
+
qutritMDL.operations['Gy', 'QT'] = _FullTPOp(arrType(gateYSOfinal), basis, evotype, state_space)
|
293
|
+
qutritMDL.operations['Gm', 'QT'] = _FullTPOp(arrType(gateMSOfinal), basis, evotype, state_space)
|
294
|
+
qutritMDL.default_gauge_group = _TPGaugeGroup(state_space, qutritMDL.basis, evotype)
|
294
295
|
|
295
296
|
return qutritMDL
|
@@ -19,11 +19,13 @@ import numpy as _np
|
|
19
19
|
|
20
20
|
from pygsti import tools as _tools
|
21
21
|
from pygsti.layouts.distlayout import DistributableCOPALayout as _DistributableCOPALayout
|
22
|
+
from pygsti.layouts.matrixlayout import MatrixCOPALayout as _MatrixCOPALayout
|
22
23
|
from pygsti.tools import slicetools as _slct, mpitools as _mpit, sharedmemtools as _smt
|
23
24
|
from pygsti.circuits.circuitlist import CircuitList as _CircuitList
|
24
25
|
from pygsti.baseobjs.resourceallocation import ResourceAllocation as _ResourceAllocation
|
25
26
|
from pygsti.baseobjs.nicelyserializable import NicelySerializable as _NicelySerializable
|
26
27
|
from pygsti.baseobjs.verbosityprinter import VerbosityPrinter as _VerbosityPrinter
|
28
|
+
from pygsti.models.model import OpModel as _OpModel
|
27
29
|
|
28
30
|
|
29
31
|
def _objfn(objfn_cls, model, dataset, circuits=None,
|
@@ -110,9 +112,6 @@ def _objfn(objfn_cls, model, dataset, circuits=None,
|
|
110
112
|
|
111
113
|
return ofn
|
112
114
|
|
113
|
-
#def __len__(self):
|
114
|
-
# return len(self.circuits)
|
115
|
-
|
116
115
|
|
117
116
|
class ObjectiveFunctionBuilder(_NicelySerializable):
|
118
117
|
"""
|
@@ -843,12 +842,10 @@ class ModelDatasetCircuitsStore(object):
|
|
843
842
|
point.
|
844
843
|
"""
|
845
844
|
def __init__(self, model, dataset, circuits=None, resource_alloc=None, array_types=(),
|
846
|
-
precomp_layout=None, verbosity=0):
|
845
|
+
precomp_layout=None, verbosity=0, outcome_count_by_circuit=None):
|
847
846
|
self.dataset = dataset
|
848
847
|
self.model = model
|
849
|
-
#self.opBasis = mdl.basis
|
850
848
|
self.resource_alloc = _ResourceAllocation.cast(resource_alloc)
|
851
|
-
# expand = ??? get from model based on fwdsim type?
|
852
849
|
|
853
850
|
circuit_list = circuits if (circuits is not None) else list(dataset.keys())
|
854
851
|
bulk_circuit_list = circuit_list if isinstance(
|
@@ -872,8 +869,21 @@ class ModelDatasetCircuitsStore(object):
|
|
872
869
|
else:
|
873
870
|
self.global_circuits = self.circuits
|
874
871
|
|
875
|
-
#
|
876
|
-
#
|
872
|
+
#If a matrix layout then we have some precached circuit structures we can
|
873
|
+
#grab to speed up store generation.
|
874
|
+
if isinstance(self.layout, _MatrixCOPALayout):
|
875
|
+
#Grab the split_circuit_cache and down select to those in
|
876
|
+
#self.circuits
|
877
|
+
self.split_circuit_cache = self.layout.split_circuit_cache
|
878
|
+
self.split_circuits = [self.split_circuit_cache[ckt] for ckt in self.circuits]
|
879
|
+
#currently only implemented for matrix, will eventually add map support.
|
880
|
+
else:
|
881
|
+
self.split_circuits = None
|
882
|
+
self.split_circuit_cache = None
|
883
|
+
|
884
|
+
#set the value of the circuit outcome count cache (can be None)
|
885
|
+
self.outcome_count_by_circuit_cache = outcome_count_by_circuit
|
886
|
+
|
877
887
|
self.ds_circuits = self.circuits.apply_aliases()
|
878
888
|
|
879
889
|
# computed by add_count_vectors
|
@@ -888,18 +898,6 @@ class ModelDatasetCircuitsStore(object):
|
|
888
898
|
|
889
899
|
self.time_dependent = False # indicates whether the data should be treated as time-resolved
|
890
900
|
|
891
|
-
#if not self.cache.has_evaltree():
|
892
|
-
# subcalls = self.get_evaltree_subcalls()
|
893
|
-
# evt_resource_alloc = _ResourceAllocation(self.raw_objfn.comm, evt_mlim,
|
894
|
-
# self.raw_objfn.profiler, self.raw_objfn.distribute_method)
|
895
|
-
# self.cache.add_evaltree(self.mdl, self.dataset, bulk_circuit_list, evt_resource_alloc,
|
896
|
-
# subcalls, self.raw_objfn.printer - 1)
|
897
|
-
#self.eval_tree = self.cache.eval_tree
|
898
|
-
#self.lookup = self.cache.lookup
|
899
|
-
#self.outcomes_lookup = self.cache.outcomes_lookup
|
900
|
-
#self.wrt_block_size = self.cache.wrt_block_size
|
901
|
-
#self.wrt_block_size2 = self.cache.wrt_block_size2
|
902
|
-
|
903
901
|
#convenience attributes (could make properties?)
|
904
902
|
if isinstance(self.layout, _DistributableCOPALayout):
|
905
903
|
self.global_nelements = self.layout.global_num_elements
|
@@ -916,8 +914,8 @@ class ModelDatasetCircuitsStore(object):
|
|
916
914
|
assert(self.global_nparams is None or self.global_nparams == self.model.num_params)
|
917
915
|
else:
|
918
916
|
self.global_nelements = self.host_nelements = self.nelements = len(self.layout)
|
919
|
-
self.global_nparams = self.host_nparams = self.nparams = self.model.num_params
|
920
|
-
self.global_nparams2 = self.host_nparams2 = self.nparams2 = self.model.num_params
|
917
|
+
self.global_nparams = self.host_nparams = self.nparams = self.model.num_params if self.model else 0
|
918
|
+
self.global_nparams2 = self.host_nparams2 = self.nparams2 = self.model.num_params if self.model else 0
|
921
919
|
|
922
920
|
@property
|
923
921
|
def opBasis(self):
|
@@ -940,14 +938,36 @@ class ModelDatasetCircuitsStore(object):
|
|
940
938
|
"""
|
941
939
|
if self.firsts is None or force:
|
942
940
|
# FUTURE: add any tracked memory? self.resource_alloc.add_tracked_memory(...)
|
943
|
-
self.firsts = []
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
941
|
+
self.firsts = []
|
942
|
+
self.indicesOfCircuitsWithOmittedData = []
|
943
|
+
|
944
|
+
if self.outcome_count_by_circuit_cache is None:
|
945
|
+
#bulk compute the number of outcomes.
|
946
|
+
if isinstance(self.model, _OpModel) and self.split_circuits is not None:
|
947
|
+
bulk_outcomes_list = self.model.bulk_circuit_outcomes(self.circuits, split_circuits=self.split_circuits)
|
948
|
+
num_outcomes_list = [len(outcome_tup) for outcome_tup in bulk_outcomes_list]
|
949
|
+
else:
|
950
|
+
num_outcomes_list = [self.model.compute_num_outcomes(c) for c in self.circuits]
|
951
|
+
else:
|
952
|
+
num_outcomes_list = []
|
953
|
+
for ckt in self.circuits:
|
954
|
+
num_outcomes = self.outcome_count_by_circuit_cache.get(ckt, None)
|
955
|
+
if num_outcomes is None:
|
956
|
+
num_outcomes = self.model.compute_num_outcomes(ckt)
|
957
|
+
#also add this to the cache, just in case it is later needed.
|
958
|
+
self.outcome_count_by_circuit_cache[ckt] = num_outcomes
|
959
|
+
num_outcomes_list.append(num_outcomes)
|
960
|
+
|
961
|
+
for i in range(len(self.circuits)):
|
962
|
+
indices = self.layout.indices_for_index(i)
|
963
|
+
#The return types of indices_for_index are either ndarrays
|
964
|
+
#or slices.
|
965
|
+
if isinstance(indices, slice):
|
966
|
+
indices = _slct.indices(indices)
|
967
|
+
if 0 < len(indices) < num_outcomes_list[i]:
|
948
968
|
self.firsts.append(indices[0])
|
949
969
|
self.indicesOfCircuitsWithOmittedData.append(i)
|
950
|
-
if
|
970
|
+
if self.firsts:
|
951
971
|
self.firsts = _np.array(self.firsts, 'i')
|
952
972
|
self.indicesOfCircuitsWithOmittedData = _np.array(self.indicesOfCircuitsWithOmittedData, 'i')
|
953
973
|
self.dprobs_omitted_rowsum = _np.empty((len(self.firsts), self.nparams), 'd')
|
@@ -974,13 +994,15 @@ class ModelDatasetCircuitsStore(object):
|
|
974
994
|
|
975
995
|
for (i, circuit) in enumerate(self.ds_circuits):
|
976
996
|
cnts = self.dataset[circuit].counts
|
977
|
-
|
978
|
-
|
997
|
+
idcs_for_idx = self.layout.indices_for_index(i)
|
998
|
+
totals[idcs_for_idx] = sum(cnts.values()) # dataset[opStr].
|
999
|
+
counts[idcs_for_idx] = [cnts.getitem_unsafe(x, 0) for x in self.layout.outcomes_for_index(i)]
|
979
1000
|
|
980
1001
|
if self.circuits.circuit_weights is not None:
|
981
1002
|
for i in range(len(self.ds_circuits)): # multiply N's by weights
|
982
|
-
|
983
|
-
|
1003
|
+
idcs_for_idx = self.layout.indices_for_index(i)
|
1004
|
+
counts[idcs_for_idx] *= self.circuits.circuit_weights[i]
|
1005
|
+
totals[idcs_for_idx] *= self.circuits.circuit_weights[i]
|
984
1006
|
|
985
1007
|
self.counts = counts
|
986
1008
|
self.total_counts = totals
|
@@ -994,7 +1016,7 @@ class EvaluatedModelDatasetCircuitsStore(ModelDatasetCircuitsStore):
|
|
994
1016
|
|
995
1017
|
def __init__(self, mdc_store, verbosity):
|
996
1018
|
super().__init__(mdc_store.model, mdc_store.dataset, mdc_store.global_circuits, mdc_store.resource_alloc,
|
997
|
-
mdc_store.array_types, mdc_store.layout, verbosity)
|
1019
|
+
mdc_store.array_types, mdc_store.layout, verbosity, mdc_store.outcome_count_by_circuit_cache)
|
998
1020
|
|
999
1021
|
# Memory check - see if there's enough memory to hold all the evaluated quantities
|
1000
1022
|
#persistent_mem = self.layout.memory_estimate()
|
@@ -1436,96 +1458,6 @@ class MDCObjectiveFunction(ObjectiveFunction, EvaluatedModelDatasetCircuitsStore
|
|
1436
1458
|
"""
|
1437
1459
|
raise NotImplementedError("Derived classes should implement this!")
|
1438
1460
|
|
1439
|
-
#MOVED - but these versions have updated names
|
1440
|
-
#def _persistent_memory_estimate(self, num_elements=None):
|
1441
|
-
# # Estimate & check persistent memory (from allocs within objective function)
|
1442
|
-
# """
|
1443
|
-
# Compute the amount of memory needed to perform evaluations of this objective function.
|
1444
|
-
#
|
1445
|
-
# This number includes both intermediate and final results, and assumes
|
1446
|
-
# that the types of evauations given by :meth:`_evaltree_subcalls`
|
1447
|
-
# are required.
|
1448
|
-
#
|
1449
|
-
# Parameters
|
1450
|
-
# ----------
|
1451
|
-
# num_elements : int, optional
|
1452
|
-
# The number of elements (circuit outcomes) that will be computed.
|
1453
|
-
#
|
1454
|
-
# Returns
|
1455
|
-
# -------
|
1456
|
-
# int
|
1457
|
-
# """
|
1458
|
-
# if num_elements is None:
|
1459
|
-
# nout = int(round(_np.sqrt(self.mdl.dim))) # estimate of avg number of outcomes per string
|
1460
|
-
# nc = len(self.circuits)
|
1461
|
-
# ne = nc * nout # estimate of the number of elements (e.g. probabilities, # LS terms, etc) to compute
|
1462
|
-
# else:
|
1463
|
-
# ne = num_elements
|
1464
|
-
# np = self.mdl.num_params
|
1465
|
-
#
|
1466
|
-
# # "persistent" memory is that used to store the final results.
|
1467
|
-
# obj_fn_mem = FLOATSIZE * ne
|
1468
|
-
# jac_mem = FLOATSIZE * ne * np
|
1469
|
-
# hess_mem = FLOATSIZE * ne * np**2
|
1470
|
-
# persistent_mem = 4 * obj_fn_mem + jac_mem # 4 different objective-function sized arrays, 1 jacobian array?
|
1471
|
-
# if any([nm == "bulk_fill_hprobs" for nm in self._evaltree_subcalls()]):
|
1472
|
-
# persistent_mem += hess_mem # we need room for the hessian too!
|
1473
|
-
# # TODO: what about "bulk_hprobs_by_block"?
|
1474
|
-
#
|
1475
|
-
# return persistent_mem
|
1476
|
-
#
|
1477
|
-
#def _evaltree_subcalls(self):
|
1478
|
-
# """
|
1479
|
-
# The types of calls that will be made to an evaluation tree.
|
1480
|
-
#
|
1481
|
-
# This information is used for memory estimation purposes.
|
1482
|
-
#
|
1483
|
-
# Returns
|
1484
|
-
# -------
|
1485
|
-
# list
|
1486
|
-
# """
|
1487
|
-
# calls = ["bulk_fill_probs", "bulk_fill_dprobs"]
|
1488
|
-
# if self.enable_hessian: calls.append("bulk_fill_hprobs")
|
1489
|
-
# return calls
|
1490
|
-
#
|
1491
|
-
#def num_data_params(self):
|
1492
|
-
# """
|
1493
|
-
# The number of degrees of freedom in the data used by this objective function.
|
1494
|
-
#
|
1495
|
-
# Returns
|
1496
|
-
# -------
|
1497
|
-
# int
|
1498
|
-
# """
|
1499
|
-
# return self.dataset.degrees_of_freedom(self.ds_circuits,
|
1500
|
-
# aggregate_times=not self.time_dependent)
|
1501
|
-
|
1502
|
-
#def _precompute_omitted_freqs(self):
|
1503
|
-
# """
|
1504
|
-
# Detect omitted frequences (assumed to be 0) so we can compute objective fn correctly
|
1505
|
-
# """
|
1506
|
-
# self.firsts = []; self.indicesOfCircuitsWithOmittedData = []
|
1507
|
-
# for i, c in enumerate(self.circuits):
|
1508
|
-
# lklen = _slct.length(self.lookup[i])
|
1509
|
-
# if 0 < lklen < self.mdl.compute_num_outcomes(c):
|
1510
|
-
# self.firsts.append(_slct.to_array(self.lookup[i])[0])
|
1511
|
-
# self.indicesOfCircuitsWithOmittedData.append(i)
|
1512
|
-
# if len(self.firsts) > 0:
|
1513
|
-
# self.firsts = _np.array(self.firsts, 'i')
|
1514
|
-
# self.indicesOfCircuitsWithOmittedData = _np.array(self.indicesOfCircuitsWithOmittedData, 'i')
|
1515
|
-
# self.dprobs_omitted_rowsum = _np.empty((len(self.firsts), self.nparams), 'd')
|
1516
|
-
# self.raw_objfn.printer.log("SPARSE DATA: %d of %d rows have sparse data" %
|
1517
|
-
# (len(self.firsts), len(self.circuits)))
|
1518
|
-
# else:
|
1519
|
-
# self.firsts = None # no omitted probs
|
1520
|
-
#
|
1521
|
-
#def _compute_count_vectors(self):
|
1522
|
-
# """
|
1523
|
-
# Ensure self.cache contains count and total-count vectors.
|
1524
|
-
# """
|
1525
|
-
# if not self.cache.has_count_vectors():
|
1526
|
-
# self.cache.add_count_vectors(self.dataset, self.ds_circuits, self.circuit_weights)
|
1527
|
-
# return self.cache.counts, self.cache.total_counts
|
1528
|
-
|
1529
1461
|
def _construct_hessian(self, counts, total_counts, prob_clip_interval):
|
1530
1462
|
"""
|
1531
1463
|
Framework for constructing a hessian matrix row by row using a derived
|
@@ -1630,7 +1562,7 @@ class MDCObjectiveFunction(ObjectiveFunction, EvaluatedModelDatasetCircuitsStore
|
|
1630
1562
|
len(layout.atoms), atom.num_elements))
|
1631
1563
|
_sys.stdout.flush(); k += 1
|
1632
1564
|
|
1633
|
-
hessian_blk = self._hessian_from_block(hprobs, dprobs12, probs, atom_counts,
|
1565
|
+
hessian_blk = self._hessian_from_block(hprobs, dprobs12, probs, atom.element_slice, atom_counts,
|
1634
1566
|
atom_total_counts, freqs, param2_resource_alloc)
|
1635
1567
|
#NOTE: _hessian_from_hprobs MAY modify hprobs and dprobs12
|
1636
1568
|
#NOTE2: we don't account for memory within _hessian_from_block - maybe we should?
|
@@ -1645,7 +1577,7 @@ class MDCObjectiveFunction(ObjectiveFunction, EvaluatedModelDatasetCircuitsStore
|
|
1645
1577
|
|
1646
1578
|
return atom_hessian # (my_nparams1, my_nparams2)
|
1647
1579
|
|
1648
|
-
def _hessian_from_block(self, hprobs, dprobs12, probs, counts, total_counts, freqs, resource_alloc):
|
1580
|
+
def _hessian_from_block(self, hprobs, dprobs12, probs, element_slice, counts, total_counts, freqs, resource_alloc):
|
1649
1581
|
raise NotImplementedError("Derived classes should implement this!")
|
1650
1582
|
|
1651
1583
|
def _gather_hessian(self, local_hessian):
|
@@ -5122,7 +5054,7 @@ class TimeIndependentMDCObjectiveFunction(MDCObjectiveFunction):
|
|
5122
5054
|
if paramvec is not None: self.model.from_vector(paramvec)
|
5123
5055
|
return self._gather_hessian(self._construct_hessian(self.counts, self.total_counts, self.prob_clip_interval))
|
5124
5056
|
|
5125
|
-
def _hessian_from_block(self, hprobs, dprobs12, probs, counts, total_counts, freqs, resource_alloc):
|
5057
|
+
def _hessian_from_block(self, hprobs, dprobs12, probs, element_slice, counts, total_counts, freqs, resource_alloc):
|
5126
5058
|
""" Factored-out computation of hessian from raw components """
|
5127
5059
|
|
5128
5060
|
# Note: hprobs, dprobs12, probs are sometimes shared memory, but the caller (e.g. _construct_hessian)
|
@@ -5141,18 +5073,23 @@ class TimeIndependentMDCObjectiveFunction(MDCObjectiveFunction):
|
|
5141
5073
|
hprobs_coeffs = self.raw_objfn.dterms(probs, counts, total_counts, freqs)
|
5142
5074
|
|
5143
5075
|
if self.firsts is not None:
|
5076
|
+
# iel = element index (of self.layout), ic = circuit index
|
5077
|
+
firsts, indicesWithOmitted = zip(*([(iel - element_slice.start, ic) for (iel, ic)
|
5078
|
+
in zip(self.firsts, self.indicesOfCircuitsWithOmittedData)
|
5079
|
+
if element_slice.start <= iel < element_slice.stop]))
|
5080
|
+
|
5144
5081
|
#Allocate these above? Need to know block sizes of dprobs12 & hprobs...
|
5145
|
-
dprobs12_omitted_rowsum = _np.empty((len(
|
5146
|
-
hprobs_omitted_rowsum = _np.empty((len(
|
5082
|
+
dprobs12_omitted_rowsum = _np.empty((len(firsts),) + dprobs12.shape[1:], 'd')
|
5083
|
+
hprobs_omitted_rowsum = _np.empty((len(firsts),) + hprobs.shape[1:], 'd')
|
5147
5084
|
|
5148
5085
|
omitted_probs = 1.0 - _np.array([_np.sum(probs[self.layout.indices_for_index(i)])
|
5149
|
-
for i in
|
5150
|
-
for ii, i in enumerate(
|
5086
|
+
for i in indicesWithOmitted])
|
5087
|
+
for ii, i in enumerate(indicesWithOmitted):
|
5151
5088
|
dprobs12_omitted_rowsum[ii, :, :] = _np.sum(dprobs12[self.layout.indices_for_index(i), :, :], axis=0)
|
5152
5089
|
hprobs_omitted_rowsum[ii, :, :] = _np.sum(hprobs[self.layout.indices_for_index(i), :, :], axis=0)
|
5153
5090
|
|
5154
|
-
dprobs12_omitted_coeffs = -self.raw_objfn.zero_freq_hterms(total_counts[
|
5155
|
-
hprobs_omitted_coeffs = -self.raw_objfn.zero_freq_dterms(total_counts[
|
5091
|
+
dprobs12_omitted_coeffs = -self.raw_objfn.zero_freq_hterms(total_counts[firsts], omitted_probs)
|
5092
|
+
hprobs_omitted_coeffs = -self.raw_objfn.zero_freq_dterms(total_counts[firsts], omitted_probs)
|
5156
5093
|
|
5157
5094
|
# hessian = hprobs_coeffs * hprobs + dprobs12_coeff * dprobs12
|
5158
5095
|
# but re-using dprobs12 and hprobs memory (which is overwritten!)
|
@@ -5160,8 +5097,10 @@ class TimeIndependentMDCObjectiveFunction(MDCObjectiveFunction):
|
|
5160
5097
|
hprobs *= hprobs_coeffs[:, None, None]
|
5161
5098
|
dprobs12 *= dprobs12_coeffs[:, None, None]
|
5162
5099
|
if self.firsts is not None:
|
5163
|
-
|
5164
|
-
|
5100
|
+
firsts = [(iel - element_slice.start) for iel in self.firsts
|
5101
|
+
if element_slice.start <= iel < element_slice.stop]
|
5102
|
+
hprobs[firsts, :, :] += hprobs_omitted_coeffs[:, None, None] * hprobs_omitted_rowsum
|
5103
|
+
dprobs12[firsts, :, :] += dprobs12_omitted_coeffs[:, None, None] * dprobs12_omitted_rowsum
|
5165
5104
|
hessian = dprobs12; hessian += hprobs
|
5166
5105
|
else:
|
5167
5106
|
hessian = dprobs12
|
@@ -6474,10 +6413,6 @@ class LogLWildcardFunction(ObjectiveFunction):
|
|
6474
6413
|
self.logl_objfn.resource_alloc.add_tracked_memory(self.logl_objfn.probs.size)
|
6475
6414
|
self.probs = self.logl_objfn.probs.copy()
|
6476
6415
|
|
6477
|
-
#def _default_evalpt(self):
|
6478
|
-
# """The default point to evaluate functions at """
|
6479
|
-
# return self.wildcard_budget.to_vector()
|
6480
|
-
|
6481
6416
|
#Mimic the underlying LogL objective
|
6482
6417
|
def __getattr__(self, attr):
|
6483
6418
|
return getattr(self.__dict__['logl_objfn'], attr) # use __dict__ so no chance for recursive __getattr__
|
@@ -143,11 +143,6 @@ class WildcardBudget(_NicelySerializable):
|
|
143
143
|
"""
|
144
144
|
raise NotImplementedError("Derived classes must implement `description`")
|
145
145
|
|
146
|
-
#def compute_circuit_wildcard_budget(c, w_vec):
|
147
|
-
# #raise NotImplementedError("TODO!!!")
|
148
|
-
# #for now, assume w_vec is a length-1 vector
|
149
|
-
# return abs(w_vec[0]) * len(c)
|
150
|
-
|
151
146
|
def precompute_for_same_circuits(self, circuits):
|
152
147
|
"""
|
153
148
|
Compute a pre-computed quantity for speeding up circuit calculations.
|
@@ -596,7 +591,7 @@ class PrimitiveOpsWildcardBudgetBase(WildcardBudget):
|
|
596
591
|
elif lbl.name in error_per_op:
|
597
592
|
return pos(error_per_op[lbl.name])
|
598
593
|
else:
|
599
|
-
assert(not lbl.is_simple
|
594
|
+
assert(not lbl.is_simple), "Simple label %s must be a primitive op of this WEB!" % str(lbl)
|
600
595
|
return sum([budget_for_label(component) for component in lbl.components])
|
601
596
|
|
602
597
|
budget = error_per_op.get('SPAM', 0)
|
@@ -656,7 +651,7 @@ class PrimitiveOpsWildcardBudgetBase(WildcardBudget):
|
|
656
651
|
deriv[self.primitive_op_index[lbl.name]] = 1.0
|
657
652
|
return deriv
|
658
653
|
else:
|
659
|
-
assert(not lbl.is_simple
|
654
|
+
assert(not lbl.is_simple), "Simple label %s must be a primitive op of this WEB!" % str(lbl)
|
660
655
|
return sum([budget_deriv_for_label(component) for component in lbl.components])
|
661
656
|
|
662
657
|
circuit_budget_matrix = _np.zeros((len(circuits), self.num_primitive_ops), 'd')
|
pygsti/optimize/__init__.py
CHANGED
@@ -579,6 +579,19 @@ class UndistributedArraysInterface(ArraysInterface):
|
|
579
579
|
"""
|
580
580
|
return _np.diag_indices_from(jtj)
|
581
581
|
|
582
|
+
def jtj_update_regularization(self, jtj, prd, mu):
|
583
|
+
ind = self.jtj_diag_indices(jtj)
|
584
|
+
jtj[ind] = prd + mu
|
585
|
+
return
|
586
|
+
|
587
|
+
def jtj_pre_regularization_data(self, jtj):
|
588
|
+
return jtj[self.jtj_diag_indices(jtj)].copy()
|
589
|
+
|
590
|
+
|
591
|
+
def jtj_max_diagonal_element(self, jtj):
|
592
|
+
diag = jtj[self.jtj_diag_indices(jtj)]
|
593
|
+
return self.max_x(diag)
|
594
|
+
|
582
595
|
|
583
596
|
class DistributedArraysInterface(ArraysInterface):
|
584
597
|
"""
|
@@ -626,6 +639,9 @@ class DistributedArraysInterface(ArraysInterface):
|
|
626
639
|
"""
|
627
640
|
Allocate an array for holding a Jacobian matrix (type `'ep'`).
|
628
641
|
|
642
|
+
Note: this function is only called when the Jacobian needs to be
|
643
|
+
approximated with finite differences.
|
644
|
+
|
629
645
|
Returns
|
630
646
|
-------
|
631
647
|
numpy.ndarray or LocalNumpyArray
|
@@ -1266,3 +1282,15 @@ class DistributedArraysInterface(ArraysInterface):
|
|
1266
1282
|
col_indices = _np.arange(global_param_indices.start, global_param_indices.stop)
|
1267
1283
|
assert(len(row_indices) == len(col_indices)) # checks that global_param_indices is good
|
1268
1284
|
return row_indices, col_indices # ~ _np.diag_indices_from(jtj)
|
1285
|
+
|
1286
|
+
def jtj_update_regularization(self, jtj, prd, mu):
|
1287
|
+
ind = self.jtj_diag_indices(jtj)
|
1288
|
+
jtj[ind] = prd + mu
|
1289
|
+
return
|
1290
|
+
|
1291
|
+
def jtj_pre_regularization_data(self, jtj):
|
1292
|
+
return jtj[self.jtj_diag_indices(jtj)].copy()
|
1293
|
+
|
1294
|
+
def jtj_max_diagonal_element(self, jtj):
|
1295
|
+
diag = jtj[self.jtj_diag_indices(jtj)]
|
1296
|
+
return self.max_x(diag)
|
pygsti/optimize/customcg.py
CHANGED
@@ -244,15 +244,3 @@ def _finite_diff_dfdx_and_bdflag(f, x, delta):
|
|
244
244
|
#completely undefined
|
245
245
|
|
246
246
|
return dfdx, bd
|
247
|
-
|
248
|
-
#def f6(param):
|
249
|
-
# '''Schaffer's F6 function'''
|
250
|
-
# para = param*10
|
251
|
-
# para = param[0:2]
|
252
|
-
# num = (sin(sqrt((para[0] * para[0]) + (para[1] * para[1])))) * \
|
253
|
-
# (sin(sqrt((para[0] * para[0]) + (para[1] * para[1])))) - 0.5
|
254
|
-
# denom = (1.0 + 0.001 * ((para[0] * para[0]) + (para[1] * para[1]))) * \
|
255
|
-
# (1.0 + 0.001 * ((para[0] * para[0]) + (para[1] * para[1])))
|
256
|
-
# f6 = 0.5 - (num/denom)
|
257
|
-
# errorf6 = 1 - f6
|
258
|
-
# return f6, errorf6;
|