Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlambert committed Jan 31, 2025
2 parents 5241f84 + 0d87e07 commit 1f676a7
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 17 deletions.
31 changes: 23 additions & 8 deletions .github/workflows/nightly_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,28 @@ jobs:
- qutip-version: '5'
qutip-branch: 'master'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: 'yes'
folder-path: tutorials-v${{ matrix.qutip-version }}
#use config file to define 403 and 405 errors as valid links
#use config file to define 403 and 405 errors as valid links
#(APS blocks this link check)
config-file: mlc_config.json

- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
- name: Setup Conda
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: test-environment-v${{ matrix.qutip-version }}
use-mamba: true

- name: Get Date
id: get-date
run: echo "::set-output name=today::$(/bin/date -u '+%Y%m%d')"
shell: bash

- name: Cache Conda env
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs
key: conda-${{ runner.os }}--${{ runner.arch }}--${{ steps.get-date.outputs.today }}-${{ hashFiles('test_environment.yml') }}-${{ env.CACHE_NUMBER }}-qutip-${{ matrix.qutip-version }}
Expand All @@ -54,7 +52,7 @@ jobs:

- name: Install environment
if: steps.cache.outputs.cache-hit != 'true'
run: mamba env update -n test-environment-v${{ matrix.qutip-version }} -f test_environment-v${{ matrix.qutip-version }}.yml
run: conda env update -n test-environment-v${{ matrix.qutip-version }} -f test_environment-v${{ matrix.qutip-version }}.yml

- name: Install QuTiP
run: |
Expand Down Expand Up @@ -107,3 +105,20 @@ jobs:
path: |
notebooks/*.ipynb
notebooks/**/*.ipynb
finalise:
needs: pytests
if: failure()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Open Issue on Failure
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
if [[ -z "${{ inputs.open_issue }}" ]] || [[ "${{ inputs.open_issue }}" != "False" ]];
then
pip install requests
python tools/report_failing_tests.py $GITHUB_TOKEN
fi
16 changes: 7 additions & 9 deletions .github/workflows/notebook_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,29 @@ jobs:
- qutip-version: '5'
qutip-branch: 'master'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: 'yes'
folder-path: tutorials-v${{ matrix.qutip-version }}
#use config file to define 403 and 405 errors as valid links
#use config file to define 403 and 405 errors as valid links
#(APS blocks this link check)
config-file: mlc_config.json

- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
- name: Setup Conda
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: test-environment-v${{ matrix.qutip-version }}
use-mamba: true

- name: Get Date
id: get-date
run: echo "::set-output name=today::$(/bin/date -u '+%Y%m%d')"
shell: bash

- name: Cache Conda env
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs
key: conda-${{ runner.os }}--${{ runner.arch }}--${{ steps.get-date.outputs.today }}-${{ hashFiles('test_environment.yml') }}-${{ env.CACHE_NUMBER }}-qutip-${{ matrix.qutip-version }}
Expand All @@ -56,7 +54,7 @@ jobs:

- name: Install environment
if: steps.cache.outputs.cache-hit != 'true'
run: mamba env update -n test-environment-v${{ matrix.qutip-version }} -f test_environment-v${{ matrix.qutip-version }}.yml
run: conda env update -n test-environment-v${{ matrix.qutip-version }} -f test_environment-v${{ matrix.qutip-version }}.yml

- name: Install QuTiP
run: |
Expand Down Expand Up @@ -114,7 +112,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.repository == 'qutip/qutip-tutorials' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: executed-notebooks-v4
Expand Down
46 changes: 46 additions & 0 deletions tools/report_failing_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import requests
import json
import sys
import argparse
from datetime import date

def open_issue(token):
url = "https://api.github.com/repos/qutip/qutip-jax/issues"
data = json.dumps({
"title": f"Automated tests failed on {date.today()}",
"labels": ["bug"],
"body": "Scheduled test failed!"
})

headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization" : f"token {token}",
}

post_request = requests.post(url=url, data=data, headers=headers)

if post_request.status_code == 201:
print("Success")

else:
print(
"Fail:",
post_request.status_code,
post_request.reason,
post_request.content
)


def main():
parser = argparse.ArgumentParser(
description="""Open an issue on failed tests."""
)
parser.add_argument("token")
args = parser.parse_args()
print(args.token)
open_issue(args.token)


if __name__ == "__main__":
sys.exit(main())
68 changes: 68 additions & 0 deletions tutorials-v5/visualization/distributions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: markdown
format_version: '1.3'
jupytext_version: 1.13.8
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---

# Using qutip.distributions

Author: Mathis Beaudoin (2025)

### Introduction

This notebook shows how to use probability distributions inside QuTiP. We begin by importing the necessary packages.

```python
from qutip import fock, about
from qutip.distributions import HarmonicOscillatorWaveFunction
from qutip.distributions import HarmonicOscillatorProbabilityFunction
import matplotlib.pyplot as plt
```

### Harmonic Oscillator Wave Function

Here, we display the spatial distribution of the wave function for the harmonic oscillator (n=0 to n=7) with the `HarmonicOscillatorWaveFunction()` class.

Optionally, define a range of values for each coordinate with the parameter called `extent`. Also, define a number of data points inside the given range with the optional parameter called `steps`. From this information, the distribution is generated and can be visualized with the `.visualize()` method.

```python
M = 8
N = 20

fig, ax = plt.subplots(M, 1, figsize=(10, 12), sharex=True)

for n in range(M):
psi = fock(N, n)
wf = HarmonicOscillatorWaveFunction(psi, 1.0, extent=[-10, 10])
wf.visualize(fig=fig, ax=ax[M-n-1], show_ylabel=False, show_xlabel=(n == 0))
```

### Harmonic Oscillator Probability Function

The class `HarmonicOscillatorProbabilityFunction()` is the squared magnitude of the data that would normally be in `HarmonicOscillatorWaveFunction()`. We use the same example as before.

```python
M = 8
N = 20

fig, ax = plt.subplots(M, 1, figsize=(10, 12), sharex=True)

for n in range(M):
psi = fock(N, n)
wf = HarmonicOscillatorProbabilityFunction(psi, 1.0, extent=[-10, 10])
wf.visualize(fig=fig, ax=ax[M-n-1], show_ylabel=False, show_xlabel=(n == 0))
```

### About

```python
about()
```

0 comments on commit 1f676a7

Please sign in to comment.