get_statetensor_to_sampled_expectation_func
- qujax.get_statetensor_to_sampled_expectation_func(hermitian_seq_seq, qubits_seq_seq, coefficients)
Converts strings (or arrays) representing Hermitian matrices, qubit indices and coefficients into a function that converts a statetensor into a sampled expected value.
On a quantum device, measurements are always taken in the computational basis, as such sampled expectation values should be taken with respect to an observable that commutes with the Pauli Z - a warning will be raised if it does not.
qujax applies an importance sampling heuristic for sampled expectation values that only reflects the physical notion of measurement in the case that the observable commutes with Z. In the case that it does not, the expectation value will still be asymptotically unbiased but not representative of an experiment on a real quantum device.
- Parameters:
hermitian_seq_seq (Sequence[Sequence[str | ndarray]]) – Sequence of sequences of Hermitian matrices/tensors. Each Hermitian is either a tensor (jnp.ndarray) or a string in (‘X’, ‘Y’, ‘Z’). E.g. [[‘Z’, ‘Z’], [‘X’]]
qubits_seq_seq (Sequence[Sequence[int]]) – Sequence of sequences of integer qubit indices. E.g. [[0,1], [2]]
coefficients (Sequence[float] | ndarray) – Sequence of float coefficients to scale the expected values.
- Returns:
Function that takes statetensor, random key and integer number of shots and returns sampled expected value (float).
- Return type:
Callable[[ndarray, jax.random.PRNGKeyArray, int], float]