Skip to content

Commit 962216e

Browse files
authored
Merge pull request #540 from sandialabs/bugfix-germ-selection-pspec-docs
Bugfix Germ Selection and ProcessorSpec Documentation
2 parents 871a571 + c7cd821 commit 962216e

File tree

6 files changed

+476
-169
lines changed

6 files changed

+476
-169
lines changed

pygsti/algorithms/germselection.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,19 @@ def find_germs(target_model, randomize=True, randomization_strength=1e-2,
406406
raise ValueError("'{}' is not a valid algorithm "
407407
"identifier.".format(algorithm))
408408

409-
return germList
409+
#force the line labels on each circuit to match the state space labels for the target model.
410+
#this is suboptimal for many-qubit models, so will probably want to revisit this. #TODO
411+
finalGermList = []
412+
for ckt in germList:
413+
if ckt._static:
414+
new_ckt = ckt.copy(editable=True)
415+
new_ckt.line_labels = target_model.state_space.state_space_labels
416+
new_ckt.done_editing()
417+
finalGermList.append(new_ckt)
418+
else:
419+
ckt.line_labels = target_model.state_space.state_space_labels
420+
finalGermList.append(ckt)
421+
return finalGermList
410422

411423

412424
def compute_germ_set_score(germs, target_model=None, neighborhood=None,

pygsti/forwardsims/mapforwardsim.py

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def __getstate__(self):
103103
# and this is done by the parent model which will cause _set_evotype to be called.
104104
return state
105105

106-
107106
class MapForwardSimulator(_DistributableForwardSimulator, SimpleMapForwardSimulator):
108107
"""
109108
Computes circuit outcome probabilities using circuit layer maps that act on a state.

pygsti/modelmembers/povms/__init__.py

+131-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# in compliance with the License. You may obtain a copy of the License at
1010
# http://www.apache.org/licenses/LICENSE-2.0 or in the LICENSE file in the root pyGSTi directory.
1111
#***************************************************************************************************
12-
import _collections
1312
import functools as _functools
1413
import itertools as _itertools
1514

@@ -42,10 +41,40 @@
4241

4342
def create_from_pure_vectors(pure_vectors, povm_type, basis='pp', evotype='default', state_space=None,
4443
on_construction_error='warn'):
45-
""" TODO: docstring -- create a POVM from a list/dict of (key, pure-vector) pairs """
44+
"""
45+
Creates a Positive Operator-Valued Measure (POVM) from a list or dictionary of (key, pure-vector) pairs.
46+
47+
Parameters
48+
----------
49+
pure_vectors : list or dict
50+
A list of (key, pure-vector) pairs or a dictionary where keys are labels and values are pure state vectors.
51+
52+
povm_type : str or tuple
53+
The type of POVM to create. This can be a single string or a tuple of strings indicating the preferred types.
54+
Supported types include 'computational', 'static pure', 'full pure', 'static', 'full', 'full TP', and any valid
55+
Lindblad parameterization type.
56+
57+
basis : str, optional
58+
The basis in which the pure vectors are expressed. Default is 'pp'.
59+
60+
evotype : str, optional
61+
The evolution type. Default is 'default'.
62+
63+
state_space : StateSpace, optional
64+
The state space in which the POVM operates. Default is None.
65+
66+
on_construction_error : str, optional
67+
Specifies the behavior when an error occurs during POVM construction. Options are 'raise' to raise the error,
68+
'warn' to print a warning message, or any other value to silently ignore the error. Default is 'warn'.
69+
70+
Returns
71+
-------
72+
POVM
73+
The constructed POVM object.
74+
"""
4675
povm_type_preferences = (povm_type,) if isinstance(povm_type, str) else povm_type
4776
if not isinstance(pure_vectors, dict): # then assume it's a list of (key, value) pairs
48-
pure_vectors = _collections.OrderedDict(pure_vectors)
77+
pure_vectors = dict(pure_vectors)
4978
if state_space is None:
5079
state_space = _statespace.default_space_for_udim(len(next(iter(pure_vectors.values()))))
5180

@@ -94,10 +123,41 @@ def create_from_pure_vectors(pure_vectors, povm_type, basis='pp', evotype='defau
94123

95124
def create_from_dmvecs(superket_vectors, povm_type, basis='pp', evotype='default', state_space=None,
96125
on_construction_error='warn'):
97-
""" TODO: docstring -- create a POVM from a list/dict of (key, pure-vector) pairs """
126+
"""
127+
Creates a Positive Operator-Valued Measure (POVM) from a list or dictionary of (key, superket) pairs.
128+
129+
Parameters
130+
----------
131+
superket_vectors : list or dict
132+
A list of (key, pure-vector) pairs or a dictionary where keys are labels and values are superket vectors.
133+
i.e. vectorized density matrices.
134+
135+
povm_type : str or tuple
136+
The type of POVM to create. This can be a single string or a tuple of strings indicating the preferred types.
137+
Supported types include 'full', 'static', 'full TP', 'computational', 'static pure', 'full pure', and any valid
138+
Lindblad parameterization type.
139+
140+
basis : str or `Basis`, optional
141+
The basis in which the density matrix vectors are expressed. Default is 'pp'.
142+
143+
evotype : str, optional
144+
The evolution type. Default is 'default'.
145+
146+
state_space : StateSpace, optional
147+
The state space in which the POVM operates. Default is None.
148+
149+
on_construction_error : str, optional
150+
Specifies the behavior when an error occurs during POVM construction. Options are 'raise' to raise the error,
151+
'warn' to print a warning message, or any other value to silently ignore the error. Default is 'warn'.
152+
153+
Returns
154+
-------
155+
POVM
156+
The constructed POVM object.
157+
"""
98158
povm_type_preferences = (povm_type,) if isinstance(povm_type, str) else povm_type
99159
if not isinstance(superket_vectors, dict): # then assume it's a list of (key, value) pairs
100-
superket_vectors = _collections.OrderedDict(superket_vectors)
160+
superket_vectors = dict(superket_vectors)
101161

102162
for typ in povm_type_preferences:
103163
try:
@@ -140,12 +200,42 @@ def create_from_dmvecs(superket_vectors, povm_type, basis='pp', evotype='default
140200
print('Failed to construct povm with type "{}" with error: {}'.format(typ, str(err)))
141201
pass # move on to next type
142202

143-
raise ValueError("Could not create a POVM of type(s) %s from the given pure vectors!" % (str(povm_type)))
203+
raise ValueError("Could not create a POVM of type(s) %s from the given density matrix vectors!" % (str(povm_type)))
144204

145205

146206
def create_effect_from_pure_vector(pure_vector, effect_type, basis='pp', evotype='default', state_space=None,
147207
on_construction_error='warn'):
148-
""" TODO: docstring -- create a State from a state vector """
208+
"""
209+
Creates a POVM effect from a pure state vector.
210+
211+
Parameters
212+
----------
213+
pure_vector : array-like
214+
The pure state vector from which to create the POVM effect.
215+
216+
effect_type : str or tuple
217+
The type of effect to create. This can be a single string or a tuple of strings indicating the preferred types.
218+
Supported types include 'computational', 'static pure', 'full pure', 'static', 'full', 'static clifford', and
219+
any valid Lindblad parameterization type.
220+
221+
basis : str or `Basis` optional
222+
The basis in which the pure vector is expressed. Default is 'pp'.
223+
224+
evotype : str, optional
225+
The evolution type. Default is 'default'.
226+
227+
state_space : StateSpace, optional
228+
The state space in which the effect operates. Default is None.
229+
230+
on_construction_error : str, optional
231+
Specifies the behavior when an error occurs during effect construction. Options are 'raise' to raise the error,
232+
'warn' to print a warning message, or any other value to silently ignore the error. Default is 'warn'.
233+
234+
Returns
235+
-------
236+
POVMEffect
237+
The constructed POVM effect object.
238+
"""
149239
effect_type_preferences = (effect_type,) if isinstance(effect_type, str) else effect_type
150240
if state_space is None:
151241
state_space = _statespace.default_space_for_udim(len(pure_vector))
@@ -196,6 +286,38 @@ def create_effect_from_pure_vector(pure_vector, effect_type, basis='pp', evotype
196286

197287
def create_effect_from_dmvec(superket_vector, effect_type, basis='pp', evotype='default', state_space=None,
198288
on_construction_error='warn'):
289+
"""
290+
Creates a POVM effect from a density matrix vector (superket).
291+
292+
Parameters
293+
----------
294+
superket_vector : array-like
295+
The density matrix vector (superket) from which to create the POVM effect.
296+
297+
effect_type : str or tuple
298+
The type of effect to create. This can be a single string or a tuple of strings indicating the preferred types.
299+
Supported types include 'static', 'full', and any valid Lindblad parameterization type. For other types
300+
we first try to convert to a pure state vector and then utilize `create_effect_from_pure_vector`
301+
302+
basis : str or `Basis` optional
303+
The basis in which the superket vector is expressed. Default is 'pp'.
304+
305+
evotype : str, optional
306+
The evolution type. Default is 'default'.
307+
308+
state_space : StateSpace, optional
309+
The state space in which the effect operates. Default is None.
310+
311+
on_construction_error : str, optional
312+
Specifies the behavior when an error occurs during effect construction. Options are 'raise' to raise the error,
313+
'warn' to print a warning message, or any other value to silently ignore the error. Default is 'warn'.
314+
315+
Returns
316+
-------
317+
POVMEffect
318+
The constructed POVM effect object.
319+
"""
320+
199321
effect_type_preferences = (effect_type,) if isinstance(effect_type, str) else effect_type
200322
if state_space is None:
201323
state_space = _statespace.default_space_for_dim(len(superket_vector))
@@ -241,7 +363,8 @@ def create_effect_from_dmvec(superket_vector, effect_type, basis='pp', evotype='
241363

242364

243365
def povm_type_from_op_type(op_type):
244-
"""Decode an op type into an appropriate povm type.
366+
"""
367+
Decode an op type into an appropriate povm type.
245368
246369
Parameters:
247370
-----------

0 commit comments

Comments
 (0)