Branch¶
- class Branch(state: State | None = None, outcome: Tuple[int | float, ...] | None = None, frequency: Fraction | None = None)¶
Represents a branching in the quantum computation caused by a measurement.
Describes a branch in the computation tree that arises due to a measurement operation. Upon each measurement, the quantum state can collapse into multiple possible outcomes, each leading to a different branch in the computation. Roughly, a quantum state \(|\psi\rangle\) undergoing a measurement with possible outcomes \(\{m_i\}\) will collapse into one of the post-measurement states \(\{|\psi_i\rangle\}\) with corresponding probabilities \(\{p_i\}\) (i.e., an ensemble of quantum states). Each of these possible outcomes define a separate branch in the computation, and a Branch object is holding momentary information about these branches.
Each Branch instance contains the post-measurement quantum state, the outcomes of the measurements that led to this branch, and the frequency (or weight) of this branch in the overall ensemble. The frequency indicates how often this particular outcome occurred relative to the total number of shots (simulations) performed, which is an approximation of the probability of observing this outcome.
If the simulation was run with shots=None, indicating that the exact probability distribution was calculated instead of sampling, the frequency corresponds to the exact probability of the outcome.
The data in the branch is illustrated as follows. Consider the following setup, where a measurement is performed with two possible outcomes, 0 and 1:
In this case, two branches are created, one for each possible outcome of the measurement. The branches contain the post-measurement quantum states \(|\psi_0\rangle\) and \(|\psi_1\rangle\), the outcomes 0 and 1, and their corresponding probabilities \(p_0\) and \(p_1\), corresponding to each outcome. Since the circuit is executed shots times, instead of the probabilities, the frequencies are stored in the branches, which are calculated as \(f_i = n_i / \text{shots}\), where \(n_i\) is the number of times the outcome \(i\) was observed.
- Variables:
state – The post-measurement quantum state corresponding to the branch. If the branch has no associated quantum state (e.g., all the modes are measured), then this is set to None.
outcome – The accumulated outcome corresponding to the measurement(s) that caused the branching. If no measurements were performed, then this is is set to None.
frequency – The contribution of the state in the final ensemble. If the branch is the result of a measurement with multiple possible outcomes, then this is set to the ratio of the number of times outcome appears in the simulation, divided by shots (which is the total number of samples taken). If the branch is not the result of a measurement (i.e., the branch was not created after a branching event), then this value is simply 1.