CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-qiskit

An open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

Pending
Overview
Eval results
Files

quantum-information.mddocs/

Quantum Information Processing

Qiskit's quantum information module provides mathematical foundations for quantum computing including quantum states, operators, channels, and information-theoretic measures. This enables quantum algorithm development, state analysis, and quantum channel characterization.

Capabilities

Quantum States

Representations of pure and mixed quantum states with manipulation and analysis operations.

class Statevector:
    def __init__(self, data, dims=None):
        """
        Initialize a quantum state vector.
        
        Parameters:
        - data: State vector data (array-like, QuantumCircuit, or Instruction)
        - dims: Subsystem dimensions
        """
    
    def evolve(self, other, qargs=None):
        """Evolve state by quantum operation."""
    
    def expectation_value(self, oper, qargs=None):
        """Calculate expectation value of observable."""
    
    def sample_counts(self, shots):
        """Sample measurement outcomes."""
    
    def sample_memory(self, shots):  
        """Sample individual measurement results."""
    
    def probabilities(self, qargs=None):
        """Get measurement probabilities."""
    
    def probabilities_dict(self, qargs=None, decimals=None):
        """Get probabilities as dictionary."""
    
    def reset(self, qargs=None):
        """Reset specified qubits to |0⟩."""
    
    def measure(self, qargs=None):
        """Measure specified qubits."""
    
    def is_valid(self, atol=None, rtol=None):
        """Check if state is valid (normalized)."""
    
    def purity(self):
        """Calculate state purity."""
    
    def conjugate(self):
        """Return complex conjugate of state."""
    
    def tensor(self, other):
        """Tensor product with another state."""
    
    @classmethod
    def from_label(cls, label):
        """Create state from computational basis label."""
    
    @classmethod  
    def from_instruction(cls, instruction):
        """Create state from quantum instruction."""

class DensityMatrix:
    def __init__(self, data, dims=None):
        """
        Initialize a density matrix.
        
        Parameters:
        - data: Density matrix data
        - dims: Subsystem dimensions
        """
    
    def evolve(self, other, qargs=None):
        """Evolve state by quantum channel."""
    
    def expectation_value(self, oper, qargs=None):
        """Calculate expectation value."""
    
    def probabilities(self, qargs=None):
        """Get measurement probabilities."""
    
    def sample_counts(self, shots):
        """Sample measurement outcomes."""
    
    def purity(self):
        """Calculate state purity."""
    
    def trace(self):
        """Calculate trace of density matrix."""
    
    def is_valid(self, atol=None, rtol=None):
        """Check if density matrix is valid."""
    
    def tensor(self, other):
        """Tensor product with another state."""
    
    @classmethod
    def from_label(cls, label):
        """Create density matrix from basis label."""

class StabilizerState:
    def __init__(self, data, validate=True):
        """
        Initialize a stabilizer state.
        
        Parameters:
        - data: Stabilizer tableau or quantum circuit
        - validate: Whether to validate the stabilizer state
        """
    
    def evolve(self, other, qargs=None):
        """Evolve by Clifford operation."""
    
    def expectation_value(self, oper, qargs=None):
        """Calculate Pauli expectation value."""
    
    def probabilities(self, qargs=None):
        """Get measurement probabilities."""
    
    def sample_counts(self, shots):
        """Sample measurement outcomes."""
    
    def measure(self, qargs=None):
        """Measure qubits and collapse state."""
    
    def reset(self, qargs=None):
        """Reset qubits to |0⟩."""
    
    def is_valid(self):
        """Check if stabilizer state is valid."""

Quantum Operators

Mathematical representations of quantum operations and measurements.

class Operator:
    def __init__(self, data, input_dims=None, output_dims=None):
        """
        Initialize a quantum operator.
        
        Parameters:
        - data: Operator matrix data
        - input_dims: Input subsystem dimensions
        - output_dims: Output subsystem dimensions
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another operator."""
    
    def tensor(self, other):
        """Tensor product with another operator."""
    
    def expand(self, other):
        """Tensor expand with another operator."""
    
    def power(self, n):
        """Return operator raised to power n."""
    
    def conjugate(self):
        """Return complex conjugate."""
    
    def transpose(self):
        """Return transpose."""
    
    def adjoint(self):
        """Return adjoint (conjugate transpose)."""
    
    def is_unitary(self, atol=None, rtol=None):
        """Check if operator is unitary."""
    
    def trace(self):
        """Calculate trace."""
    
    @classmethod
    def from_label(cls, label):
        """Create operator from Pauli label."""
    
    @classmethod
    def from_circuit(cls, circuit):
        """Create operator from quantum circuit."""

class Pauli:
    def __init__(self, data=None):
        """
        Initialize a Pauli operator.
        
        Parameters:
        - data: Pauli string or array representation
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another Pauli."""
    
    def tensor(self, other):
        """Tensor product with another Pauli."""
    
    def expand(self, other):
        """Tensor expand with another Pauli."""
    
    def conjugate(self):
        """Return complex conjugate."""
    
    def transpose(self):
        """Return transpose."""
    
    def adjoint(self):
        """Return adjoint."""
    
    def commutes(self, other):
        """Check if commutes with another Pauli."""
    
    def anticommutes(self, other):
        """Check if anticommutes with another Pauli."""
    
    def evolve(self, other, frame='h'):
        """Evolve Pauli by Clifford operation."""
    
    @property
    def x(self):
        """X component of Pauli."""
    
    @property  
    def z(self):
        """Z component of Pauli."""
    
    @property
    def phase(self):
        """Phase of Pauli (+1, -1, +1j, -1j)."""

class PauliList:
    def __init__(self, data):
        """
        Initialize a list of Pauli operators.
        
        Parameters:
        - data: List of Pauli strings or array data
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another PauliList."""
    
    def tensor(self, other):
        """Tensor product with another PauliList."""
    
    def commutes(self, other):
        """Check commutation with another PauliList."""
    
    def anticommutes(self, other):
        """Check anticommutation with another PauliList."""
    
    def evolve(self, other, frame='h'):
        """Evolve PauliList by Clifford."""
    
    def sort(self, weight=False):
        """Sort Pauli operators."""
    
    def unique(self, return_indices=False, return_counts=False):
        """Find unique Pauli operators."""

class Clifford:
    def __init__(self, data, validate=True):
        """
        Initialize a Clifford operator.
        
        Parameters:
        - data: Clifford data (matrix, QuantumCircuit, or Instruction)
        - validate: Whether to validate the Clifford representation
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another Clifford."""
    
    def tensor(self, other):
        """Tensor product with another Clifford."""
    
    def expand(self, other):  
        """Tensor expand with another Clifford."""
    
    def conjugate(self):
        """Return complex conjugate."""
    
    def transpose(self):
        """Return transpose."""
    
    def adjoint(self):
        """Return adjoint."""
    
    def is_unitary(self):
        """Check if Clifford is unitary."""
    
    def to_circuit(self):
        """Convert to quantum circuit."""
    
    def to_matrix(self):
        """Convert to unitary matrix."""
    
    @classmethod
    def from_circuit(cls, circuit):
        """Create Clifford from quantum circuit."""
    
    @classmethod
    def from_label(cls, label):
        """Create Clifford from Pauli label."""

class ScalarOp:
    def __init__(self, dims, coeff=1):
        """
        Initialize a scalar operator (identity times scalar).
        
        Parameters:
        - dims: Operator dimensions
        - coeff: Scalar coefficient
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another operator."""
    
    def tensor(self, other):
        """Tensor product with another operator."""
    
    def to_operator(self):
        """Convert to dense Operator."""

class CNOTDihedral:
    def __init__(self, data=None, num_qubits=None):
        """
        Initialize a CNOT-dihedral operator.
        
        Parameters:
        - data: Operator data 
        - num_qubits: Number of qubits
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another CNOTDihedral."""
    
    def tensor(self, other):
        """Tensor product with another CNOTDihedral."""
    
    def adjoint(self):
        """Return adjoint."""
    
    def to_operator(self):
        """Convert to dense Operator."""

class SparsePauliOp:
    def __init__(self, data, coeffs=None, ignore_pauli_phase=False, copy=True):
        """
        Initialize a sparse Pauli operator.
        
        Parameters:  
        - data: Pauli operators (PauliList or list of strings)
        - coeffs: Coefficients for each Pauli
        - ignore_pauli_phase: Whether to ignore Pauli phases
        - copy: Whether to copy input data
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another operator."""
    
    def tensor(self, other):
        """Tensor product with another operator."""
    
    def expand(self, other):
        """Tensor expand with another operator."""
    
    def conjugate(self):
        """Return complex conjugate."""
    
    def transpose(self, copy=True):
        """Return transpose."""
    
    def adjoint(self):
        """Return adjoint."""
    
    def simplify(self, atol=None):
        """Simplify by combining duplicate Paulis."""
    
    def is_hermitian(self, atol=None):
        """Check if operator is Hermitian."""
    
    def expectation_value(self, state):
        """Calculate expectation value for given state."""
    
    @classmethod
    def from_operator(cls, op):
        """Convert general operator to SparsePauliOp."""
    
    @classmethod
    def from_list(cls, obj):
        """Create from list of (Pauli string, coefficient) pairs."""

Quantum Channels

Representations of quantum channels and noise processes.

class Choi:
    def __init__(self, data, input_dims=None, output_dims=None):
        """
        Initialize Choi matrix representation.
        
        Parameters:
        - data: Choi matrix data
        - input_dims: Input dimensions
        - output_dims: Output dimensions
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another channel."""
    
    def tensor(self, other):
        """Tensor product with another channel."""
    
    def expand(self, other):
        """Tensor expand with another channel."""
    
    def conjugate(self):
        """Return complex conjugate."""
    
    def transpose(self):
        """Return transpose."""
    
    def adjoint(self):
        """Return adjoint."""
    
    def is_cp(self, atol=None, rtol=None):
        """Check if completely positive."""
    
    def is_tp(self, atol=None, rtol=None):
        """Check if trace preserving."""
    
    def is_cptp(self, atol=None, rtol=None):
        """Check if CPTP (valid quantum channel)."""

class Kraus:
    def __init__(self, data, input_dims=None, output_dims=None):
        """
        Initialize Kraus operator representation.
        
        Parameters:
        - data: List of Kraus operators
        - input_dims: Input dimensions
        - output_dims: Output dimensions  
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another channel."""
    
    def tensor(self, other):
        """Tensor product with another channel."""
    
    def is_cp(self, atol=None, rtol=None):
        """Check if completely positive."""
    
    def is_tp(self, atol=None, rtol=None):
        """Check if trace preserving."""

class SuperOp:
    def __init__(self, data, input_dims=None, output_dims=None):
        """
        Initialize superoperator representation.
        
        Parameters:
        - data: Superoperator matrix
        - input_dims: Input dimensions
        - output_dims: Output dimensions
        """
    
    def compose(self, other, qargs=None, front=False):
        """Compose with another channel."""
    
    def tensor(self, other):
        """Tensor product with another channel."""
    
    def is_cptp(self, atol=None, rtol=None):
        """Check if CPTP."""

Information Measures

Quantum information-theoretic measures and distance functions.

def state_fidelity(state1, state2, validate=True):
    """
    Calculate fidelity between two quantum states.
    
    Parameters:
    - state1, state2: Quantum states (Statevector, DensityMatrix, or array)
    - validate: Whether to validate input states
    
    Returns:
    float: State fidelity (0 to 1)
    """

def process_fidelity(channel1, channel2, require_cptp=True):
    """
    Calculate process fidelity between quantum channels.
    
    Parameters:
    - channel1, channel2: Quantum channels
    - require_cptp: Whether channels must be CPTP
    
    Returns:
    float: Process fidelity
    """

def average_gate_fidelity(channel, target=None, require_cptp=True):
    """
    Calculate average gate fidelity.
    
    Parameters:
    - channel: Quantum channel
    - target: Target unitary (identity if None)
    - require_cptp: Whether channel must be CPTP
    
    Returns:
    float: Average gate fidelity
    """

def gate_error(channel, target=None, require_cptp=True):
    """
    Calculate gate error (1 - average_gate_fidelity).
    
    Parameters:
    - channel: Quantum channel
    - target: Target unitary
    - require_cptp: Whether channel must be CPTP
    
    Returns:
    float: Gate error
    """

def diamond_norm(choi, **kwargs):
    """
    Calculate diamond norm of quantum channel.
    
    Parameters:
    - choi: Channel in Choi representation
    
    Returns:  
    float: Diamond norm
    """

def entropy(state, base=2):
    """
    Calculate von Neumann entropy.
    
    Parameters:
    - state: Quantum state (DensityMatrix)
    - base: Logarithm base
    
    Returns:
    float: von Neumann entropy
    """

def mutual_information(state, base=2):
    """
    Calculate mutual information between subsystems.
    
    Parameters:
    - state: Bipartite quantum state
    - base: Logarithm base
    
    Returns:
    float: Mutual information
    """

def entanglement_of_formation(state):
    """
    Calculate entanglement of formation.
    
    Parameters:
    - state: Bipartite quantum state
    
    Returns:
    float: Entanglement of formation
    """

def concurrence(state):
    """
    Calculate concurrence entanglement measure.
    
    Parameters:
    - state: Bipartite quantum state
    
    Returns:
    float: Concurrence (0 to 1)
    """

def partial_trace(state, qargs):
    """
    Calculate partial trace over specified subsystems.
    
    Parameters:
    - state: Quantum state
    - qargs: Subsystems to trace out
    
    Returns:
    Reduced quantum state
    """

Random Quantum Objects

Generation of random quantum states, operators, and channels for testing and research.

def random_statevector(dims, seed=None):
    """
    Generate random quantum state vector.
    
    Parameters:
    - dims: Dimensions (int or list)
    - seed: Random seed
    
    Returns:
    Statevector: Random state vector
    """

def random_density_matrix(dims, rank=None, method='Hilbert-Schmidt', seed=None):
    """
    Generate random density matrix.
    
    Parameters:
    - dims: Dimensions
    - rank: Rank of density matrix
    - method: Generation method
    - seed: Random seed
    
    Returns:
    DensityMatrix: Random density matrix
    """

def random_unitary(dims, seed=None):
    """
    Generate random unitary matrix.
    
    Parameters:
    - dims: Matrix dimensions
    - seed: Random seed
    
    Returns:
    Operator: Random unitary operator
    """

def random_hermitian(dims, traceless=False, seed=None):
    """
    Generate random Hermitian matrix.
    
    Parameters:
    - dims: Matrix dimensions
    - traceless: Whether matrix should be traceless
    - seed: Random seed
    
    Returns:
    Operator: Random Hermitian operator
    """

def random_pauli(num_qubits, group_phase=False, seed=None):
    """
    Generate random Pauli operator.
    
    Parameters:
    - num_qubits: Number of qubits
    - group_phase: Whether to include group phase
    - seed: Random seed
    
    Returns:
    Pauli: Random Pauli operator
    """

def random_clifford(num_qubits, seed=None):
    """
    Generate random Clifford operator.
    
    Parameters:
    - num_qubits: Number of qubits
    - seed: Random seed
    
    Returns:
    Clifford: Random Clifford operator
    """

Usage Examples

from qiskit.quantum_info import Statevector, DensityMatrix, Operator, Pauli, SparsePauliOp
from qiskit.quantum_info import state_fidelity, process_fidelity, entropy, random_statevector
import numpy as np

# Create quantum states
bell_state = Statevector.from_label('00')
bell_state = bell_state.evolve(Operator.from_label('HI'))  # H on first qubit
bell_state = bell_state.evolve(Operator.from_label('CX'))  # CNOT

# Calculate expectation values
z_obs = SparsePauliOp.from_list([('ZZ', 1.0)])
expectation = bell_state.expectation_value(z_obs)

# Work with mixed states
mixed_state = DensityMatrix(bell_state)
purity = mixed_state.purity()

# Create operators
pauli_x = Pauli('X')
pauli_y = Pauli('Y') 
xy_op = pauli_x.tensor(pauli_y)  # X⊗Y operator

# Sparse Pauli operators for Hamiltonians
hamiltonian = SparsePauliOp.from_list([
    ('XX', 0.5),
    ('YY', 0.5), 
    ('ZZ', -1.0),
    ('ZI', 0.1),
    ('IZ', 0.1)
])

# Calculate information measures
state1 = random_statevector(4)
state2 = random_statevector(4)
fidelity = state_fidelity(state1, state2)

# Partial trace for subsystem analysis
bipartite_state = random_statevector(4)  # 2-qubit state
reduced_state = partial_trace(bipartite_state, [1])  # Trace out second qubit

# Channel operations
unitary_channel = Operator.from_label('H')
evolved_state = bell_state.evolve(unitary_channel)

Install with Tessl CLI

npx tessl i tessl/pypi-qiskit

docs

circuit-construction.md

circuit-formats.md

gates-operations.md

index.md

primitives.md

providers.md

quantum-information.md

synthesis.md

transpilation.md

visualization.md

tile.json