ket.quantumstate

Quantum state snapshot.

This module provides the base class for a snapshot of a quantum state obtained using a quantum simulator.

Classes ket.quantumstate

QuantumState

Snapshot of a quantum state.

class QuantumState(*qubits: Quant)

Snapshot of a quantum state.

This class holds a reference for a snapshot of a quantum state obtained using a quantum simulator. The result may not be available right after the measurement call, especially in batch execution.

You can instantiate this class by calling the dump function.

Parameters:

qubits – Qubits from which to capture a quantum state snapshot.

property states: dict[int, complex] | None

Get the quantum state.

Returns a dictionary mapping base states to their corresponding probability amplitudes.

Returns:

The quantum state, or None if the quantum state information is not available.

get() dict[int, complex]

Get the quantum state.

If the quantum state is not available, the quantum process will execute to get the result.

property probability: dict[int, float] | None

Get the measurement probabilities.

Returns a dictionary mapping base states to their corresponding measurement probabilities.

Returns:

The measurement probabilities, or None if the quantum state information is not available.

sample(shots=4096, seed=None) dict[int, int] | None

Get the quantum execution shots.

The parameters shots and seed are used to generate the sample from the quantum state snapshot.

Parameters:
  • shots – Number of shots. Defaults to 4096.

  • seed – Seed for the RNG.

Returns:

A dictionary mapping measurement outcomes to their frequencies in the generated sample, or None if the quantum state information is not available.

sphere() go.Figure

Generate a Bloch sphere plot representing the quantum state.

This method creates a Bloch sphere plot visualizing of one qubit quantum state.

Note

This method requires additional dependencies from ket-lang[plot].

Install with: pip install ket-lang[plot].

Returns:

A Bloch sphere plot illustrating the quantum state.

show(mode: Literal['latex', 'str'] | None = None, polar: bool = False, round_tol: float = 1e-06) str

Return the quantum state as a formatted string or LaTeX Math object.

Parameters:
  • mode – If "str", returns a plain text string. If "latex", returns a LaTeX Math representation. Defaults to "latex" in Jupyter Notebooks, otherwise "str".

  • polar – If True, prints complex coefficients in polar form (r * e^{i * theta}).

  • round_tol – Numerical tolerance used when rounding values.

Returns:

The formatted quantum state as a string, or Latex Math.

histogram(mode: Literal['bin', 'dec'] = 'dec', **kwargs) go.Figure

Generate a histogram representing the quantum state.

This method creates a histogram visualizing the probability distribution of the quantum state.

Note

This method requires additional dependencies from ket-lang[plot].

Install with: pip install ket-lang[plot].

Parameters:
  • mode – If "bin", display the states in binary format. If "dec",

  • "dec". (display the states in decimal format. Defaults to)

  • **kwargs – Additional keyword arguments passed to plotly.express.bar.

Returns:

Histogram of the quantum state.