def _from_nice_serialization( cls, state): # memo holds already de-serialized objects from pygsti.io.readers import convert_strings_to_circuits as _convert_strings_to_circuits from pygsti.io import stdinput as _stdinput std = _stdinput.StdInputParser() def _decodeval(typ, val): if typ in ("int", "str"): return val if typ == "circuit": return std.parse_circuit( val, create_subcircuits=not _Circuit.default_expand_subcircuits) raise ValueError("Unknown x/y type: %s" % str(typ)) op_label_aliases = _convert_strings_to_circuits( state['op_label_aliases']) circuit_rules = _convert_strings_to_circuits(state['circuit_rules']) \ if ('circuit_rules' in state) else None # for backward compatibility (REMOVE in FUTURE?) plaquettes = {(_decodeval(state['xtype'], x), _decodeval(state['ytype'], y)): CircuitPlaquette.from_nice_serialization(d) for (x, y), d in state['plaquettes']} for p in plaquettes.values(): p._post_from_nice_serialization_init(op_label_aliases, circuit_rules) additional_circuits = [ std.parse_circuit( s, create_subcircuits=not _Circuit.default_expand_subcircuits) for s in state['additional_circuits'] ] circuit_weights = ({ std.parse_circuit( s, create_subcircuits=not _Circuit.default_expand_subcircuits): weight for s, weight in state['circuit_weights'].items() } if (state['circuit_weights'] is not None) else None) xvalues = tuple( [_decodeval(state['xtype'], x) for x in state['xvalues']]) yvalues = tuple( [_decodeval(state['ytype'], y) for y in state['yvalues']]) return cls(plaquettes, xvalues, yvalues, state['xlabel'], state['ylabel'], additional_circuits, op_label_aliases, circuit_rules, circuit_weights, state['additional_circuits_location'], name=state['name'])
def _from_nice_serialization(cls, state): # Note: it's ok that this method assumes the presence of 'elements', since it should only # be called to de-serialize a serialized actual CircuitPlaquette object and not a serialized # derived class object. from pygsti.io import stdinput as _stdinput from pygsti.io.readers import convert_strings_to_circuits as _convert_strings_to_circuits std = _stdinput.StdInputParser() elements = { tuple(ij): std.parse_circuit( s, create_subcircuits=not _Circuit.default_expand_subcircuits) for ij, s in state['elements'] } return cls(elements, state['num_rows'], state['num_cols'], None, None)
def _from_nice_serialization(cls, state): from pygsti.io import stdinput as _stdinput std = _stdinput.StdInputParser() germ = std.parse_circuit( state['germ'], create_subcircuits=not _Circuit.default_expand_subcircuits) fidpairs = { tuple(ij): (std.parse_circuit( prepfid, create_subcircuits=not _Circuit.default_expand_subcircuits), std.parse_circuit( measfid, create_subcircuits=not _Circuit.default_expand_subcircuits)) for ij, prepfid, measfid in state['fiducial_pairs'] } return cls(germ, state['power'], fidpairs, state['num_rows'], state['num_cols'], None, None)
def _from_nice_serialization( cls, state): # memo holds already de-serialized objects from pygsti.io.readers import convert_strings_to_circuits as _convert_strings_to_circuits from pygsti.io import stdinput as _stdinput std = _stdinput.StdInputParser() circuits = [ std.parse_circuit( s, create_subcircuits=_Circuit.default_expand_subcircuits) for s in state['circuits'] ] circuit_weights = _np.array(state['circuit_weights'], 'd') if ( state['circuit_weights'] is not None) else None op_label_aliases = _convert_strings_to_circuits( state['op_label_aliases']) circuit_rules = _convert_strings_to_circuits(state['circuit_rules']) ret = cls(circuits, op_label_aliases, circuit_rules, circuit_weights, state['name']) ret.uuid = _uuid.UUID(state['uuid']) return ret
def _from_nice_serialization(cls, state): from pygsti.io import stdinput as _stdinput std = _stdinput.StdInputParser() circuits = _CircuitList.from_nice_serialization(state['circuits']) unique_circuits = [ std.parse_circuit( s, create_subcircuits=_Circuit.default_expand_subcircuits) for s in state['unique_circuits'] ] to_unique = {k: v for k, v in state['to_unique']} elindex_outcome_tuples = _collections.OrderedDict( state['elindex_outcome_tuples']) return cls(circuits, unique_circuits, to_unique, elindex_outcome_tuples, unique_complete_circuits=None, param_dimensions=state['parameter_dimensions'], resource_alloc=None)
def setUp(self): self.std = stdin.StdInputParser()