Result¶
- class Result(branches: List[Branch], config: Config, shots: int | None)¶
Collects the results of a quantum computation.
The Result class contains the results of a quantum computation. If no measurements were performed, then it contains the final quantum state, accessible through the property
state(). If measurements were performed, then it contains the measurement outcomes (samples), accessible through the propertysamples(). Also, the post-measurement quantum states are stored in thebranches()property, containing a list ofBranchinstances.If the program was executed with a finite number of shots, then the samples can be accessed through the
samples()property. If the program was executed with shots=None, then the exact probability distribution was calculated, and thesamples()property is not available. In this case, the post-measurement states and their probabilities can be accessed through thebranches()property.- Parameters:
branches – The branches containing all the simulation results.
config – The config object.
shots – The number of times the circuit was executed. If it is None, the exact probability distribution was calculated, instead of samples.
- property outcome_map: dict¶
Returns a mapping from measurement outcomes to their frequencies and states.
- Returns:
- A dictionary where the keys are the measurement outcomes, and the
values are dictionaries containing the frequency and the post-measurement state corresponding to the outcome.
- Return type:
- property branches: List[Branch]¶
Returns the list of branches obtained in the calculation.
The
Branchinstances contain the post-measurement quantum states, the corresponding measurement outcomes (samples), and their frequencies, i.e., how many times the outcome appeared divided by the total number of shots. If the program was executed with shots=None, then the frequency corresponds to the exact probability of the outcome.- Returns:
The list of branches containing the post-measurement states, samples, and their frequencies.
- Return type:
List[Branch]
- property samples: List[Tuple[int | float, ...]]¶
The list of measurement outcomes.
A measurement outcome (or sample) is a tuple of integers or floating point numbers, depending on the type of measurements used. A sample is sorted by the ordering of the measurements in the executed program.
Note, that a sample can contain both integers and floats at the same type, e.g., both
ParticleNumberMeasurementandHomodyneMeasurementis used.
- get_counts() dict¶
Returns the samples binned according to their frequency.
- Raises:
NotImplementedError – If the samples contain non-integer data.
- Returns:
The binned samples in a dictionary format, where the keys are the samples and the values are the number of occurrences.
- Return type:
- to_subgraph_nodes() List[List[int]]¶
Convert samples to subgraph modes.
Assuming that a graph’s adjacency matrix is embedded into the circuit, the samples from particle number measurement naturally favor dense subgraphs. The samples could be converted to subgraph modes using this method.
The resulting subgraph node indices correspond to the indices in the adjacency matrix.
Only meaningful for discrete samples generated by
ParticleNumberMeasurement.References