Skip to content

feat: Add Ising analysis and atomic visualization features (#58 #59)#71

Merged
yhteoh merged 4 commits intoOpenQuantumDesign:uhack_ising_and_visualizationfrom
idriss-hamadi:feature/combined-ising-visualization-58-59
Jun 16, 2025
Merged

feat: Add Ising analysis and atomic visualization features (#58 #59)#71
yhteoh merged 4 commits intoOpenQuantumDesign:uhack_ising_and_visualizationfrom
idriss-hamadi:feature/combined-ising-visualization-58-59

Conversation

@idriss-hamadi
Copy link
Copy Markdown

@idriss-hamadi idriss-hamadi commented Jun 10, 2025

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    issue 58 & 59

  • What is the current behavior? (You can also link to an open issue here)

  • What is the new behavior (if this is a feature change)?

tested to pass ruff tests, same code of the two PRs merged in one PR that was tested locally to pass the ruff tests

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

  • Other information:

closes #58
closes #59

Summary

This PR combines two complementary features for quantum system analysis and visualization:

  1. Ising Hamiltonian Analysis ([IN REVIEW] Check if an analog AnalogGate implements an Ising-like Hamiltonian #59) - Analyzes AnalogGate for Ising-like properties
  2. Atomic Energy Level Visualization ([IN REVIEW] Create a energy level visualization based on an instance of the Atomic objects #58) - Generates Grotrian-like diagrams for Ion instances

Why Combined PR?

These two features are being submitted together because:

  • Shared Infrastructure: Both features modify the same core files (src/oqd_core/__init__.py, src/oqd_core/compiler/analog/passes/__init__.py)
  • Avoid Merge Conflicts: Separating them would create unnecessary merge conflicts and complicate the review process

each feature was submitted in it's PR, this one is combining them, no code change execept for combining and passing ruff tests

Features Added

1. Ising Hamiltonian Analysis (#59)

  • Analyzes AnalogGate instances to determine if they implement Ising-like Hamiltonians
  • Validates three key constraints:
    • Only qubit registers (no bosonic operators)
    • Weight-2 Pauli strings (max two non-identity Paulis per term)
    • Time-independent coefficients
  • Extracts coupling matrices for all Pauli interaction types (XX, YY, ZZ, XY, XZ, YZ)
  • Provides structured error reporting for invalid Hamiltonians
  • Includes comprehensive unit tests (13 test cases covering valid/invalid scenarios)

2. Atomic Energy Level Visualization (#58)

  • Generates Grotrian-like energy level diagrams for Ion instances
  • Groups energy levels by orbital quantum number (s, p, d, f columns)
  • Displays transitions as arrows between levels
  • Highly customizable (colors, fonts, arrow styles, labels, etc.)
  • Handles edge cases (empty ions, no transitions, etc.)
  • Adds matplotlib as a project dependency

Testing Status

  • All pytest tests pass (13/13 Ising analysis tests)
  • Visualization functionality verified via manual testing script
  • All ruff linting issues resolved (import formatting, unused imports, variable naming)
  • No breaking changes to existing functionality

Files Changed

Core Infrastructure:

  • src/oqd_core/__init__.py - Added visualizations module import
  • src/oqd_core/compiler/analog/passes/__init__.py - Added Ising analysis export
  • pyproject.toml - Added matplotlib dependency

Ising Analysis Feature:

  • src/oqd_core/compiler/analog/passes/ising_analysis.py - Main analysis logic
  • src/oqd_core/compiler/analog/passes/ising_types.py - Data structures
  • tests/test_analog/test_ising_analysis.py - Comprehensive test suite

Visualization Feature:

  • src/oqd_core/visualizations/__init__.py - Package initialization
  • src/oqd_core/visualizations/atomic.py - Plotting implementation

Usage Examples

Ising Analysis

from oqd_core.compiler.analog.passes import analyze_ising_gate
from oqd_core.interface.analog import AnalogGate, OperatorKron, PauliX

gate = AnalogGate(hamiltonian=OperatorKron(op1=PauliX(), op2=PauliX()))
result = analyze_ising_gate(gate)
print(f"Is Ising-like: {result.is_ising_like}")
print(f"XX coupling: {result.coupling_matrices.XX}")

Visualization

from oqd_core.visualizations import generate_energy_level_plot
from oqd_core.interface.atomic import Ion, Level, Transition

Create Ion with levels and transitions

ion = Ion(levels=[...], transitions=[...])
fig = generate_energy_level_plot(ion, figure={'figsize': (10, 8)})
fig.show()

some figs of the tests included

image

image

… introduces an analysis pass to check if an AnalogGate implements an Ising-like Hamiltonian. The analysis verifies: - Only qubit registers are used. - Hamiltonian is composed of weight-2 Pauli strings (or weight-1/0). - Coefficients are time-independent. It also extracts coupling matrices (XX, YY, ZZ, XY, XZ, YZ) for valid Ising-like Hamiltonians. Includes unit tests for various valid and invalid cases. Closes OpenQuantumDesign#59
…visualization tool to plot energy level diagrams (Grotrian-like) for Ion instances from the atomic interface. The function generate_energy_level_plot takes an Ion object and produces a matplotlib figure showing its energy levels grouped by orbital quantum number and the transitions between them. Matplotlib has been added as a project dependency. Closes OpenQuantumDesign#58
…t introduces two complementary features for quantum system analysis: 1. Ising Hamiltonian Analysis (OpenQuantumDesign#59):    - Analyzes AnalogGate for Ising-like properties    - Extracts coupling matrices for Pauli interactions (XX, YY, ZZ, XY, XZ, YZ)    - Validates qubit-only, weight-2, time-independent constraints    - Includes comprehensive unit tests  2. Atomic Energy Level Visualization (OpenQuantumDesign#58):    - Generates Grotrian-like diagrams for Ion instances    - Plots energy levels grouped by orbital quantum number    - Shows transitions between energy levels with customizable styling    - Supports various plot customization options  Both features integrate seamlessly with the existing oqd-core infrastructure. Matplotlib dependency added for visualization support.  Closes OpenQuantumDesign#58 OpenQuantumDesign#59
@yhteoh yhteoh changed the base branch from main to uhack_ising_and_visualization June 16, 2025 14:53
@yhteoh yhteoh merged commit c712887 into OpenQuantumDesign:uhack_ising_and_visualization Jun 16, 2025
15 checks passed
@yhteoh yhteoh self-assigned this Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants