Gates
Gates are stochastic kernels acting on pbits, pdits, and pmodes.
Abstract base classes
AbstractPGateclassAbstractPGate()Base class for all probabilistic gates.
For visualization, there are additional properties:
_control_indices: Indices of control sites for drawing.()empty tuple: no controls, draw as spanning box (default)(0,)tuple of ints: specific site indices are controls"all_but_last": all sites except the last are controls_draw_label: Optional short label for visualization (defaults to class name).
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw a single sample from this factor.
Arguments:
key: PRNG key.inputs: Per-port pytree inputs. Keys must equal theself.input_portskeys.params: Parameter pytree for this factor.info: Runtime auxiliary info.site_info: Static per-site metadata supplied by the surroundingSite.return_aux: IfTrue, return(output, aux).
Returns:
The sampled output (a pytree matching output_spec), or (output, aux) when return_aux=True.
init_paramsmethodinit_params(key: Key[Array, '']) -> ~_ThetaTypeReturn a freshly-initialised parameter pytree (theta).
Arguments:
key: PRNG key.
Returns:
An initial theta pytree for this gate.
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
AbstractDiscreteGateclassAbstractDiscreteGate()A discrete probabilistic gate, a finite-state matrix factor.
get_matrixmethodget_matrix(theta: ~_ThetaType) -> Float[Array, 'dim1 dim2']Get the matrix representation of the gate.
Arguments:
theta: the gate's parameters.
Returns:
The column-stochastic transition matrix P[out, in] of the gate.
AbstractGeneratorGateclassAbstractGeneratorGate()Discrete gate defined by a continuous-time Markov generator $Q$.
Subclasses provide a rate matrix $Q$ via get_generator and a time step via dt. The transition matrix is then
dtmethoddt(theta: ~_ThetaType) -> Float[Array, '']The continuous-time step $\Delta t$, extracted from theta.
get_generatormethodget_generator(theta: ~_ThetaType) -> Float[Array, 'dim1 dim2']Return the continuous-time Markov generator $Q$.
$Q$ must be a rate matrix, which means off-diagonal entries are non-negative and column sums equal to zero.
Arguments:
theta: the gate's parameters.
Returns:
The Markov generator $Q$.
get_matrixmethodget_matrix(theta: ~_ThetaType) -> Float[Array, 'dim1 dim2']Column-stochastic transition matrix $P = \exp(Q \cdot \Delta t)$.
See AbstractDiscreteGate.get_matrix for documentation.
AbstractHybridGateclassAbstractHybridGate()Base class for hybrid gates.
Gates specify which discrete and continuous sites they act on via the sites dict. As a Factor, the gate's sample takes the relevant substate as its inputs (a dict with "discrete" / "continuous" values at the gate's sites) and returns the new continuous substate.
torx currently only supports discrete controlled continuous gates.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the new continuous substate.
Arguments:
key: JAX random key.inputs: Substate dict with"discrete"/"continuous"keysparams: the gate'stheta.info: optional runtime information.site_info: unused.return_aux: ifTrue, return(output, None).
holding the values at the gate's sites.
Returns:
New values for the continuous sites (same shape as inputs["continuous"]), or (output, None) when return_aux.
AbstractContinuousGateclassAbstractContinuousGate()Gate that only touches continuous sites.
Subclasses set sites to specify which continuous sites they act on.
Arguments:
sites: List of continuous site indices.dims: Tuple of continuous dimensions for each site.
init_paramsmethodinit_params(key: Key[Array, '']) -> ~_ThetaTypeReturn a freshly-initialised parameter pytree (theta).
Arguments:
key: PRNG key.
Returns:
An initial theta pytree for this gate.
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
discrete_dimspropertydiscrete_dimsDimensions of discrete control sites, aligned with sites["discrete"].
input_portspropertyinput_portsoutput_specpropertyoutput_specsamplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the new continuous substate.
Arguments:
key: JAX random key.inputs: Substate dict with"discrete"/"continuous"keysparams: the gate'stheta.info: optional runtime information.site_info: unused.return_aux: ifTrue, return(output, None).
holding the values at the gate's sites.
Returns:
New values for the continuous sites (same shape as inputs["continuous"]), or (output, None) when return_aux.
AbstractAffineGaussianGateclassAbstractAffineGaussianGate()Continuous gate with an exact affine-Gaussian channel.
Subclasses expose their local continuous-state transition as
by implementing affine_parameters. The default sample draws from this channel, but exposing $(A, b, \log\text{var})$ also lets simulators reason about the exact Gaussian transition rather than only drawing samples.
Arguments:
sites: List of continuous site indices.dims: Tuple of continuous dimensions for each site.
affine_parametersmethodaffine_parameters(
theta: ~_ThetaType,
) -> tuple[Float[Array, 'local_dim local_dim'], Float[Array, 'local_dim'], Float[Array, 'local_dim']]Return (A, b, log_var) for the local affine-Gaussian channel.
Arguments:
theta: the gate's parameters.
Returns:
A tuple (A, b, log_var) describing x' = A x + b + noise with noise ~ Normal(0, diag(exp(log_var))).
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the affine-Gaussian channel exposed by affine_parameters.
AbstractControlledContinuousGateclassAbstractControlledContinuousGate()Gate where discrete sites control the continuous transformation.
Currently we only support control by a single discrete site (pbit/pdit), so dims only specifies continuous dimensions. Multi-site discrete control would require tracking discrete dims as well.
Arguments:
sites: Tuple of (discrete_site, continuous_sites).dims: Tuple of continuous dimensions.
init_paramsmethodinit_params(key: Key[Array, '']) -> ~_ThetaTypeReturn a freshly-initialised parameter pytree (theta).
Arguments:
key: PRNG key.
Returns:
An initial theta pytree for this gate.
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
discrete_dimspropertydiscrete_dimsDimensions of discrete control sites, aligned with sites["discrete"].
input_portspropertyinput_portsoutput_specpropertyoutput_specsamplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the new continuous substate.
Arguments:
key: JAX random key.inputs: Substate dict with"discrete"/"continuous"keysparams: the gate'stheta.info: optional runtime information.site_info: unused.return_aux: ifTrue, return(output, None).
holding the values at the gate's sites.
Returns:
New values for the continuous sites (same shape as inputs["continuous"]), or (output, None) when return_aux.
AbstractKBranchGateclassAbstractKBranchGate()Gates with K branches selected via softmax over K-1 parameters.
The probability of branch k is softmax([0, theta])[k], where theta has K-1 learnable parameters for K branches. For K = 2, this reduces to the sigmoid parameterization: softmax([0, theta]) = [1 - sigmoid(theta), sigmoid(theta)].
Subclasses must implement:
- num_branches: The number of branches K (>= 2)
- branches: A list of K lookup tables, one per branch
num_branchespropertynum_branchesReturn the number of branches K (must be >= 2).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
branchespropertybranchesGet the K lookup tables for all branches as a stacked array.
Each lookup table (along axis 0) maps computational basis state index to output state values for each site. For example, for a PCNOT gate the operation branch is a CNOT gate. A CNOT gate's action on the computational basis states is 00 -> 00, 01 -> 01, 10 -> 11, and 11 -> 10, so the lookup table is [[0, 0], [0, 1], [1, 1], [1, 0]].
The identity branch (often branches[0]) maps each state to itself. For the PCNOT example, the identity maps 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11, so the lookup table is [[0, 0], [0, 1], [1, 0], [1, 1]].
For binary gates, basis_size = 2**num_sites. For pdit gates, basis_size = prod(dims).
Returns:
A stacked array of shape (K, basis_size, num_sites) containing all branch lookup tables.
AbstractSingleBinaryPGateclassAbstractSingleBinaryPGate()Abstract base class for single-site binary gates (dimension 2).
Arguments:
sites: The index of the site that this gate acts on.
get_matrixmethodget_matrix(theta: ~_ThetaType) -> Float[Array, 'dim1 dim2']Get the matrix representation of the gate.
Arguments:
theta: the gate's parameters.
Returns:
The column-stochastic transition matrix P[out, in] of the gate.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
num_branchespropertynum_branchesReturn the number of branches K (must be >= 2).
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
branchespropertybranchesGet the K lookup tables for all branches as a stacked array.
Each lookup table (along axis 0) maps computational basis state index to output state values for each site. For example, for a PCNOT gate the operation branch is a CNOT gate. A CNOT gate's action on the computational basis states is 00 -> 00, 01 -> 01, 10 -> 11, and 11 -> 10, so the lookup table is [[0, 0], [0, 1], [1, 1], [1, 0]].
The identity branch (often branches[0]) maps each state to itself. For the PCNOT example, the identity maps 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11, so the lookup table is [[0, 0], [0, 1], [1, 0], [1, 1]].
For binary gates, basis_size = 2**num_sites. For pdit gates, basis_size = prod(dims).
Returns:
A stacked array of shape (K, basis_size, num_sites) containing all branch lookup tables.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsAbstractMultiBinaryPGateclassAbstractMultiBinaryPGate()Abstract base class for multi-site binary gates (dims = 2).
Arguments:
sites: A list of site indices that this gate acts on.
get_matrixmethodget_matrix(theta: ~_ThetaType) -> Float[Array, 'dim1 dim2']Get the matrix representation of the gate.
Arguments:
theta: the gate's parameters.
Returns:
The column-stochastic transition matrix P[out, in] of the gate.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
num_branchespropertynum_branchesReturn the number of branches K (must be >= 2).
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
branchespropertybranchesGet the K lookup tables for all branches as a stacked array.
Each lookup table (along axis 0) maps computational basis state index to output state values for each site. For example, for a PCNOT gate the operation branch is a CNOT gate. A CNOT gate's action on the computational basis states is 00 -> 00, 01 -> 01, 10 -> 11, and 11 -> 10, so the lookup table is [[0, 0], [0, 1], [1, 1], [1, 0]].
The identity branch (often branches[0]) maps each state to itself. For the PCNOT example, the identity maps 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11, so the lookup table is [[0, 0], [0, 1], [1, 0], [1, 1]].
For binary gates, basis_size = 2**num_sites. For pdit gates, basis_size = prod(dims).
Returns:
A stacked array of shape (K, basis_size, num_sites) containing all branch lookup tables.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsAbstractSinglePditGateclassAbstractSinglePditGate()Abstract base class for single-site pdit gates (arbitrary dimension k).
Arguments:
sites: The index of the site that this gate acts on.dims: Tuple containing the dimension of the pdit.
get_matrixmethodget_matrix(theta: ~_ThetaType) -> Float[Array, 'dim1 dim2']Get the matrix representation of the gate.
Arguments:
theta: the gate's parameters.
Returns:
The column-stochastic transition matrix P[out, in] of the gate.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
num_branchespropertynum_branchesReturn the number of branches K (must be >= 2).
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
branchespropertybranchesGet the K lookup tables for all branches as a stacked array.
Each lookup table (along axis 0) maps computational basis state index to output state values for each site. For example, for a PCNOT gate the operation branch is a CNOT gate. A CNOT gate's action on the computational basis states is 00 -> 00, 01 -> 01, 10 -> 11, and 11 -> 10, so the lookup table is [[0, 0], [0, 1], [1, 1], [1, 0]].
The identity branch (often branches[0]) maps each state to itself. For the PCNOT example, the identity maps 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11, so the lookup table is [[0, 0], [0, 1], [1, 0], [1, 1]].
For binary gates, basis_size = 2**num_sites. For pdit gates, basis_size = prod(dims).
Returns:
A stacked array of shape (K, basis_size, num_sites) containing all branch lookup tables.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
AbstractMultiPditGateclassAbstractMultiPditGate()Abstract base class for multi-site pdit gates (same dimension k per site).
Arguments:
sites: A list of site indices that this gate acts on.dims: Tuple containing the dimensions of each pdit.
get_matrixmethodget_matrix(theta: ~_ThetaType) -> Float[Array, 'dim1 dim2']Get the matrix representation of the gate.
Arguments:
theta: the gate's parameters.
Returns:
The column-stochastic transition matrix P[out, in] of the gate.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
num_branchespropertynum_branchesReturn the number of branches K (must be >= 2).
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
branchespropertybranchesGet the K lookup tables for all branches as a stacked array.
Each lookup table (along axis 0) maps computational basis state index to output state values for each site. For example, for a PCNOT gate the operation branch is a CNOT gate. A CNOT gate's action on the computational basis states is 00 -> 00, 01 -> 01, 10 -> 11, and 11 -> 10, so the lookup table is [[0, 0], [0, 1], [1, 1], [1, 0]].
The identity branch (often branches[0]) maps each state to itself. For the PCNOT example, the identity maps 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11, so the lookup table is [[0, 0], [0, 1], [1, 0], [1, 1]].
For binary gates, basis_size = 2**num_sites. For pdit gates, basis_size = prod(dims).
Returns:
A stacked array of shape (K, basis_size, num_sites) containing all branch lookup tables.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
Concrete classes
HybridSitesclassHybridSites(discrete: list[int], continuous: list[int])Site mapping for hybrid gates.
Keys:
discrete: discrete site indices read as controls.continuous: continuous site indices updated by the gate.
Continuous-only gates also accept a list of continuous site indices; hybrid gate constructors accept a (discrete, continuous) pair.
discreteattributediscrete: list[int]continuousattributecontinuous: list[int]PNOTclassPNOT(sites: int)A probabilistic NOT gate.
This gate flips the value of a given pbit with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter, and otherwise does nothing.
The transition matrix is:
sitesattributesites: intnum_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: 0 -> 0 and 1 -> 1. branches[1] is bit flip: 0 -> 1 and 1 -> 0.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '2 2']See AbstractDiscreteGate.get_matrix for documentation.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsPCNOTclassPCNOT(sites: list[int])A probabilistic CNOT gate.
This gate performs a controlled-NOT operation on two given pbits with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter, and otherwise does nothing. A controlled-NOT operation flips the value of the second pbit if the first pbit has the value 1, and does nothing if the first pbit has the value 0.
Transition matrix:
sitesattributesites: list[int]num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11. branches[1] is CNOT: 00->00, 01->01, 10->11, 11->10.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '4 4']See AbstractDiscreteGate.get_matrix for documentation.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsPSWAPclassPSWAP(sites: list[int])A probabilistic SWAP gate.
This gate swaps the values of two given pbits with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter, and otherwise does nothing.
Transition matrix:
sitesattributesites: list[int]input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11. branches[1] is swap: 00->00, 01->10, 10->01, 11->11.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '4 4']See AbstractDiscreteGate.get_matrix for documentation.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsPJUMPclassPJUMP(sites: list[int])A probabilistic JUMP gate.
This gate performs a "jump" operation on two given pbits with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter, and otherwise does nothing. A jump operation moves probability from $|10)$ to $|01)$ if the first pbit has the value 1.
Transition matrix:
sitesattributesites: list[int]input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11. branches[1] is JUMP: 00->00, 01->01, 10->01, 11->11.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '4 4']See AbstractDiscreteGate.get_matrix for documentation.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsPMultiCNOTclassPMultiCNOT(sites: list[int])A probabilistic multi-controlled-NOT gate.
This gate performs a multi-controlled-NOT operation on any number of given pbits with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter, and otherwise does nothing. A multi-controlled-NOT operation flips the value of the last pbit if all the other pbits have the value 1, and does nothing otherwise.
The transition matrix is identity except for the last two rows/columns which swap with probability $p$.
sitesattributesites: list[int]input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity. branches[1] is multi-controlled-NOT: flips last bit when all others are 1.
output_specpropertyoutput_specget_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, 'd d']See AbstractDiscreteGate.get_matrix for documentation.
n_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsPDEMUXclassPDEMUX(sites: list[int])A probabilistic demultiplexor.
This gate has one input pbit and one "work" pbit. It either (i) copies the input to the work pbit and sets the input to 0, or (ii) does nothing to the input and sets the work pbit to 0. The probability of the former occurring is $p = \sigma(\theta)$ where $\theta$ is the gate parameter.
Transition matrix:
sitesattributesites: list[int]input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']num_branchespropertynum_branchesbranchespropertybranchesbranches[0] resets second pbit: 00 -> 00, 01 -> 00, 10 -> 10, 11 -> 10. branches[1] copies and resets: 00->00, 01->00, 10->01, 11->01.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '4 4']See AbstractDiscreteGate.get_matrix for documentation.
get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsPORclassPOR(sites: list[int])A probabilistic OR gate.
This gate performs a modified OR operation on two given pbits with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter, and otherwise does nothing. A modified OR operation sets the first pbit to the OR of the two input pbits, and sets the second pbit to 0.
Transition matrix:
sitesattributesites: list[int]input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: 00 -> 00, 01 -> 01, 10 -> 10, 11 -> 11. branches[1] is OR: 00->00, 01->10, 10->10, 11->10.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '4 4']See AbstractDiscreteGate.get_matrix for documentation.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsPResetclassPReset(sites: int)A probabilistic reset gate.
This gate sets the given pbit to 0 with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter, and otherwise does nothing.
The transition matrix is:
sitesattributesites: intinput_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: 0 -> 0 and 1 -> 1. branches[1] resets to 0: 0 -> 0 and 1 -> 0.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '2 2']See AbstractDiscreteGate.get_matrix for documentation.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsPCopyclassPCopy(sites: list[int])A probabilistic copy gate.
This gate copies the first pbit to the second pbit with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter, and otherwise does nothing.
Transition matrix:
sitesattributesites: list[int]input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: 00->00, 01->01, 10->10, 11->11. branches[1] copies first to second: 00->00, 01->00, 10->11, 11->11.
dimspropertydimsget_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '4 4']See AbstractDiscreteGate.get_matrix for documentation.
PCSWAPclassPCSWAP(sites: list[int])A probabilistic controlled-SWAP gate (Fredkin gate).
This gate swaps the values of two target pbits only when the control pbit is in state $|1)$, with probability $p = \sigma(\theta)$ where $\theta$ is the gate parameter. If the control is $|0)$ or the gate is not applied (with probability $1-p$), nothing happens.
The first site is the control, the second and third sites are the targets to be swapped.
Transition matrix:
sitesattributesites: list[int]input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
dimspropertydimsnum_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity. branches[1] is controlled-SWAP: swap targets if control=1.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, '8 8']See AbstractDiscreteGate.get_matrix for documentation.
GaussianNoiseGateclassGaussianNoiseGate(sites: HybridSites | list[int], dims: tuple[int, ...])Additive Gaussian noise gate.
This gate adds independent Gaussian noise to the continuous state:
The variance is parameterized as $\exp(\theta)$ to ensure positivity.
sitesattributesites: HybridSitesdimsattributedims: tuple[int, ...]init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'd']Initial theta (log-variance), zeros over the continuous dims.
affine_parametersmethodaffine_parameters(
theta: Float[Array, 'd'],
) -> tuple[Float[Array, 'local_dim local_dim'], Float[Array, 'local_dim'], Float[Array, 'local_dim']]Return the additive Gaussian channel as (A, b, log_var).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
discrete_dimspropertydiscrete_dimsDimensions of discrete control sites, aligned with sites["discrete"].
input_portspropertyinput_portsoutput_specpropertyoutput_specsamplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the affine-Gaussian channel exposed by affine_parameters.
AffineGaussianGateclassAffineGaussianGate(sites: HybridSites | list[int], dims: tuple[int, ...])Affine transformation with Gaussian noise.
This gate applies an affine transformation followed by Gaussian noise: $x' = Ax + b + \mathcal{N}(0, \sigma^2)$ where $\sigma^2 = \exp$(log_var)
The theta dict contains:
A: Transformation matrix of shape (d, d)b: Bias vector of shape (d,)log_var: Log-variance of shape (d,)
sitesattributesites: HybridSitesdimsattributedims: tuple[int, ...]init_paramsmethodinit_params(key: Key[Array, '']) -> dict[str, Array]Initial identity affine: A = I, b = 0, log_var = 0.
affine_parametersmethodaffine_parameters(
theta: dict[str, Array],
) -> tuple[Float[Array, 'local_dim local_dim'], Float[Array, 'local_dim'], Float[Array, 'local_dim']]Return (A, b, log_var) for this affine-Gaussian channel.
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
discrete_dimspropertydiscrete_dimsDimensions of discrete control sites, aligned with sites["discrete"].
input_portspropertyinput_portsoutput_specpropertyoutput_specsamplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the affine-Gaussian channel exposed by affine_parameters.
DisplaceclassDisplace(sites: HybridSites | list[int], dims: tuple[int, ...])Displace continuous sites by theta.
This deterministic affine-Gaussian channel applies
sitesattributesites: HybridSitesdimsattributedims: tuple[int, ...]sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'd']Initial displacement theta of zeros over the continuous dims.
affine_parametersmethodaffine_parameters(
theta: Float[Array, 'd'],
) -> tuple[Float[Array, 'local_dim local_dim'], Float[Array, 'local_dim'], Float[Array, 'local_dim']]Return the displacement channel as (A, b, log_var).
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
discrete_dimspropertydiscrete_dimsDimensions of discrete control sites, aligned with sites["discrete"].
input_portspropertyinput_portsoutput_specpropertyoutput_specsamplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the affine-Gaussian channel exposed by affine_parameters.
ScaleclassScale(sites: HybridSites | list[int], dims: tuple[int, ...])Scale continuous sites by $\exp(\theta)$.
This deterministic affine-Gaussian channel applies
sitesattributesites: HybridSitesdimsattributedims: tuple[int, ...]sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'd']Initial log-scale theta of zeros (i.e. unit scale).
affine_parametersmethodaffine_parameters(
theta: Float[Array, 'd'],
) -> tuple[Float[Array, 'local_dim local_dim'], Float[Array, 'local_dim'], Float[Array, 'local_dim']]Return the scaling channel as (A, b, log_var).
discrete_dimspropertydiscrete_dimsDimensions of discrete control sites, aligned with sites["discrete"].
input_portspropertyinput_portsoutput_specpropertyoutput_specsamplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the affine-Gaussian channel exposed by affine_parameters.
MixclassMix(sites: HybridSites | list[int], dims: tuple[int, ...])Rotate exactly two scalar continuous sites by angle theta.
This deterministic affine-Gaussian channel applies
Expects two scalar continuous sites (dims = (1, 1)).
sitesattributesites: HybridSitesdimsattributedims: tuple[int, ...]sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
discrete_dimspropertydiscrete_dimsDimensions of discrete control sites, aligned with sites["discrete"].
input_portspropertyinput_portsoutput_specpropertyoutput_specinit_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, '']Initial rotation angle theta of zero.
affine_parametersmethodaffine_parameters(
theta: Float[Array, ''],
) -> tuple[Float[Array, 'local_dim local_dim'], Float[Array, 'local_dim'], Float[Array, 'local_dim']]Return the rotation channel as (A, b, log_var).
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the affine-Gaussian channel exposed by affine_parameters.
DiffuseclassDiffuse(sites: HybridSites | list[int], dims: tuple[int, ...])Apply Brownian diffusion with log-variance theta.
This additive affine-Gaussian channel applies
For a diffusion coefficient $D$ over time $t$, set theta to $\log(2 D t)$. Functionally this matches GaussianNoiseGate; it is provided as a named Brownian-diffusion channel.
sitesattributesites: HybridSitesdimsattributedims: tuple[int, ...]sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
discrete_dimspropertydiscrete_dimsDimensions of discrete control sites, aligned with sites["discrete"].
input_portspropertyinput_portsoutput_specpropertyoutput_specinit_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'd']Initial log-variance theta of zeros over the continuous dims.
affine_parametersmethodaffine_parameters(
theta: Float[Array, 'd'],
) -> tuple[Float[Array, 'local_dim local_dim'], Float[Array, 'local_dim'], Float[Array, 'local_dim']]Return the Brownian diffusion channel as (A, b, log_var).
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the affine-Gaussian channel exposed by affine_parameters.
MixtureGaussianGateclassMixtureGaussianGate(
sites: HybridSites | tuple[int | list[int], int | list[int]],
dims: tuple[int, ...],
num_components: int,
)Mixture Gaussian gate controlled by a discrete site.
This gate samples from one of K Gaussian components, where the component is selected by the discrete control site. Given discrete state $k$: $x' = x + \mu_k + \mathcal{N}(0, \sigma_k^2)$ where $\sigma_k^2 = \exp$(log_vars[k])
The discrete site should take values in $\{0, 1, ..., K-1\}$ where K is the number of mixture components.
dims only specifies continuous dimensions since we only support control by a single discrete site for now.
The theta dict contains:
means: Component means of shape (K, d)log_vars: Component log-variances of shape (K, d)
sitesattributesites: HybridSitesdimsattributedims: tuple[int, ...]num_componentsattributenum_components: intsample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
input_portspropertyinput_portsoutput_specpropertyoutput_specdiscrete_dimspropertydiscrete_dimsinit_paramsmethodinit_params(key: Key[Array, '']) -> dict[str, Array]Initial means and log_vars of zeros, shape (K, d).
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: dict[str, Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the new continuous substate.
Arguments:
key: JAX random key.inputs: Substate dict with"discrete"/"continuous"keysparams: the gate'stheta.info: optional runtime information.site_info: unused.return_aux: ifTrue, return(output, None).
holding the values at the gate's sites.
Returns:
New values for the continuous sites (same shape as inputs["continuous"]), or (output, None) when return_aux.
JumpDiffusionGateclassJumpDiffusionGate(
sites: HybridSites | tuple[int | list[int], int | list[int]],
dims: tuple[int, ...],
)Jump-diffusion gate controlled by a discrete firing site.
This gate applies continuous diffusion, and conditionally applies a jump based on the discrete control site. Given discrete state $j \in \{0, 1\}$:
where $\sigma_d^2 = \exp$(diff_log_var) and $\sigma_j^2 = \exp$(jump_log_var).
When $j = 0$, only diffusion is applied. When $j = 1$, both diffusion and the jump are applied.
dims only specifies continuous dimensions since we only support control by a single discrete site for now.
The theta dict contains:
diff_log_var: Diffusion log-variance of shape (d,)jump_mean: Jump mean of shape (d,)jump_log_var: Jump log-variance of shape (d,)
sitesattributesites: HybridSitesdimsattributedims: tuple[int, ...]sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
input_portspropertyinput_portsoutput_specpropertyoutput_specdiscrete_dimspropertydiscrete_dimsinit_paramsmethodinit_params(key: Key[Array, '']) -> dict[str, Array]Initial diff_log_var/jump_mean/jump_log_var of zeros.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: dict[str, Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Sample the new continuous substate.
Arguments:
key: JAX random key.inputs: Substate dict with"discrete"/"continuous"keysparams: the gate'stheta.info: optional runtime information.site_info: unused.return_aux: ifTrue, return(output, None).
holding the values at the gate's sites.
Returns:
New values for the continuous sites (same shape as inputs["continuous"]), or (output, None) when return_aux.
PISINGclassPISING(sites: list[int])A probabilistic Ising interaction gate.
Unlike the Boolean gates (PNOT, PCNOT, PSWAP, ...) which interpolate between identity and a logic operation, PISING is an energy-based gate: it drives two pbits toward the thermal equilibrium of a pairwise Ising interaction. Applying it repeatedly thermalizes the joint distribution toward the Boltzmann distribution $\pi_i \propto e^{-\beta E_i}$.
PISING is a generator-defined dense-matrix gate. Use it with [StateVectorSimulator][torx.psc.StateVectorSimulator]; it is not compatible with [BranchingSimulator][torx.psc.BranchingSimulator], which currently requires branch lookup-table gates.
The Ising energy for two pbits $\sigma_1, \sigma_2 \in \{0, 1\}$ is:
where $s_i = 2\sigma_i - 1 \in \{-1, +1\}$.
The transition matrix $P = \exp(Q \cdot \Delta t)$ is the matrix exponential of a Markov generator $Q$ whose off-diagonal entries are Glauber single-spin-flip rates:
Only single-spin-flip transitions are nonzero.
Parameters:
theta[0], $J$: coupling strengththeta[1], $h_1$: external field on first pbittheta[2], $h_2$: external field on second pbittheta[3], $\beta$: inverse temperaturetheta[4], $\Delta t$: continuous-time step
($J > 0$ ferromagnetic, $J < 0$ antiferromagnetic)
($\beta \to 0$: uniform, $\beta \to \infty$: ground state)
($0$: identity, larger: closer to equilibrium)
sitesattributesites: list[int]dimspropertydimsinit_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, '5']Initial theta = [J, h1, h2, beta, dt] (zeros).
JmethodJ(theta: Float[Array, '5']) -> Float[Array, '']h1methodh1(theta: Float[Array, '5']) -> Float[Array, '']h2methodh2(theta: Float[Array, '5']) -> Float[Array, '']betamethodbeta(theta: Float[Array, '5']) -> Float[Array, '']dtmethoddt(theta: Float[Array, '5']) -> Float[Array, '']The continuous-time step $\Delta t$, extracted from theta.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_generatormethodget_generator(theta: Float[Array, '5']) -> Float[Array, '4 4']Build the 4x4 Glauber-dynamics Markov generator $Q$.
$Q$ is a rate matrix with zero column sums and non-negative off-diagonal entries. Only single-spin-flip transitions are nonzero: $|00) \leftrightarrow |01)$, $|00) \leftrightarrow |10)$, $|01) \leftrightarrow |11)$, $|10) \leftrightarrow |11)$.
The generator is independent of $\Delta t$.
get_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
get_matrixmethodget_matrix(theta: ~_ThetaType) -> Float[Array, 'dim1 dim2']Column-stochastic transition matrix $P = \exp(Q \cdot \Delta t)$.
See AbstractDiscreteGate.get_matrix for documentation.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
PditShiftclassPditShift(sites: int, dims: Any)A probabilistic cyclic shift gate for a single k-dimensional pdit.
This gate shifts the state cyclically: i -> (i+1) mod k with probability $p = \sigma(\theta)$, and does nothing with probability $1-p$.
The transition matrix for dimension k is: $(1 - p) I + p C$ where $C$ is the cyclic permutation matrix.
sitesattributesites: intdimsattributedims: tuple[int, ...]num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: i -> i. branches[1] is cyclic shift: i -> (i+1) mod k.
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, 'd d']See AbstractDiscreteGate.get_matrix for documentation.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
PditSWAPclassPditSWAP(sites: list[int], dims: Any)A probabilistic SWAP gate for two k-dimensional pdits.
This gate swaps the values of two pdits with probability $p = \sigma(\theta)$, and does nothing with probability $1-p$. Both pdits must have the same dimension.
For dimension k, the state space is $k^2$ and the SWAP permutes basis states $|i,j) \to |j,i)$.
sitesattributesites: list[int]dimsattributedims: tuple[int, ...]num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: |i,j) -> |i,j). branches[1] is SWAP: |i,j) -> |j,i).
get_matrixmethodget_matrix(theta: Float[Array, '1']) -> Float[Array, 'd2 d2']See AbstractDiscreteGate.get_matrix for documentation.
input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.
PditCycleclassPditCycle(sites: int, dims: Any)A probabilistic 3-branch cyclic gate for a single d-dimensional pdit.
This gate implements a random walk on a ring: with some probability stay in place, shift forward, or shift backward. Useful for modeling diffusion or random walks on discrete rings.
This gate has 3 branches:
- Branch 0: Identity (i -> i)
- Branch 1: Forward cycle (i -> (i+1) mod d)
- Branch 2: Backward cycle (i -> (i-1) mod d)
The probabilities are determined by softmax([0, theta[0], theta[1]]).
The transition matrix is:
where $C_{forward}$ is the forward cyclic permutation and $C_{backward}$ is the backward cyclic permutation.
sitesattributesites: intdimsattributedims: tuple[int, ...]input_statespropertyinput_statesoutput_statespropertyoutput_statesinput_portspropertyinput_portsget_log_probability_matrixmethodget_log_probability_matrix(
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
) -> Float[Array, 'n_input_states n_output_states']Row-stochastic log P[in, out] = log(get_matrix(params).T).
sample_multiplemethodsample_multiple(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_samples: int = 1,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw n_samples samples by vmap-ing sample.
Arguments:
key: PRNG key, splitn_samplesways.inputs: Per-port pytree inputs, as insample.params: Parameter pytree for this factor.info: Runtime auxiliary info, as insample.site_info: Static per-site metadata, as insample.n_samples: Number of independent samples to draw.return_aux: Whether to return theauxpytree, as insample.
Returns:
The stacked outputs, or (outputs, auxes) when return_aux=True, each with a leading axis of size n_samples.
samplemethodsample(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> PyTree[Array] | tuple[PyTree[Array], PyTree[Array]]Draw the gate's output configuration from its transition matrix.
num_branchespropertynum_branchesbranchespropertybranchesbranches[0] is identity: i -> i. branches[1] is forward cycle: i -> (i+1) mod d. branches[2] is backward cycle: i -> (i-1) mod d.
get_matrixmethodget_matrix(theta: Float[Array, '2']) -> Float[Array, 'd d']See AbstractDiscreteGate.get_matrix for documentation.
sample_with_referencesmethodsample_with_references(
key: Key[Array, ''],
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
n_references: int = 1,
) -> tuple[PyTree[Array], PyTree[Array]]Generic reference-sampling default.
Draws n_references + 1 samples via sample_multiple and returns the first as the main sample, with all of their auxes stacked.
log_probabilitymethodlog_probability(
inputs: Mapping[str, PyTree[Array]],
outputs: PyTree[Array],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, ''] | tuple[Float[Array, ''], PyTree[Array]]Index get_log_output_distribution at the queried outputs.
output_specpropertyoutput_specn_input_statespropertyn_input_statesn_output_statespropertyn_output_statesget_nth_input_statemethodget_nth_input_state(n: int | Int[Array, '']) -> Mapping[str, PyTree[Array]]get_nth_output_statemethodget_nth_output_state(n: int | Int[Array, '']) -> PyTree[Array]input_state_to_indexmethodinput_state_to_index(inputs: Mapping[str, PyTree[Array]]) -> Float[Array, '']output_state_to_indexmethodoutput_state_to_index(outputs: PyTree[Array]) -> Float[Array, '']get_log_output_distributionmethodget_log_output_distribution(
inputs: Mapping[str, PyTree[Array]],
params: PyTree[Array],
info: PyTree = None,
site_info: Any = None,
return_aux: bool = False,
) -> Float[Array, 'n_output_states'] | tuple[Float[Array, 'n_output_states'], PyTree[Array]]The matrix row selected by the input's canonical index.
init_paramsmethodinit_params(key: Key[Array, '']) -> Float[Array, 'num_branch_params']Initial theta of shape (num_branches - 1,) (zeros).
probsmethodprobs(theta: Float[Array, 'num_branch_params']) -> Float[Array, 'K']Branch probabilities for parameters theta.
probmethodprob(theta: Float[Array, 'num_branch_params']) -> Float[Array, '']Probability of applying the operation (branches[1]); K=2 only.