Skip to main content

Simple module allowing to record animations to trace changes in qubit states for arbitrary quantum circuits.

Project description

release GitHub Release Libraries.io dependency status for GitHub repo


qiskit-state-evolution-recorder

Simple module allowing to record animations to trace changes in qubit states for arbitrary quantum circuits.

Installation

pip install qiskit-state-evolution-recorder

Usage

from qiskit.circuit import QuantumCircuit
from qiskit_state_evolution_recorder import StateEvolutionRecorder

qc = QuantumCircuit(4)
# apply Pauli X-gate
qc.x(3)
# apply Hadamart gate
qc.h(range(4))
# apply Toffoli gate
qc.mcx(list(range(3)), 3)
# apply Hadamart gate
qc.h(range(4))
qc.measure_all()

recorder = StateEvolutionRecorder(qc, figsize=(12, 8), num_cols=4, style={'name': 'bw'})
# evolve the circuit using 120 intermediate states for each qubit
# since we have 5 fundamental states it will lead to 481 frames
recorder.evolve(120)
# with FPS of 30, the video duration will be 16.033333s
recorder.record("quantum_circuit.mp4", fps=30)

In a Jupyter notebook, you can do:

from IPython.display import Video

video = Video("quantum_circuit.mp4")
video.reload()
video

https://github.com/user-attachments/assets/8a3c8567-cbb8-4271-9c2c-9588130c01b0

Testing

Running Tests

The project includes both unit tests and performance tests. Performance tests are marked with the @pytest.mark.performance decorator and can be run optionally.

# Run all tests except performance tests
python -m pytest -m "not performance"

# Run all tests including performance tests
python -m pytest

# Run only performance tests
python -m pytest -m "performance"

# Run specific test file
python -m pytest tests/test_state_evolution.py

# Run with verbose output
python -m pytest -v

Backend Support

The library supports multiple animation backends:

  • FFmpeg (default, preferred): Uses matplotlib's FuncAnimation with FFmpeg
  • OpenCV: Uses OpenCV for video creation (fallback when FFmpeg is not available)

The system automatically selects the best available backend. To install additional backends:

# Install OpenCV backend
pip install opencv-python

# Install FFmpeg (system-dependent)
# Ubuntu/Debian: sudo apt-get install ffmpeg
# macOS: brew install ffmpeg
# Windows: Download from https://ffmpeg.org/download.html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qiskit_state_evolution_recorder-1.0.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qiskit_state_evolution_recorder-1.0.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file qiskit_state_evolution_recorder-1.0.0.tar.gz.

File metadata

File hashes

Hashes for qiskit_state_evolution_recorder-1.0.0.tar.gz
Algorithm Hash digest
SHA256 91b4745f4a7876cfe0079f7270b389cbedcc06ab00c9416d3571d0291e7a012d
MD5 fcb87dc02bcadd0a9d4f7e251f5dd167
BLAKE2b-256 7e3115bc07dcacb2146d05247d8ee565bdf7733eeec2f997190d644048223c96

See more details on using hashes here.

File details

Details for the file qiskit_state_evolution_recorder-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for qiskit_state_evolution_recorder-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d4c2181a0a0607bf75a22a9546f4da311fd12ea6f40bc2f87ea7aa07b073d3e
MD5 14d39afe787accbe6f5004fdb1e2cf50
BLAKE2b-256 0c045b3d5a07d4ed4f3ca502ec42c72c57c8836999673fe9a687c562d8849a60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page