Liking cljdoc? Tell your friends :D

org.soulspace.qclojure.domain.observables

Domain for quantum observables - Hermitian operators representing measurable quantities.

Observables in quantum mechanics are represented by Hermitian matrices. This namespace provides functions for creating and manipulating observables, calculating expectation values, and working with composite observables.

Design Philosophy:

  • Observables are simple data (matrices) - no complex wrapping
  • Pure functions for all operations
  • Compose complex observables from simple primitives
  • Separate representation, computation, and measurement concerns
Domain for quantum observables - Hermitian operators representing measurable quantities.

Observables in quantum mechanics are represented by Hermitian matrices.
This namespace provides functions for creating and manipulating observables,
calculating expectation values, and working with composite observables.

Design Philosophy:
- Observables are simple data (matrices) - no complex wrapping
- Pure functions for all operations
- Compose complex observables from simple primitives
- Separate representation, computation, and measurement concerns
raw docstring

expectation-valueclj

(expectation-value observable quantum-state)

Calculate expectation value ⟨ψ|O|ψ⟩ of observable O in state ψ

Parameters:

  • observable: Hermitian matrix representing the observable
  • quantum-state: quantum state vector (normalized)

Returns: Real number representing the expectation value

Example: (expectation-value pauli-z |0⟩) ; returns 1.0

Calculate expectation value ⟨ψ|O|ψ⟩ of observable O in state ψ

Parameters:
- observable: Hermitian matrix representing the observable
- quantum-state: quantum state vector (normalized)

Returns:
  Real number representing the expectation value

Example:
  (expectation-value pauli-z |0⟩) ; returns 1.0
sourceraw docstring

expectation-value-density-matrixclj

(expectation-value-density-matrix observable density-matrix)
(expectation-value-density-matrix observable density-matrices weights)

Calculate expectation value Tr(ρO) of observable O for density matrix ρ.

For density matrices (mixed states), the expectation value is calculated as the trace of the product of the density matrix and the observable: Tr(ρO).

This function supports both single density matrices and collections of density matrices with optional weights for ensemble averaging.

Parameters:

  • observable: Hermitian matrix representing the observable
  • density-matrix-or-collection: Either a single density matrix or collection of matrices
  • weights: (optional) Collection of weights for weighted averaging. If not provided, uniform weighting is used for collections.

Returns: For single matrix: Real number representing the expectation value For collection: Map with :mean, :std-dev, :variance, :weights, :individual-values

Examples: (expectation-value-density-matrix pauli-z single-density-matrix) (expectation-value-density-matrix pauli-z [dm1 dm2 dm3]) (expectation-value-density-matrix pauli-z [dm1 dm2] [0.3 0.7])

Calculate expectation value Tr(ρO) of observable O for density matrix ρ.

For density matrices (mixed states), the expectation value is calculated as
the trace of the product of the density matrix and the observable: Tr(ρO).

This function supports both single density matrices and collections of density 
matrices with optional weights for ensemble averaging.

Parameters:
- observable: Hermitian matrix representing the observable
- density-matrix-or-collection: Either a single density matrix or collection of matrices
- weights: (optional) Collection of weights for weighted averaging. If not provided,
          uniform weighting is used for collections.

Returns:
  For single matrix: Real number representing the expectation value
  For collection: Map with :mean, :std-dev, :variance, :weights, :individual-values

Examples:
  (expectation-value-density-matrix pauli-z single-density-matrix)
  (expectation-value-density-matrix pauli-z [dm1 dm2 dm3])
  (expectation-value-density-matrix pauli-z [dm1 dm2] [0.3 0.7])
sourceraw docstring

identity-opclj

Identity observable (I)

Identity observable (I)
sourceraw docstring

linear-combinationclj

(linear-combination coeffs-observables)

Create a linear combination of observables: Σᵢ cᵢ Oᵢ

Parameters:

  • coeffs-observables: sequence of [coefficient observable] pairs

Returns: Matrix representing the linear combination

Example: (linear-combination [[0.5 pauli-x] [0.5 pauli-z]])

Create a linear combination of observables: Σᵢ cᵢ Oᵢ

Parameters:
- coeffs-observables: sequence of [coefficient observable] pairs

Returns:
  Matrix representing the linear combination

Example:
  (linear-combination [[0.5 pauli-x] [0.5 pauli-z]])
sourceraw docstring

matrix-equal?clj

(matrix-equal? m1 m2)

Check if two matrices of complex numbers are equal within tolerance

Check if two matrices of complex numbers are equal within tolerance
sourceraw docstring

measurement-probabilitiesclj

(measurement-probabilities observable quantum-state)

Calculate measurement probabilities for an observable's eigenvalues using eigendecomposition.

This function computes the probability of measuring each eigenvalue of a Hermitian observable when the system is in the given quantum state. The probabilities are calculated as |⟨vᵢ|ψ⟩|² where vᵢ are the eigenvectors and ψ is the state.

Parameters:

  • observable: Hermitian matrix representing the observable
  • quantum-state: quantum state vector (normalized)

Returns: Map with keys representing eigenvalues and values representing probabilities

Example: (measurement-probabilities pauli-z |+⟩) ; => {1.0 0.5, -1.0 0.5}

Calculate measurement probabilities for an observable's eigenvalues using eigendecomposition.

This function computes the probability of measuring each eigenvalue of a Hermitian 
observable when the system is in the given quantum state. The probabilities are 
calculated as |⟨vᵢ|ψ⟩|² where vᵢ are the eigenvectors and ψ is the state.

Parameters:
- observable: Hermitian matrix representing the observable
- quantum-state: quantum state vector (normalized)

Returns:
  Map with keys representing eigenvalues and values representing probabilities

Example:
  (measurement-probabilities pauli-z |+⟩) ; => {1.0 0.5, -1.0 0.5}
sourceraw docstring

pauli-char->matrixclj

(pauli-char->matrix pauli-char)

Convert a single Pauli character to its matrix representation

Convert a single Pauli character to its matrix representation
sourceraw docstring

pauli-commute?clj

(pauli-commute? p1 p2)

Check if two Pauli operators commute.

Two Pauli strings commute if they differ on an even number of positions where both have non-identity, non-equal operators. This is crucial for:

  • Error correction syndrome measurements
  • Hamiltonian term grouping for simultaneous measurement
  • Quantum algorithm optimization

Parameters:

  • p1: First Pauli string
  • p2: Second Pauli string (must be same length as p1)

Returns: Boolean indicating if operators commute

Examples: (pauli-commute? "XII" "IXI") ; => true (differ at 0 positions) (pauli-commute? "XII" "ZII") ; => false (differ at 1 position) (pauli-commute? "XYZ" "ZYX") ; => false (differ at 2 positions)

Check if two Pauli operators commute.

Two Pauli strings commute if they differ on an even number of positions
where both have non-identity, non-equal operators. This is crucial for:
- Error correction syndrome measurements
- Hamiltonian term grouping for simultaneous measurement
- Quantum algorithm optimization

Parameters:
- p1: First Pauli string
- p2: Second Pauli string (must be same length as p1)

Returns:
Boolean indicating if operators commute

Examples:
  (pauli-commute? "XII" "IXI") ; => true (differ at 0 positions)
  (pauli-commute? "XII" "ZII") ; => false (differ at 1 position)
  (pauli-commute? "XYZ" "ZYX") ; => false (differ at 2 positions)
sourceraw docstring

pauli-operatorsclj

The four single-qubit Pauli operators: Identity, X (bit-flip), Y (both), Z (phase-flip)

The four single-qubit Pauli operators: Identity, X (bit-flip), Y (both), Z (phase-flip)
sourceraw docstring

pauli-string->observableclj

(pauli-string->observable pauli-str)

Convert a Pauli string to an observable matrix

Parameters:

  • pauli-str: string like 'XZYI' representing multi-qubit Pauli operator

Returns: Matrix representing the tensor product of Pauli matrices

Example: (pauli-string->observable 'XZ') ; creates X ⊗ Z

Convert a Pauli string to an observable matrix

Parameters:
- pauli-str: string like 'XZYI' representing multi-qubit Pauli operator

Returns:
  Matrix representing the tensor product of Pauli matrices

Example:
  (pauli-string->observable 'XZ') ; creates X ⊗ Z
sourceraw docstring

pauli-string?clj

(pauli-string? s)

Check if a string is a valid Pauli string.

A valid Pauli string contains only the characters I, X, Y, Z representing the Pauli operators.

Parameters:

  • s: String to check

Returns: Boolean indicating validity

Example: (pauli-string? "XYZII") ; => true (pauli-string? "ABC") ; => false

Check if a string is a valid Pauli string.

A valid Pauli string contains only the characters I, X, Y, Z representing
the Pauli operators.

Parameters:
- s: String to check

Returns:
Boolean indicating validity

Example:
  (pauli-string? "XYZII") ; => true
  (pauli-string? "ABC")   ; => false
sourceraw docstring

pauli-weightclj

(pauli-weight pauli-str)

Calculate the weight of a Pauli string (number of non-identity operators).

The weight is the number of qubits on which non-trivial operations are performed. This is an important metric in quantum error correction and algorithm analysis.

Parameters:

  • pauli-str: Pauli string like 'XYZII'

Returns: Integer count of non-I operators

Example: (pauli-weight "XYZII") ; => 3 (pauli-weight "IIIII") ; => 0

Calculate the weight of a Pauli string (number of non-identity operators).

The weight is the number of qubits on which non-trivial operations are performed.
This is an important metric in quantum error correction and algorithm analysis.

Parameters:
- pauli-str: Pauli string like 'XYZII'

Returns:
Integer count of non-I operators

Example:
  (pauli-weight "XYZII") ; => 3
  (pauli-weight "IIIII") ; => 0
sourceraw docstring

pauli-xclj

Pauli-X observable (σₓ)

Pauli-X observable (σₓ)
sourceraw docstring

pauli-yclj

Pauli-Y observable (σᵧ)

Pauli-Y observable (σᵧ)
sourceraw docstring

pauli-zclj

Pauli-Z observable (σᵤ)

Pauli-Z observable (σᵤ)
sourceraw docstring

projector-0clj

Projector onto |0⟩ state

Projector onto |0⟩ state
sourceraw docstring

projector-1clj

Projector onto |1⟩ state

Projector onto |1⟩ state
sourceraw docstring

tensor-productclj

(tensor-product observables)

Create tensor product of observables: O₁ ⊗ O₂ ⊗ ... ⊗ Oₙ

Parameters:

  • observables: sequence of observable matrices

Returns: Matrix representing the tensor product

Example: (tensor-product [pauli-x pauli-z])

Create tensor product of observables: O₁ ⊗ O₂ ⊗ ... ⊗ Oₙ

Parameters:
- observables: sequence of observable matrices

Returns:
  Matrix representing the tensor product

Example:
  (tensor-product [pauli-x pauli-z])
sourceraw docstring

varianceclj

(variance observable quantum-state)

Calculate variance of observable: ⟨O²⟩ - ⟨O⟩²

Parameters:

  • observable: Hermitian matrix representing the observable
  • quantum-state: quantum state vector (normalized)

Returns: Real number representing the variance

Calculate variance of observable: ⟨O²⟩ - ⟨O⟩²

Parameters:
- observable: Hermitian matrix representing the observable
- quantum-state: quantum state vector (normalized)

Returns:
  Real number representing the variance
sourceraw docstring

zero-matrixclj

(zero-matrix rows cols)

Create a zero matrix of complex numbers of given dimensions

Create a zero matrix of complex numbers of given dimensions
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close