Skip to content

Commit

Permalink
Merge pull request #118 from ytdHuang/ci/format-check
Browse files Browse the repository at this point in the history
Introduce CI FormatCheck
  • Loading branch information
ytdHuang authored May 22, 2024
2 parents def87cd + bddc96f commit f0a6e1c
Show file tree
Hide file tree
Showing 41 changed files with 184 additions and 162 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ always_use_return=true
format_docstrings=true
indent_submodule=true
format_markdown=true
ignore = ["README.md"]
44 changes: 44 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Format Check
on:
push:
branches:
- 'main'
tags:
- '*'
pull_request:
branches:
- 'main'
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
build:
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- name: Install and Run JuliaFormatter
run: |
julia -e 'import Pkg; Pkg.add("JuliaFormatter")'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format Check
run: |
julia -e '
output = Cmd(`git diff --name-only`) |> read |> String
if output == ""
exit(0)
else
@error "The following files have not been formatted !!!"
write(stdout, output)
write(stdout, "-----\n")
write(stdout, "Please format them by running the following command:\n")
write(stdout, "julia -e \"using JuliaFormatter; format(\\\".\\\")\"")
exit(1)
end'
31 changes: 0 additions & 31 deletions .github/workflows/JuliaFormatter.yml

This file was deleted.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

[![Release](https://img.shields.io/github/release/albertomercurio/QuantumToolbox.jl.svg)](https://github.com/albertomercurio/QuantumToolbox.jl/releases)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.11096277.svg)](https://doi.org/10.5281/zenodo.11096277)
[![Downloads](https://img.shields.io/badge/dynamic/json?url=http%3A%2F%2Fjuliapkgstats.com%2Fapi%2Fv1%2Fmonthly_downloads%2FQuantumToolbox&query=total_requests&suffix=%2Fmonth&label=Downloads)](https://juliapkgstats.com/pkg/QuantumToolbox)

[![Downloads](https://img.shields.io/badge/dynamic/json?url=http%3A%2F%2Fjuliapkgstats.com%2Fapi%2Fv1%2Fmonthly_downloads%2FQuantumToolbox&query=total_requests&suffix=%2Fmonth&label=Downloads)](https://juliapkgstats.com/pkg/QuantumToolbox)
[![Build Status](https://github.com/albertomercurio/QuantumToolbox.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/albertomercurio/QuantumToolbox.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
[![Coverage](https://codecov.io/gh/albertomercurio/QuantumToolbox.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/albertomercurio/QuantumToolbox.jl)

[![Coverage](https://codecov.io/gh/albertomercurio/QuantumToolbox.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/albertomercurio/QuantumToolbox.jl)
[![Doc-Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://albertomercurio.github.io/QuantumToolbox.jl/stable)
[![Doc-Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://albertomercurio.github.io/QuantumToolbox.jl/dev)

## Introduction

[QuantumToolbox.jl](https://github.com/albertomercurio/QuantumToolbox.jl) is a cutting-edge Julia package designed for quantum physics simulations, closely emulating the popular Python [QuTiP](https://github.com/qutip/qutip) package. It uniquely combines the simplicity and power of Julia with advanced features like GPU acceleration and distributed computing, making simulation of quantum systems more accessible and efficient.

## Features

QuantumToolbox.jl is equipped with a robust set of features:

- **Quantum State and Operator Manipulation:** Easily handle quantum states and operators with a rich set of tools.
Expand All @@ -27,6 +27,7 @@ QuantumToolbox.jl is equipped with a robust set of features:
- **GPU and Distributed Computing:** Leverage GPU and distributed resources for high-performance computing.

## Installation

```julia
using Pkg
Pkg.add("QuantumToolbox")
Expand Down
6 changes: 5 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ steadystate_floquet
```

## [Correlations and Spectrum](@id API: Correlations and Spectrum)

```@docs
correlation_3op_2t
correlation_2op_2t
Expand All @@ -118,6 +119,7 @@ spectrum
```

## [Eigenvalues and eigenvectors](@id API: Eigenvalues and eigenvectors)

```@docs
EigsolveResult
eigenenergies
Expand All @@ -129,6 +131,7 @@ eigsolve_al
```

## [Low Rank internal APIs](@id API: Low Rank internal APIs)

```@docs
_calculate_expectation!
_adjM_condition_variational
Expand All @@ -139,7 +142,8 @@ dBdz!
```

## [Miscellaneous](@id API: Miscellaneous)

```@docs
QuantumToolbox.versioninfo
QuantumToolbox.about
```
```
2 changes: 1 addition & 1 deletion docs/src/benchmarks/benchmark_history.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
window.addEventListener('message', adjustIframeHeight, false);
</script>
```
```
38 changes: 18 additions & 20 deletions docs/src/tutorials/logo.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ A cat state, often referred to as a Schrödinger cat state, is a quantum state t

where ``| \alpha \rangle`` is a coherent state with amplitude ``\alpha``.

The triangular cat state is a generalization of the standard cat state. It is a superposition of three coherent states with phases ``\theta_0, \theta_1, \theta_2 ``separated by ``120^\circ ``(or ``2\pi/3 ``radians):
The triangular cat state is a generalization of the standard cat state. It is a superposition of three coherent states with phases ``\theta_0, \theta_1, \theta_2``separated by ``120^\circ``(or ``2\pi/3``radians):

```math
| \psi_{\text{tri-cat}} \rangle = \frac{1}{\sqrt{3}} \left( | \alpha_0 \rangle + | \alpha_1 \rangle + | \alpha_2 \rangle \right)
```

where ``\alpha_j = \rho e^{i\theta_j} ``with ``\theta_j = \frac{\pi}{2} + \frac{2\pi j}{3} ``and ``j = 0, 1, 2 ``.
where ``\alpha_j = \rho e^{i\theta_j}``with ``\theta_j = \frac{\pi}{2} + \frac{2\pi j}{3}``and ``j = 0, 1, 2``.

### Wigner Function

The Wigner function ``W(x, p) ``is a quasi-probability distribution used in quantum mechanics to represent quantum states in phase space. It is defined as:
The Wigner function ``W(x, p)``is a quasi-probability distribution used in quantum mechanics to represent quantum states in phase space. It is defined as:

```math
W(x, p) = \frac{1}{\pi \hbar} \int_{-\infty}^{\infty} \psi^*(x + y) \psi(x - y) e^{2ipy / \hbar} \, dy
```

where ``\psi(x) ``is the wave function of the quantum state, ``x ``is the position, ``p ``is the momentum, and ``\hbar ``is the reduced Planck constant. Unlike classical probability distributions, the Wigner function can take negative values, which indicates non-classical behavior.
where ``\psi(x)``is the wave function of the quantum state, ``x``is the position, ``p``is the momentum, and ``\hbar``is the reduced Planck constant. Unlike classical probability distributions, the Wigner function can take negative values, which indicates non-classical behavior.

## Generating the Logo

Expand All @@ -50,9 +50,9 @@ Here we define the parameters for the triangular cat state:
```@example logo
N = 30 # Cutoff of the Hilbert space for the harmonic oscillator
ρ = 2.5 # Amplitude of the coherent state
θ1 = π/2
θ2 = π/2 + 2π/3
θ3 = π/2 + 4π/3
θ1 = π / 2
θ2 = π / 2 + 2π / 3
θ3 = π / 2 + 4π / 3
α1 = ρ * exp(im * θ1)
α2 = ρ * exp(im * θ2)
α3 = ρ * exp(im * θ3)
Expand All @@ -75,7 +75,7 @@ We define the grid for the Wigner function and calculate it using the [`wigner`]
xvec = range(-ρ, ρ, 500) .* 1.5
yvec = xvec .+ (abs(imag(α1)) - abs(imag(α2))) / 2
wig = wigner(ψ, xvec, yvec, g=2)
wig = wigner(ψ, xvec, yvec, g = 2)
```

### Plotting the Wigner function
Expand All @@ -100,7 +100,7 @@ The figure obtained above coulb be already a potential logo for the package. How
\frac{d \hat{\rho}}{dt} = -i [\hat{H}, \hat{\rho}] + \gamma \left( 2 \hat{a} \hat{\rho} \hat{a}^\dagger - \hat{a}^\dagger \hat{a} \hat{\rho} - \hat{\rho} \hat{a}^\dagger \hat{a} \right)
```

where ``\hat{\rho}`` is the density matrix, ``\hat{H} = \omega \hat{a}^\dagger \hat{a} ``is the Hamiltonian of the harmonic oscillator (``\hbar = 1``), ``\hat{a} ``and ``\hat{a}^\dagger ``are the annihilation and creation operators, and ``\gamma ``is the damping rate. Thus, we initialize the system in the triangular cat state and evolve it under the Lindblad master equation, using the [`mesolve`](@ref) function.
where ``\hat{\rho}`` is the density matrix, ``\hat{H} = \omega \hat{a}^\dagger \hat{a}``is the Hamiltonian of the harmonic oscillator (``\hbar = 1``), ``\hat{a}``and ``\hat{a}^\dagger``are the annihilation and creation operators, and ``\gamma``is the damping rate. Thus, we initialize the system in the triangular cat state and evolve it under the Lindblad master equation, using the [`mesolve`](@ref) function.

```@example logo
γ = 0.012
Expand All @@ -111,19 +111,19 @@ c_ops = [sqrt(γ) * a]
tlist = range(0, 2π, 100)
sol = mesolve(H, ψ, tlist, c_ops, progress_bar=false)
sol = mesolve(H, ψ, tlist, c_ops, progress_bar = false)
nothing # hide
```

And the Wigner function becomes more uniform:

```@example logo
wig = wigner(sol.states[end], xvec, yvec, g=2)
wig = wigner(sol.states[end], xvec, yvec, g = 2)
fig = Figure(size=(500, 500), figure_padding=0)
fig = Figure(size = (500, 500), figure_padding = 0)
ax = Axis(fig[1, 1])
img_wig = heatmap!(ax, xvec, yvec, wig', colormap=:RdBu, interpolate=true, rasterize=2)
img_wig = heatmap!(ax, xvec, yvec, wig', colormap = :RdBu, interpolate = true, rasterize = 2)
hidespines!(ax)
hidexdecorations!(ax)
hideydecorations!(ax)
Expand All @@ -138,8 +138,7 @@ At this stage, we have finished to use the `QuantumToolbox` package. From now on
We define a custom colormap that changes depending on the Wigner function and spatial coordinates. Indeed, we want the three different colormaps, in the regions corresponding to the three coherent states, to match the colors of the Julia logo. We also want the colormap change to be smooth, so we use a Gaussian function to blend the colors. We introduce also a Wigner function dependent transparency to make the logo more appealing.

```@example logo
function set_color_julia(x, y, wig::T, α1, α2, α3, cmap1, cmap2, cmap3, δ) where T
function set_color_julia(x, y, wig::T, α1, α2, α3, cmap1, cmap2, cmap3, δ) where {T}
amp1 = gaussian(x, real(α1), δ) * gaussian(y, imag(α1), δ)
amp2 = gaussian(x, real(α2), δ) * gaussian(y, imag(α2), δ)
amp3 = gaussian(x, real(α3), δ) * gaussian(y, imag(α3), δ)
Expand All @@ -149,13 +148,12 @@ function set_color_julia(x, y, wig::T, α1, α2, α3, cmap1, cmap2, cmap3, δ) w
c3 = get(cmap3, wig)
c_tot = (amp1 * c1 + amp2 * c2 + amp3 * c3) / (amp1 + amp2 + amp3)
wig_abs = abs( 2 * (wig - 1/2) )
wig_abs = abs(2 * (wig - 1 / 2))
# We introduce some non-linearity to increase the contrast
alpha = 2 * ( 1 / (1 + exp(-5 * wig_abs)) - 1/2 )
alpha = 2 * (1 / (1 + exp(-5 * wig_abs)) - 1 / 2)
return RGBAf(c_tot.r, c_tot.g, c_tot.b, alpha)
end
X, Y = meshgrid(xvec, yvec)
Expand Down Expand Up @@ -210,4 +208,4 @@ fig

## Conclusion

This tutorial demonstrates how to generate the [QuantumToolbox.jl](https://github.com/albertomercurio/QuantumToolbox.jl) logo using the package itself and [Makie.jl](https://github.com/MakieOrg/Makie.jl) for visualization. The logo is a visualization of the Wigner function of a triangular cat state, with a custom colormap that highlights the different coherent states with colors matching the Julia logo.
This tutorial demonstrates how to generate the [QuantumToolbox.jl](https://github.com/albertomercurio/QuantumToolbox.jl) logo using the package itself and [Makie.jl](https://github.com/MakieOrg/Makie.jl) for visualization. The logo is a visualization of the Wigner function of a triangular cat state, with a custom colormap that highlights the different coherent states with colors matching the Julia logo.
Loading

0 comments on commit f0a6e1c

Please sign in to comment.