EmulatorResult¶
- class guppylang.emulator.EmulatorResult(results: Iterable[QsysShot | Iterable[TaggedResult]] | None = None)[source]¶
A result from running an emulator instance.
Collects data from
result("tag", val)
calls in the guppy program. Includes results for all shots.Includes conversions to traditional distributions over bitstrings if a tagging convention is used, including conversion to a pytket BackendResult.
Under this convention, tags are assumed to be a name of a bit register unless they fit the regex pattern
^([a-z][\w_]*)\[(\d+)\]$
(likemy_Reg[12]
) in which case they are assumed to refer to the nth element of a bit register.For results of the form
result("<register>", value)
,value
can be{0, 1}
, wherein the register is assumed to be length 1, or lists over those values, wherein the list is taken to be the value of the entire register.For results of the form
result("<register>[n]", value)
value
can only be{0,1}
. The register is assumed to be at least n+1 in size and unset elements are assumed to be0
.Subsequent writes to the same register/element in the same shot will overwrite.
To convert to a
BackendResult
all registers must be present in all shots, and register sizes cannot change between shots.- __abstractmethods__ = frozenset({})¶
- collated_counts() Counter[tuple[tuple[str, str], ...]] [source]¶
Calculate counts of bit strings for each tag by collating across shots using QsysResult.tag_collated_shots. Each result entry per shot is seen to be appending to the bitstring for that tag.
If the result value is a list, it is flattened and appended to the bitstring.
- Example:
>>> shots = [QsysShot([("a", 1), ("a", 0)]), QsysShot([("a", [0, 1])])] >>> res = QsysResult(shots) >>> res.collated_counts() Counter({(('a', '10'),): 1, (('a', '01'),): 1})
- Raises:
ValueError: If any value is a float.
- collated_shots() list[dict[str, list[DataValue]]] [source]¶
For each shot generate a dictionary of tags to collated data.
- partial_state_dicts() list[dict[str, PartialVector]] [source]¶
Extract state results from shot results in to dictionaries.
Looks for outputs from state_result(“tag”, qs) calls in the guppy program.
- Returns:
A list of dictionaries, each dictionary containing the tag as the key and the PartialVector as the value. Each dictionary corresponds to a shot. Repeated tags in a shot will overwrite previous values.
- partial_states() list[list[tuple[str, PartialVector]]] [source]¶
Extract state results from shot results.
Looks for outputs from state_result(“tag”, qs) calls in the guppy program.
- Returns:
A list (over shots) of lists. The outer list is over shots, and the inner is over the state results in that shot. Each inner list contains tuples of (string tag, PartialVector).
- register_bitstrings(strict_names: bool = False, strict_lengths: bool = False) dict[str, list[str]] [source]¶
Convert results to a dictionary from register name to list of bitstrings over the shots.
- Args:
- strict_names: Whether to enforce that all shots have the same
registers.
- strict_lengths: Whether to enforce that all register bitstrings have
the same length.