Skills

From XuShuwenn/RedAct · View interactive version

Skills is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Compute quantum state expectation values for Pauli matrices from Bloch sphere coordinates. Use when working with quantum state analysis, Bloch sphere representation, or Pauli matrix expectation values.

How to use this skill

Skill file

QuTiP: Quantum State Expectation Values from Bloch Sphere

Overview

Given Bloch sphere coordinates (theta, phi), compute the expectation values of the three Pauli matrices (σx, σy, σz).

Creating Quantum State from Bloch Coordinates

from qutip import spin_coherent, expect, sigmax, sigmay, sigmaz
import numpy as np

# Read theta and phi in degrees
theta_deg, phi_deg = map(float, open("/root/input.txt").read().split())
theta = np.radians(theta_deg)  # Convert to radians
phi = np.radians(phi_deg)

# Create quantum state on Bloch sphere
# spin_coherent(s, theta, phi) where s=1/2 for qubit
psi = spin_coherent(1/2, theta, phi)

# Compute expectation values
sx = expect(sigmax(), psi)
sy = expect(sigmay(), psi)
sz = expect(sigmaz(), psi)

# Print results with 3 decimal places
print(f"Sigma X: {sx:+.3f}")
print(f"Sigma Y: {sy:+.3f}")
print(f"Sigma Z: {sz:+.3f}")

Key Functions

spin_coherent(s, theta, phi)

Creates a coherent spin state on the Bloch sphere.

expect(op, state)

Computes expectation value ⟨ψ|O|ψ⟩ of an operator.

Pauli Matrices

sigmax()   # σx
sigmay()   # σy
sigmaz()   # σz

Example: theta=90°, phi=0° (Bloch sphere +X state)

theta = np.radians(90)
phi = np.radians(0)
psi = spin_coherent(1/2, theta, phi)
# Should give: <σx>≈1, <σy>≈0, <σz>≈0

Key Reference

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.