Skip to content

Commit

Permalink
eliminate restriction on pytest
Browse files Browse the repository at this point in the history
add Sybil
  • Loading branch information
dkweiss31 committed Oct 14, 2024
1 parent fbe4dba commit ba15478
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 34 deletions.
23 changes: 23 additions & 0 deletions docs/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np
import qutip
import scqubits
from sybil import Sybil
from sybil.parsers.doctest import DocTestParser
from sybil.parsers.markdown import PythonCodeBlockParser, SkipParser

import floquet


def sybil_setup(namespace): # noqa ARG001
namespace["np"] = np
namespace["scq"] = scqubits
namespace["ft"] = floquet
namespace["qt"] = qutip


# sybil configuration
pytest_collect_file = Sybil(
parsers=[DocTestParser(), PythonCodeBlockParser(), SkipParser()],
patterns=["*.md"],
setup=sybil_setup,
).pytest()
49 changes: 29 additions & 20 deletions docs/examples/transmon.ipynb

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/floquet.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ The **floquet** Python API consists largely of the **floquet_analysis** function
::: floquet.utils.file_io
options:
show_source: false

11 changes: 4 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ Requires Python 3.10+

Before jumping straight into the Floquet analysis, we first need to define our system Hamiltonian and the drive parameters. Here we take the example of a transmon and utilize the scubits library to help define the system Hamiltonian. Note however that the code accepts QuTiP `Qobj` as input for the Hamiltonian.
```python
import numpy as np
import qutip as qt
import scqubits as scq

num_states = 20
qubit_params = {"EJ": 20.0, "EC": 0.2, "ng": 0.25, "ncut": 41}
tmon = scq.Transmon(**qubit_params, truncated_dim=num_states)
Expand All @@ -32,15 +28,15 @@ H1 = hilbert_space.op_in_dressed_eigenbasis(tmon.n_operator)
```
We then also need to specify the drive frequencies we plan to drive at, which correspond to the cavity frequencies
```python
omega_d_linspace = 2.0 * np.pi * np.linspace(7.5, 10.0, 120)
omega_d_values = 2.0 * np.pi * np.linspace(7.5, 10.0, 120)
```
Finally, we specify the induced ac-stark shift that we want the qubit to experience. The dispersive coupling of a qubit to the cavity differs as a function of the cavity frequency. Thus we provide helper functions for normalizing the drive amplitudes so that we scan over the same induced ac-Stark shifts for all given frequencies.
```python
import floquet as ft

state_indices = [0, 1] # get data for ground and first excited states
chi_ac_linspace = 2.0 * np.pi * np.linspace(0.0, 0.1, 59) # 100 MHz ac-Stark shift
chi_to_amp = ft.ChiacToAmp(H0, H1, state_indices, omega_d_linspace)
chi_to_amp = ft.ChiacToAmp(H0, H1, state_indices, omega_d_values)
drive_amplitudes = chi_to_amp.amplitudes_for_omega_d(chi_ac_linspace)
```
We can now pass these derived quantities to `Model` which specifies the model system
Expand All @@ -51,7 +47,8 @@ model = ft.Model(
```
We are now ready to create an instance of the `FloquetAnalysis` class, and run the full Floquet simulation
```python
floquet_analysis = ft.FloquetAnalysis(model, state_indices=state_indices)
options = ft.Options(num_cpus=6)
floquet_analysis = ft.FloquetAnalysis(model, state_indices=state_indices, options=options)
data_vals = floquet_analysis.run()
```
`data_vals` is a dictionary containing all quantities computed during the call to `run()`. This includes the overlap with the "ideal" displaced state, which can be plotted to reveal "scars" in the drive frequency and amplitude space where resonances occur. Additionally we compute the [Blais branch crossing analysis](https://arxiv.org/abs/2402.06615) to understand which states are responsible for ionization. See the tutorial notebook under Examples on the left to see how to plot and visualize these quantities.
Expand Down
5 changes: 2 additions & 3 deletions floquet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ def __init__(
drive_amplitudes = np.array(drive_amplitudes)
if len(drive_amplitudes.shape) == 1:
drive_amplitudes = np.tile(drive_amplitudes, (len(omega_d_values), 1)).T
else:
assert len(drive_amplitudes.shape) == 2
assert drive_amplitudes.shape[1] == len(omega_d_values)
assert len(drive_amplitudes.shape) == 2
assert drive_amplitudes.shape[1] == len(omega_d_values)

self.H0 = H0
self.H1 = H1
Expand Down
15 changes: 12 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dev = [
"ruff",
"codespell",
"pygments",
"pytest>=7.0,<8.0",
"pytest",
"pytest-xdist",
"pymdown-extensions",
"mkdocs",
Expand All @@ -39,7 +39,7 @@ dev = [
"mkdocs-exclude",
"mknotebooks",
"nbconvert==6.5.0",
"sybil>=6",
"sybil[pytest]",
"black", # needed by mkdocstrings to format function signatures
]

Expand All @@ -57,9 +57,13 @@ select = ["F", "E", "W", "C90", "I", "D", "UP", "YTT", "ANN", "BLE", "B", "A", "
"INP", "NPY201", "PIE", "T20", "PYI", "PT", "RSE", "RET", "SLF", "SIM", "INT",
"ARG", "PTH", "PL", "TRY", "FLY", "NPY", "RUF",
]
extend-select = ["D204", "D400", "D404", "D406", "D410"]
ignore = [
"ANN101",
"C901",
"D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107", "D417",
"E741",
"INP001",
"PLC0414",
"PLR0913", "PLR2004",
"T201",
Expand Down Expand Up @@ -105,6 +109,10 @@ help = "clean the code (ruff + codespell)"
cmd = 'echo "\n>>> pytest -n=auto tests" && pytest -n=auto tests'
help = "run the unit tests suite (pytest)"

[tool.taskipy.tasks.doctest]
cmd = 'echo "\n>>> pytest docs" && pytest docs'
help = "check documentation examples (doctest)"

[tool.taskipy.tasks.docbuild]
cmd = 'mkdocs build'
help = "build the documentation website"
Expand All @@ -114,13 +122,14 @@ cmd = 'mkdocs serve'
help = "preview documentation website with hot-reloading"

[tool.taskipy.tasks.all]
cmd = 'task clean && task test'
cmd = 'task clean && task test && task doctest'
help = "run all tasks before a commit (ruff + codespell + pytest + doctest)"

[tool.taskipy.tasks.ci]
cmd = '''echo "\n>>> ruff check" && ruff check &&
echo "\n>>> ruff format --check" && ruff format --check &&
task codespell &&
task test &&
task doctest &&
task docbuild'''
help = "run all the CI checks"

0 comments on commit ba15478

Please sign in to comment.