Skip to content

[unitaryDESIGN] Documentation Improvement for AI Agents#66

Open
ahkatlio wants to merge 17 commits intoharmoniqs:mainfrom
ahkatlio:main
Open

[unitaryDESIGN] Documentation Improvement for AI Agents#66
ahkatlio wants to merge 17 commits intoharmoniqs:mainfrom
ahkatlio:main

Conversation

@ahkatlio
Copy link
Copy Markdown

Closes #61

Summary

Improved documentation across Piccolo.jl's visualization components to be more AI-agent-friendly. The changes ensure AI coding assistants (Copilot, Cursor, Claude, etc.) can effectively help users write visualization code by providing comprehensive docstrings, complete examples, and structured reference documentation.

Changes

1. Enhanced Docstrings with Complete Examples

Added comprehensive docstrings to all visualization functions with:

  • Complete mathematical background and context
  • Detailed parameter descriptions with types and defaults
  • Return type specifications
  • 2-4 runnable examples per function covering different use cases
  • Backend compatibility notes (GLMakie vs CairoMakie)
  • Cross-references to related functions
  • Common pitfall warnings

Functions enhanced:

  • animate_figure - Generic animation with custom update functions
  • animate_name - Progressive trajectory component animation
  • plot_bloch - Bloch sphere visualization with mathematical context
  • animate_bloch - Animated Bloch sphere evolution
  • plot_wigner - Wigner quasi-probability distribution plots
  • animate_wigner - Animated Wigner function evolution

2. Created AI-Friendly Reference Documents

VISUALIZATION_CONTEXT.md

A comprehensive AI-agent reference containing:

  • Overview of visualization architecture
  • Backend selection guide with trade-offs
  • Complete function signatures for all public functions
  • Common usage patterns with working code
  • Four complete workflow examples (gate synthesis, state transfer, multi-level systems, saving plots)
  • Common pitfalls and solutions
  • Type reference and quick reference card

llms.txt

LLMs.txt standard-compliant document with:

  • Concise API reference for all core components
  • Complete visualization function signatures
  • Common workflows with copy-paste examples
  • Key conventions (trajectory components, animation modes, state types)
  • Common issues and solutions
  • Resource links

3. Enhanced Visualization Guide

Updated visualization.jl with:

  • Quick start tip box at the top showing most common patterns
  • Enhanced quantum-specific plots section with better explanations
  • Tip boxes for understanding unitary populations and multi-level systems
  • New comprehensive Animation section covering:
    • Backend requirement warnings
    • Control evolution animation
    • Bloch sphere animation
    • Wigner function animation
    • Custom animations with animate_figure
  • Reference to VISUALIZATION_CONTEXT.md for detailed documentation

Benefits for AI Agents

  1. Complete, runnable examples - AI can directly copy working patterns
  2. Explicit type signatures - Clear parameter expectations reduce errors
  3. Common patterns documented - Shows typical usage flows
  4. Error prevention - Anticipates common mistakes (e.g., CairoMakie animation limitations)
  5. Mathematical context - Background theory helps AI understand function purposes
  6. Structured reference - Single source of truth for visualization API

Files Modified

  • PiccoloMakieExt.jl - Enhanced animation function docstrings
  • PiccoloQuantumToolboxExt.jl - Enhanced quantum visualization docstrings
  • visualization.jl - Added examples and animation section

Files Added

  • VISUALIZATION_CONTEXT.md - Comprehensive AI-friendly API reference
  • llms.txt - Standard AI tool integration document

Testing

  • ✅ All modified files pass syntax validation
  • ✅ No linting errors
  • ✅ Docstring examples follow Julia conventions
  • ✅ Mathematical notation properly formatted with LaTeX
  • ✅ Cross-references use correct syntax

Documentation Standards Applied

All enhanced docstrings include:

  • Clear description of function purpose
  • Mathematical background where relevant
  • Complete argument type signatures
  • Detailed keyword argument descriptions
  • Return type specification
  • Multiple runnable examples with different use cases
  • Cross-references to related functions
  • Notes on common pitfalls and backend limitations

Copy link
Copy Markdown
Member

@jack-champagne jack-champagne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, a few things to fixup to get this ready.

If you haven't yet, try building the docs locally:

./docs/get_docs_utils.sh
julia --project=docs docs/make.jl

a lot of what I said can be cross-referenced there will a build. My review comments should guide you: primarily make sure that the files end up in the right paths that I recommend -- secondarily make sure that the literate examples you give are using similar literate syntax as done elsewhere so that everything renders correctly and is easy to follow/maintain (my comments should help guide here too).

Give me a ping if you have any additional questions

Comment thread docs/literate/guides/visualization.jl Outdated
Comment thread docs/literate/guides/visualization.jl Outdated
Comment thread docs/literate/guides/visualization.jl Outdated
Comment thread docs/literate/guides/visualization.jl Outdated
# For cavity/oscillator systems, plot the Wigner quasi-probability distribution:

#nb # Uncomment if QuantumToolbox is available:
#nb # fig = plot_wigner(traj, 1) # Plot at first timestep
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var should probably be traj_ket instead of traj to get back the wigner plot

Comment thread docs/literate/guides/visualization.jl Outdated
Comment thread docs/literate/guides/visualization.jl Outdated
#nb # lines!(ax, 1:k, fidelities[1:k])
#nb # end
#nb #
#nb # animate_figure(fig, 1:traj.N, update_frame!; fps=30)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as https://github.com/harmoniqs/Piccolo.jl/pull/66/changes#r2813337379. helpful note here - if your code is generating animations, try saving this animations to a file in the docs assets directory like so:

fig = animate_wigner(traj_ket; fps=24, xvec=-4:0.1:4, yvec=-4:0.1:4)
save("<path-new-asset-file>.gif", fig)

and then animation can be included in the plain markdown via an image ref

![Alt Text](assets/<new-asset-file>.gif)

or maybe there is a way using the WGLMakie backend to skip all of that. Either way works as long as the animations display correctly.

Comment thread ext/PiccoloMakieExt.jl
Comment thread ext/PiccoloQuantumToolboxExt.jl
Comment thread DOCUMENTATION_IMPROVEMENTS.md Outdated
Comment thread src/visualizations/CONTEXT.md
@ahkatlio
Copy link
Copy Markdown
Author

Hello, I have changed the files according to your suggestions. Check again, please.

@jack-champagne
Copy link
Copy Markdown
Member

Thanks @ahkatlio - a few comments

you will need to add the following packages to the docs/Project.toml in order for the docs pages to build on your end and these examples to render appropriately.

  • QuantumToolbox
  • GLMakie

Also, changes that you made look great. Still some more lines to uncomment in the docs/literate/guides/visualization.jl literate file:

  • R122
  • R199-200
  • R214 - for this last one you will have to change the trajectory param to traj_ket

I have resolved the other comments that your commit addresses. The other review comments still open are currently unresolved. Let me know if you have any questions!!

@ahkatlio
Copy link
Copy Markdown
Author

Hello @jack-champagne, I have added packages to Project.toml and Uncommented lines in visualization.jl. Please check 🙏

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 19, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@ahkatlio
Copy link
Copy Markdown
Author

hello @jack-champagne, how do I pass all the checks?

@jack-champagne
Copy link
Copy Markdown
Member

it looks like these lines that are still commented out could still be uncommented to get the docs to build and render nicely: #66 (comment). I you want to see the docs, you can look at the job too - https://github.com/harmoniqs/Piccolo.jl/actions/runs/22136909817?pr=66, for this branch it was stored at: https://github.com/harmoniqs/Piccolo.jl/actions/runs/22136909817/artifacts/5565423921

@jack-champagne
Copy link
Copy Markdown
Member

I made this comment accidentally on one of your other pull requests:

The checks don't worry about - just needs to be auto formatted before it gets merged. I think the only thing left outstanding are the comments I left on these two lines (I noted them again in the new diff)

https://github.com/harmoniqs/Piccolo.jl/pull/71/changes#r2862149540
https://github.com/harmoniqs/Piccolo.jl/pull/71/changes#r2862150500

I left some details in this comment from earlier last week (sorry I didn't get back to you sooner!): #66 (comment)

Let me know if you have any questions!

@ahkatlio
Copy link
Copy Markdown
Author

@jack-champagne, Previously, the comments just said "To save animation to file:" or "To save animation to file instead:", but now they explicitly mention "To save animation to file, use CairoMakie with mode=:record:" for both the control evolution and Bloch sphere animation examples. This makes it more obvious that users need to switch backends and use the :record mode parameter, reducing potential confusion about why their animations aren't saving.

@jack-champagne
Copy link
Copy Markdown
Member

Hi @ahkatlio, to pass the Documentation / Documentation (pull_request), you will need either comment out all instances of code that is relying upon GLMakie to do renders, or substitute with CairoMakie (leaving in a commented out GLMakie example if you will is fine.)

Documentation won't build in a headless environment with no glfw + X11 display var as it relies on OpenGL, display output, and a graphics card - which these github runners won't have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[unitaryDESIGN] Documentation Improvement for AI Agents

2 participants