Samplers¶
A sampler for measurements of quantum circuits. |
|
A sampler for homodyne measurements. |
|
A sampler for photon-number resolving (PNR) detectors. |

Sampler¶
- class mrmustard.lab.samplers.Sampler(meas_outcomes, povms=None)[source]¶
A sampler for measurements of quantum circuits.
- Parameters:
meas_outcomes (Sequence[Any]) – The measurement outcomes for this sampler.
povms (CircuitComponent | Sequence[CircuitComponent] | None) – The (optional) POVMs of this sampler.
- property povms: CircuitComponent | Sequence[CircuitComponent] | None¶
The POVMs of this sampler.
- property meas_outcomes: Sequence[Any]¶
The measurement outcomes of this sampler.
- abstract probabilities(state, atol=0.0001)[source]¶
Returns the probability distribution of a state w.r.t. measurement outcomes.
- Parameters:
state (State) – The state to generate the probability distribution of. Note: the input state must be normalized.
atol (float) – The absolute tolerance used for validating that the computed probability distribution sums to
1.
- Return type:
Sequence[float]
- sample(state, n_samples=1000, seed=None)[source]¶
Returns an array of samples given a state.
- Parameters:
state (State) – The state to sample.
n_samples (int) – The number of samples to generate.
seed (int | None) – An optional seed for random sampling.
- Returns:
An array of samples such that the shape is
(n_samples, n_modes).- Return type:
ndarray
- sample_prob_dist(state, n_samples=1000, seed=None)[source]¶
Samples a state by computing the probability distribution.
- Parameters:
state (State) – The state to sample.
n_samples (int) – The number of samples to generate.
seed (int | None) – An optional seed for random sampling.
- Returns:
A tuple of the generated samples and the probability of obtaining the sample.
- Return type:
tuple[ndarray, ndarray]
HomodyneSampler¶
- class mrmustard.lab.samplers.HomodyneSampler(phi=0, bounds=(-10, 10), num=1000)[source]¶
Bases:
SamplerA sampler for homodyne measurements.
- Parameters:
phi (float) – The quadrature angle where
0corresponds toxand\pi/2top.bounds (tuple[float, float]) – The range of values to discretize over.
num (int) – The number of points to discretize over.
- probabilities(state, atol=0.0001)[source]¶
Returns the probability distribution of a state w.r.t. measurement outcomes.
- Parameters:
state – The state to generate the probability distribution of. Note: the input state must be normalized.
atol – The absolute tolerance used for validating that the computed probability distribution sums to
1.
- sample(state, n_samples=1000, seed=None)[source]¶
Returns an array of samples given a state.
- Parameters:
state (State) – The state to sample.
n_samples (int) – The number of samples to generate.
seed (int | None) – An optional seed for random sampling.
- Returns:
An array of samples such that the shape is
(n_samples, n_modes).- Return type:
ndarray
PNRSampler¶
- class mrmustard.lab.samplers.PNRSampler(cutoff)[source]¶
Bases:
SamplerA sampler for photon-number resolving (PNR) detectors.
- Parameters:
cutoff (int) – The photon number cutoff.
- probabilities(state, atol=0.0001)[source]¶
Returns the probability distribution of a state w.r.t. measurement outcomes.
- Parameters:
state – The state to generate the probability distribution of. Note: the input state must be normalized.
atol – The absolute tolerance used for validating that the computed probability distribution sums to
1.