Skip to content

Commit d6deda1

Browse files
author
Corey Ostrove
committed
Add option to update parameters by name
Can now specify a parameter label in addition to an integer index for model parameter updates.
1 parent 9e6b94f commit d6deda1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pygsti/models/model.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,9 +1209,9 @@ def set_parameter_value(self, index, val, close=False):
12091209
12101210
Parameters
12111211
----------
1212-
index : int or str
1212+
index : int or tuple
12131213
Index of the parameter value in the model's parameter vector to update.
1214-
If a string this instead indexes by the corresponding parameter label.
1214+
If a tuple this instead indexes by the corresponding parameter label.
12151215
12161216
val : float
12171217
Updated parameter value.
@@ -1236,10 +1236,10 @@ def set_parameter_values(self, indices, values, close=False):
12361236
12371237
Parameters
12381238
----------
1239-
indices : list of ints or strs
1239+
indices : list of ints or tuples
12401240
Indices of the parameter values in the model's parameter vector to update.
1241-
If strings this instead indexes by the corresponding parameter label.
1242-
Mixing integer indices and parameter label strings is not supported.
1241+
If tuples this instead indexes by the corresponding parameter label.
1242+
Mixing integer indices and parameter label tuples is not supported.
12431243
Note: In the event that the parameter labels vector for this model contains
12441244
duplicates the update may only apply to the first instance.
12451245
@@ -1255,9 +1255,10 @@ def set_parameter_values(self, indices, values, close=False):
12551255
None
12561256
"""
12571257

1258-
if isinstance(indices[0], str):
1258+
if isinstance(indices[0], tuple):
12591259
#parse the strings into integer indices.
1260-
indices = [self.parameter_labels.index(lbl) for lbl in indices]
1260+
param_labels_list = self.parameter_labels.tolist()
1261+
indices = [param_labels_list.index(lbl) for lbl in indices]
12611262

12621263
for idx, val in zip(indices, values):
12631264
self._paramvec[idx] = val

0 commit comments

Comments
 (0)