Skip to content

Commit 014594b

Browse files
Documentation Template Refactor (#8)
* change matrix to match others * add same building documentation comment on README * use PiccoloDocsTemplate instead of utils.jl * add doctests and docstrings * Update docs.yml --------- Co-authored-by: Gennadi Ryan <[email protected]>
1 parent eb658a2 commit 014594b

File tree

10 files changed

+298
-106
lines changed

10 files changed

+298
-106
lines changed

.github/workflows/CI.yml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
version:
21-
- '1.8'
21+
- '1.10'
22+
- '1.11'
2223
- 'nightly'
2324
os:
2425
- ubuntu-latest
2526
arch:
2627
- x64
27-
- x86
28+
# - x86
2829
steps:
2930
- uses: actions/checkout@v2
3031
- uses: julia-actions/setup-julia@v1
@@ -38,24 +39,5 @@ jobs:
3839
- uses: codecov/codecov-action@v2
3940
with:
4041
files: lcov.info
41-
docs:
42-
name: Documentation
43-
runs-on: ubuntu-latest
44-
permissions:
45-
contents: write
46-
statuses: write
47-
steps:
48-
- uses: actions/checkout@v2
49-
- uses: julia-actions/setup-julia@v1
50-
with:
51-
version: '1'
52-
- uses: julia-actions/julia-buildpkg@v1
53-
- uses: julia-actions/julia-docdeploy@v1
54-
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56-
- run: |
57-
julia --project=docs -e '
58-
using Documenter: DocMeta, doctest
59-
using TrajectoryIndexingUtils
60-
DocMeta.setdocmeta!(TrajectoryIndexingUtils, :DocTestSetup, :(using TrajectoryIndexingUtils); recursive=true)
61-
doctest(TrajectoryIndexingUtils)'
42+
token: ${{ secrets.CODECOV_TOKEN }}
43+
fail_ci_if_error: false

.github/workflows/docs.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Documentation
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
tags: ['*']
8+
concurrency:
9+
# Skip intermediate builds: always.
10+
# Cancel intermediate builds: only if it is a pull request build.
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
13+
jobs:
14+
docs:
15+
name: Documentation
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
statuses: write
20+
env:
21+
DOC_TEMPLATE_VERSION: "v0.2.1" # Change this to the specific tag version you want
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: julia-actions/setup-julia@v2
25+
- uses: julia-actions/cache@v2
26+
- name: Use Documentation Template
27+
run: |
28+
./docs/get_docs_utils.sh ${{ env.DOC_TEMPLATE_VERSION }}
29+
- uses: julia-actions/julia-buildpkg@v1
30+
- uses: julia-actions/julia-docdeploy@v1
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
- name: Upload documentation artifacts
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: documentation-build
37+
path: docs/build/
38+
retention-days: 1
39+
- run: |
40+
julia --project=docs -e '
41+
using Documenter: DocMeta, doctest
42+
using TrajectoryIndexingUtils
43+
DocMeta.setdocmeta!(TrajectoryIndexingUtils, :DocTestSetup, :(using TrajectoryIndexingUtils; Z = collect(1.5:12.5); dim = 3); recursive=true)
44+
doctest(TrajectoryIndexingUtils)'

.gitignore

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ deps/src/
1616
# Build artifacts for creating documentation generated by the Documenter package
1717
docs/build/
1818
docs/site/
19+
docs/clones/
20+
docs/out/
21+
docs/src/generated/
22+
23+
docs/src/assets/
24+
25+
# Build artifact for using README as index (probably shouldn't have this checked into version control)
26+
docs/src/index.md
1927

2028
# File generated by Pkg, the package manager, based on a corresponding Project.toml
2129
# It records a fixed state of all packages used by the project. As such, it should not be
@@ -34,12 +42,16 @@ pardiso.lic
3442
/.CondaPkg/
3543
*.code-workspace
3644

37-
# generated Literate
38-
docs/src/generated/
39-
4045
# generated build folder
4146
build/
4247

4348
# VS code
4449
*.code-workspace
4550
.vscode/settings.json
51+
52+
# doc_template stuff
53+
# Temporary directory for doc_template cloning
54+
doc_template_temp/
55+
56+
# This file is updated via script
57+
docs/utils.jl

README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ With this, the user is still responsible for keeping track of the component indi
3939

4040
## Installation
4141

42-
This package is not yet registered. To install, use the following command:
42+
TrajectoryIndexingUtils.jl is registered! Install in the REPL by entering pkg mode with `]` and then running
4343

4444
```julia
45-
using Pkg
46-
Pkg.add(url="https://github.com/harmoniqs/TrajectoryIndexingUtils.jl", rev="main")
45+
pkg> add TrajectoryIndexingUtils
4746
```
4847

4948
## Methods
@@ -65,10 +64,38 @@ slice(t::Int, indices::AbstractVector{Int}, dim::Int) -> zₜ[indices]
6564
slice(ts::UnitRange{Int}, dim::Int) -> vec(zₜ for t ∈ ts)
6665
```
6766

68-
## TODO
6967

70-
- [ ] Add tests
71-
- [ ] Add examples
72-
- [ ] Add documentation
73-
- [ ] Add methods that take in trajectory vector as the first argument
74-
- [ ] Add `block` function for accessing blocks of matrices with trajectory structure, e.g. jacobians & hessians
68+
### Building Documentation
69+
This package uses a Documenter config that is shared with many of our other repositories. To build the docs, you will need to run the docs setup script to clone and pull down the utility.
70+
```
71+
# first time only
72+
./docs/get_docs_utils.sh # or ./get_docs_utils.sh if cwd is in ./docs/
73+
```
74+
75+
To build the docs pages:
76+
```
77+
julia --project=docs docs/make.jl
78+
```
79+
80+
or editing the docs live:
81+
```
82+
julia --project=docs
83+
> using LiveServer, Piccolo, Revise
84+
> servedocs(skip_files=["docs/src/index.md"])
85+
```
86+
87+
> **Note:** `servedocs` needs to watch a subset of the files in the `docs/` folder. If it watches files that are generated on a docs build/re-build, `servedocs` will continuously try to re-serve the pages.
88+
>
89+
> To prevent this, ensure all generated files are included in the skip dirs or skip files args for `servedocs`.
90+
91+
For example, if we forget index.md like so:
92+
```
93+
julia --project=docs
94+
> using LiveServer, Piccolo, Revise
95+
> servedocs()
96+
```
97+
it will not build and serve.
98+
99+
-----
100+
101+
*"It seems that perfection is attained not when there is nothing more to add, but when there is nothing more to take away." - Antoine de Saint-Exupéry*

docs/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
4+
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
5+
PiccoloDocsTemplate = "a90a139f-c522-4b23-980b-4210ddb8d065"
6+
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
37
TrajectoryIndexingUtils = "6dad8b7f-dd9a-4c28-9b70-85b9a079bfc8"

docs/get_docs_utils.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Get the directory where this script is located
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
PROJECT_ROOT="$SCRIPT_DIR/.."
8+
9+
# if argument is provided, use it as the DOC_TEMPLATE_VERSION
10+
if [[ $# -gt 0 ]]; then
11+
DOC_TEMPLATE_VERSION="$1"
12+
else
13+
WORKFLOW_FILE="$PROJECT_ROOT/.github/workflows/docs.yml"
14+
15+
# Check if workflow file exists
16+
if [[ ! -f "$WORKFLOW_FILE" ]]; then
17+
echo "GitHub workflow file not found at: $WORKFLOW_FILE"
18+
exit 1
19+
fi
20+
21+
DOC_TEMPLATE_VERSION=$(grep -E '^\s*DOC_TEMPLATE_VERSION:' "$WORKFLOW_FILE" | sed -E 's/.*DOC_TEMPLATE_VERSION:\s*"([^"]+)".*/\1/')
22+
fi
23+
24+
if [[ -z "$DOC_TEMPLATE_VERSION" ]]; then
25+
echo "DOC_TEMPLATE_VERSION is not set"
26+
echo "Please provide a version tag as an arg or ensure it is set in $WORKFLOW_FILE"
27+
echo "Could not extract DOC_TEMPLATE_VERSION from $WORKFLOW_FILE"
28+
echo "Expected format: DOC_TEMPLATE_VERSION: \"<version tag here>\""
29+
exit 1
30+
fi
31+
32+
# Clone the repository
33+
echo "Grabbing PiccoloDocsTemplate at version $DOC_TEMPLATE_VERSION"
34+
julia --project="$PROJECT_ROOT/docs" -e "
35+
using Pkg; Pkg.add(url=\"https://github.com/harmoniqs/PiccoloDocsTemplate.jl\", rev=\"$DOC_TEMPLATE_VERSION\")
36+
"
37+
38+
echo "Successfully updated PiccoloDocsTemplate with version $DOC_TEMPLATE_VERSION"

docs/make.jl

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
using TrajectoryIndexingUtils
2-
using Documenter
2+
using PiccoloDocsTemplate
33

4-
DocMeta.setdocmeta!(TrajectoryIndexingUtils, :DocTestSetup, :(using TrajectoryIndexingUtils); recursive=true)
4+
pages=[
5+
"Home" => "index.md",
6+
"Library" => "lib.md",
7+
]
58

6-
makedocs(;
7-
modules=[TrajectoryIndexingUtils],
8-
authors="Aaron Trowbridge <[email protected]> and contributors",
9-
repo="https://github.com/harmoniqs/TrajectoryIndexingUtils.jl/blob/{commit}{path}#{line}",
10-
sitename="TrajectoryIndexingUtils.jl",
11-
format=Documenter.HTML(;
12-
prettyurls=get(ENV, "CI", "false") == "true",
13-
canonical="https://docs.harmoniqs.co/TrajectoryIndexingUtils.jl",
14-
edit_link="main",
15-
assets=String[],
9+
generate_docs(
10+
@__DIR__,
11+
"TrajectoryIndexingUtils",
12+
TrajectoryIndexingUtils,
13+
pages;
14+
make_assets = false,
15+
make_index = true,
16+
make_literate = false,
17+
format_kwargs = (canonical = "https://docs.harmoniqs.co/TrajectoryIndexingUtils.jl",),
18+
doctest_setup_meta_args = Dict(
19+
TrajectoryIndexingUtils => :(using TrajectoryIndexingUtils; Z = collect(1.5:12.5); dim = 3),
1620
),
17-
pages=[
18-
"Home" => "index.md",
19-
],
20-
)
21-
22-
deploydocs(;
23-
repo="github.com/harmoniqs/TrajectoryIndexingUtils.jl",
24-
devbranch="main",
25-
)
21+
)

docs/src/index.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/src/lib.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## TrajectoryIndexingUtils methods
2+
3+
This module contains helper functions for indexing and taking slices of the full problem variable vector
4+
definitions:
5+
6+
* problem vector:
7+
Z = [z₁, z₂, ..., zₜ]
8+
9+
* knot point:
10+
zₜ = [xₜ, uₜ]
11+
12+
* augmented state vector:
13+
xₜ = [ψ̃ₜ, ψ̃²ₜ, ..., ψ̃ⁿₜ, ∫aₜ, aₜ, daₜ, ..., dᶜ⁻¹aₜ]
14+
15+
where c = control_order
16+
17+
also, below, we use `dim(zₜ) = dim`
18+
examples:
19+
```julia
20+
Z[index(t, pos, dim)] = zₜ[pos]
21+
Z[index(t, dim)] = zₜ[dim]
22+
Z[slice(t, pos1, pos2, dim)] = zₜ[pos1:pos2]
23+
Z[slice(t, pos, dim)] = zₜ[1:pos]
24+
Z[slice(t, dim)] = zₜ[1:dim] := zₜ
25+
Z[slice(t, dim; stretch=stretch)] = zₜ[1:(dim + stretch)]
26+
Z[slice(t, indices, dim)] = zₜ[indices]
27+
Z[slice(t1:t2, dim)] = [zₜ₁;...;zₜ₂]
28+
```
29+
30+
The functions are also used to access the zₜ vectors, e.g.
31+
```julia
32+
zₜ[slice(i, isodim)] = ψ̃ⁱₜ
33+
zₜ[n_wfn_states .+ slice(1, ncontrols)] = ∫aₜ
34+
zₜ[n_wfn_states .+ slice(2, ncontrols)] = aₜ
35+
zₜ[n_wfn_states .+ slice(augdim + 1, ncontrols)] = uₜ = ddaₜ
36+
```
37+
38+
Examples below are run with:
39+
```julia
40+
using TrajectoryIndexingUtils
41+
Z = collect(1.5:12.5) # Example vector as Float64
42+
dim = 3 # Example dimension
43+
```
44+
45+
## API
46+
47+
```@autodocs
48+
Modules = [TrajectoryIndexingUtils]
49+
```

0 commit comments

Comments
 (0)