Skip to main content

Overview

The QC framework provides comprehensive entanglement analysis tools for quantum states. These features enable characterization of non-classical correlations essential for quantum algorithms and molecular simulations.
Entanglement analysis is integrated throughout the framework, from basic Bell states to complex molecular ground states.

Shannon Entropy Measurement

Definition

For a quantum state |ψ⟩ = Σₖ αₖ|k⟩, the Shannon entropy quantifies information content: S=kP(k)log2P(k)S = -\sum_k P(k) \log_2 P(k) Where P(k) = |αₖ|² are measurement probabilities.

Interpretation

Entropy (bits)State TypeExample
0Pure product state|00⟩
1Maximally entangled (2 qubits)(|00⟩+|11⟩)/√2
nUniform superpositionQFT on n qubits
Shannon entropy uses log₂, measuring information in bits:
  • 1 bit = binary choice (0 or 1)
  • n bits = 2ⁿ distinguishable states
  • Maximum entropy for n qubits = n bits (uniform distribution over 2ⁿ states)
This matches classical information theory, making quantum-classical comparisons natural.

Entangled State Preparation

Bell States

The four maximally entangled two-qubit states:
from quantum_computer import QuantumComputer

qc = QuantumComputer(config)

# Bell state |Φ+⟩ = (|00⟩ + |11⟩)/√2
result = qc.bell_state(backend="schrodinger")

print(f"Entropy: {result.entropy():.4f} bits")  # 1.0000
print(f"P(|00⟩): {result.probabilities()[0]:.4f}")  # 0.5000
print(f"P(|11⟩): {result.probabilities()[3]:.4f}")  # 0.5000
From README.md:249-250:
Bell states: P(|00>) = 0.5000, P(|11>) = 0.5000, entropy = 1.0000 bits.
All three backends (Hamiltonian, Schrödinger, Dirac) produce identical results.

GHZ States

Greenberger-Horne-Zeilinger states extend Bell entanglement to n qubits: GHZn=0n+1n2|\text{GHZ}_n\rangle = \frac{|0\rangle^{\otimes n} + |1\rangle^{\otimes n}}{\sqrt{2}}
# 3-qubit GHZ: (|000⟩ + |111⟩)/√2
result = qc.ghz_state(n_qubits=3, backend="hamiltonian")

print(f"Entropy: {result.entropy():.4f}")  # 1.0000
print(f"P(|000⟩): {result.probabilities()[0]:.4f}")  # 0.5000
print(f"P(|111⟩): {result.probabilities()[7]:.4f}")  # 0.5000
From README.md:251-252:
GHZ states: P(|000>) = 0.5000, P(|111>) = 0.5000, entropy = 1.0000 bits.
Both are n-qubit entangled states, but with different properties:GHZ State: Maximum correlation, fragile to loss
  • Losing 1 qubit → fully separable
  • Used for: distributed quantum computing, quantum secret sharing
W State: Partial entanglement, robust to loss
  • Losing 1 qubit → remaining n-1 still entangled
  • Used for: quantum networking, robust communication
# W state: (|001⟩ + |010⟩ + |100⟩)/√3
from entangled_hydrogen import WState

w_state = WState(n_qubits=3)
result = w_state.prepare(qc, "schrodinger", factory)

print(f"Entropy: {result.entropy():.4f}")  # log₂(3) ≈ 1.585

Entanglement Entropy

For bipartite splits of an n-qubit system, entanglement entropy measures quantum correlations between subsystems.

Von Neumann Entropy

Given a cut dividing qubits into regions A and B: SA=Tr(ρAlog2ρA)S_A = -\text{Tr}(\rho_A \log_2 \rho_A) Where ρ_A = Tr_B(|ψ⟩⟨ψ|) is the reduced density matrix.

MPS Implementation

From topological_hilbert_compression2.py:335-348:
def entanglement_entropy(self, cut: int) -> float:
    """Calculate entanglement entropy at bipartite cut."""
    if cut <= 0 or cut >= self.n_qubits:
        return 0.0
    
    # Move to canonical form centered at cut
    if self._canonical_form != "mixed" or self._center != cut:
        self._center = cut
        self._canonicalize()
    
    # Extract singular values from center tensor
    center_tensor = self._cores[cut].tensor
    chi_l, d, chi_r = center_tensor.shape
    matrix = center_tensor.reshape(chi_l * d, chi_r)
    _, s, _ = torch.linalg.svd(matrix, full_matrices=False)
    
    # Von Neumann entropy from singular value spectrum
    s_squared = s ** 2
    s_squared = s_squared / (torch.sum(s_squared) + 1e-12)
    entropy = -torch.sum(s_squared * torch.log2(s_squared + 1e-12))
    return float(entropy.item())

Scaling Laws

SystemMax EntropyScaling
Product state0-
Bell state1 bit-
GHZ state1 bitconstant
Critical 1Dlog(L)logarithmic
Genericmin(n_A, n_B)volume law
Volume-law entanglement (S ~ n) makes classical simulation exponentially hard. This is the power of quantum computing.

Entangled Hydrogen Visualization

Concept

From entangled_hydrogen.py, quantum entanglement is visualized through correlated hydrogen orbitals:
from entangled_hydrogen import EntangledHydrogenExperiment, EntangledHydrogenConfig

config = EntangledHydrogenConfig(
    grid_size=16,
    device="cpu",
    output_dir="download"
)

experiment = EntangledHydrogenExperiment(config)

# Bell state with 1s + 2s orbitals
result = experiment.run_bell_entangled_hydrogen(
    n1=1, l1=0, m1=0,  # 1s
    n2=2, l2=0, m2=0,  # 2s
    backend="schrodinger",
    num_samples=100000
)

print(f"Quantum entropy: {result['quantum_result'].entropy():.4f}")
print(f"Saved figure: {result['save_path']}")

Features (from entangled_hydrogen.py:361-405)

Entangled orbitals are sampled using rejection sampling:
  1. Sample from joint probability distribution
  2. Accept points according to wavefunction amplitude
  3. Create 3D visualization colored by phase and orbital
def sample_entangled_state(
    self,
    n1: int, l1: int, m1: int,  # First orbital
    n2: int, l2: int, m2: int,  # Second orbital  
    num_samples: int,
    entanglement_weight: float = 0.5
) -> Dict[str, Any]:
    """Sample from entangled state |ψ⟩ = α|n₁l₁m₁⟩ + β|n₂l₂m₂⟩"""
    samples_1 = self.sample_orbital(n1, l1, m1, num_samples // 2)
    samples_2 = self.sample_orbital(n2, l2, m2, num_samples // 2)
    
    # Combine and shuffle
    combined_x = np.concatenate([samples_1['x'], samples_2['x']])
    combined_y = np.concatenate([samples_1['y'], samples_2['y']])
    combined_z = np.concatenate([samples_1['z'], samples_2['z']])
    
    idx = np.random.permutation(len(combined_x))
    return {
        'x': combined_x[idx],
        'y': combined_y[idx],
        'z': combined_z[idx],
        'orbital_label': orbital_label[idx],
        'entanglement_weight': entanglement_weight
    }
From entangled_hydrogen.py:408-566, the visualizer creates:
  1. 3D scatter plot: Electron positions colored by phase and orbital
  2. XY projection: Top view density map
  3. XZ projection: Side view density map
  4. Statistics panel: Entropy, particle counts, radial distributions
All rendered at high resolution (24”×20” @ 150 DPI).

Entropy Evolution Tracking

Phase Coherence Tests

From README.md:746-780, the framework includes 22 phase coherence tests:
--- Group 4: Entanglement (Shannon entropy) ---
  [PASS] Bell state entropy = 1 bit  (got 1.0000)
  [PASS] GHZ-3 entropy = 1 bit  (got 1.0000)
  [PASS] QFT-3 entropy = 3 bits  (got 3.0000)
  [PASS] |0⟩ entropy = 0 bits  (got 0.0000)
All 22 tests passed across all three backends.

Molecular VQE Entropy

From README.md:266, H₂ VQE tracks entropy during optimization:
# Initial HF state
P(|1100⟩) = 1.0, entropy = 0 bits

# After singles excitations  
P(|1100⟩) = 0.85, P(|0011⟩) = 0.12, entropy = 0.71 bits

# After doubles (converged)
P(|1100⟩) = 0.92, P(|0011⟩) = 0.06, entropy = 0.42 bits
Lower entropy at convergence indicates the ground state has less mixing than excited configurations.

Implementation: Measurement Result

From quantum_computer.py, every measurement includes entropy:
@dataclass
class MeasurementResult:
    n_qubits: int
    probabilities: torch.Tensor  # Shape: (2^n,)
    amplitudes: Optional[torch.Tensor] = None
    
    def entropy(self) -> float:
        """Calculate Shannon entropy in bits."""
        probs = self.probabilities
        probs = probs[probs > 1e-12]  # Filter zeros
        if len(probs) == 0:
            return 0.0
        return float(-torch.sum(probs * torch.log2(probs)).item())
    
    def most_probable_bitstring(self) -> str:
        """Return most probable computational basis state."""
        idx = int(self.probabilities.argmax().item())
        return format(idx, f'0{self.n_qubits}b')

Experimental Validation

Backend Agreement (README.md:246-267)

All three neural backends produce identical entanglement signatures:
TestExpectedHamiltonianSchrödingerDirac
Bell entropy1.01.00001.00001.0000
GHZ entropy1.01.00001.00001.0000
QFT-3 entropy3.03.00003.00003.0000
Grover entropy0.45950.45950.45950.4595
Perfect agreement to 4 decimal places

Molecular Entanglement (README.md:265-266)

Molecular hydrogen VQE: E = -1.13730604 Ha, matching FCI to within 1.31e-11 Ha. Correlation energy recovered: 100.0%.
Ground state entanglement correctly captured by UCCSD ansatz.

Advanced Features

GHZ Multi-Orbital States

From entangled_hydrogen.py:672-743:
def run_ghz_entangled_hydrogen(
    self,
    orbitals: List[Tuple[int, int, int]],  # [(n,l,m), ...]
    backend: str = "schrodinger",
    num_samples: int = 150000
) -> Dict[str, Any]:
    """Create GHZ state correlated with n hydrogen orbitals."""
    n_qubits = len(orbitals)
    ghz_state = GHZState(n_qubits)
    quantum_result = ghz_state.prepare(self.qc, backend)
    
    # Sample each orbital
    all_samples = []
    for n, l, m in orbitals:
        samples = self.sampler.sample_orbital(n, l, m, num_samples // n_qubits)
        all_samples.append(samples)
    
    # Combine and visualize
    # ...

Relativistic Entanglement

From entangled_hydrogen.py:793-850, Dirac spinors enable relativistic entanglement:
def run_relativistic_entangled_hydrogen(self) -> Dict[str, Any]:
    """Entangled states with Dirac backend."""
    result = self.run_bell_entangled_hydrogen(
        backend="dirac",  # 8-channel Dirac spinors
        suffix="relativistic"
    )
    
    # Calculate fine structure corrections
    from relativistic_hydrogen import DiracHydrogenAtom
    dirac_atom = DiracHydrogenAtom(config)
    
    E1_dirac = dirac_atom.energy_level_dirac(n1, kappa1)
    E2_dirac = dirac_atom.energy_level_dirac(n2, kappa2)
    
    result['relativistic_data'] = {
        'E1_dirac': E1_dirac,
        'E2_dirac': E2_dirac,
        'fine_structure_1': E1_dirac - E1_schrod,
        'fine_structure_2': E2_dirac - E2_schrod
    }
    return result

Usage Examples

Basic Entanglement Measurement

from quantum_computer import QuantumComputer, SimulatorConfig

config = SimulatorConfig(grid_size=16, device="cpu")
qc = QuantumComputer(config)

# Create Bell state
result = qc.bell_state(backend="hamiltonian")

print(f"Shannon entropy: {result.entropy():.4f} bits")
print(f"Entanglement: {'Yes' if result.entropy() > 0.1 else 'No'}")

# Check marginals (should be maximally mixed)
for i in range(result.n_qubits):
    p1 = result.marginal_probability(i, |1⟩)
    print(f"Qubit {i}: P(|1⟩) = {p1:.4f}")  # 0.5000

Full Analysis Pipeline

# Run complete entanglement demonstrations
experiment = EntangledHydrogenExperiment(config)
results = experiment.run_all_demonstrations(num_samples=100000)

for name, result in results.items():
    qr = result['quantum_result']
    print(f"{name}:")
    print(f"  Entropy: {qr.entropy():.4f} bits")
    print(f"  Most probable: |{qr.most_probable_bitstring()}⟩")
    print(f"  Figure saved: {result['save_path']}")

Topology

Topological entanglement entropy

QED

Entanglement in field states

References

  • README.md experimental logs: lines 246-267, 746-780
  • Implementation: entangled_hydrogen.py
  • Phase coherence tests: lines 743-780
  • Nielsen & Chuang, “Quantum Computation and Quantum Information”, Chapter 2
For production entanglement analysis, use the built-in entropy() method on MeasurementResult objects. All backends preserve entanglement structure exactly.

Build docs developers (and LLMs) love