Skip to content

Commit 8b25bb9

Browse files
authored
add doctest to ci; version bump (#458)
* add doctest to ci; version bump * need pip? * avoid doctest errors * GKSwstype
1 parent 3226ee1 commit 8b25bb9

File tree

9 files changed

+85
-87
lines changed

9 files changed

+85
-87
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,26 @@ jobs:
4545
- uses: codecov/codecov-action@v1
4646
with:
4747
file: lcov.info
48+
docs:
49+
name: Documentation
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v2
53+
- uses: julia-actions/setup-julia@v1
54+
with:
55+
version: '1'
56+
- run: pip3 install sympy
57+
- run: |
58+
julia --project=docs -e '
59+
using Pkg
60+
Pkg.develop(PackageSpec(path=pwd()))
61+
Pkg.instantiate()'
62+
- run: |
63+
julia --project=docs -e '
64+
using Documenter: doctest
65+
using SymPy
66+
doctest(SymPy)'
67+
- run: julia --project=docs docs/make.jl
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SymPy"
22
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
3-
version = "1.1.3"
3+
version = "1.1.4"
44

55
[deps]
66
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"

docs/make.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
ENV["PLOTS_TEST"] = "true"
2+
ENV["GKSwstype"] = "100"
3+
4+
15
using Documenter
26
using SymPy
37

@@ -18,7 +22,7 @@ pages = [
1822
"Solvers" => "Tutorial/solvers.md",
1923
"Matrices" => "Tutorial/matrices.md",
2024
"Advanced expression manipulation" => "Tutorial/manipulation.md"
21-
],
25+
],
2226
"Reference/API" => "reference.md"
2327
],
2428
)

docs/src/Tutorial/basic_operations.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@ julia> expr(x => 0)
120120
```jldoctest basicoperations
121121
julia> expr = x^y
122122
y
123-
x
123+
x
124124
125125
julia> expr = expr(y => x^y)
126126
⎛ y⎞
127127
⎝x ⎠
128-
x
128+
x
129129
130130
julia> expr = expr(y => x^x)
131131
⎛ ⎛ x⎞⎞
132132
⎜ ⎝x ⎠⎟
133133
⎝x ⎠
134-
x
134+
x
135135
136136
```
137137

@@ -364,7 +364,7 @@ argument to `evalf`. Let's compute the first 100 digits of `\pi`.
364364

365365
##### In `Julia`:
366366

367-
```jldoctest basicoperations
367+
```julia
368368
julia> PI.evalf(100)
369369
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
370370
```
@@ -414,7 +414,7 @@ user's discretion by setting the `chop` flag to True.
414414

415415
```jldoctest basicoperations
416416
julia> _one = cos(Sym(1))^2 + sin(Sym(1))^2
417-
2 2
417+
2 2
418418
cos (1) + sin (1)
419419
420420
julia> (_one - 1).evalf()
@@ -506,12 +506,12 @@ julia> fn.(a)
506506

507507
!!! note "Technical note"
508508
The `lambdify` function converts a symbolic expression into a `Julia` expression, and then creates a function using `invokelatest` to avoid world age issues.
509-
509+
510510
More performant functions can be produced using the following pattern:
511-
511+
512512
```jldoctest basicoperations
513513
julia> ex = sin(x)^2 + x^2
514-
2 2
514+
2 2
515515
x + sin (x)
516516
517517
julia> body = convert(Expr, ex)
@@ -587,4 +587,3 @@ julia> fn(0)
587587
!!! note "TODO"
588588

589589
Write an advanced numerics section
590-

docs/src/Tutorial/matrices.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ U factor:
811811
julia> prod(diag(out.L)) * prod(diag(out.U))
812812
⎛ 1⎞
813813
x⋅⎜x - ─⎟
814-
⎝ x⎠
814+
⎝ x⎠
815815
```
816816

817817
### RREF
@@ -1129,7 +1129,7 @@ expensive to calculate.
11291129

11301130
* note missing `b` is not needed with `Julia`:
11311131

1132-
```jldoctest matrices
1132+
```julia
11331133
julia> @syms lambda
11341134
(lambda,)
11351135

@@ -1138,13 +1138,12 @@ PurePoly(lambda**4 - 11*lambda**3 + 29*lambda**2 + 35*lambda - 150, lambda, doma
11381138

11391139
julia> factor(p) |> string
11401140
"PurePoly(lambda^4 - 11*lambda^3 + 29*lambda^2 + 35*lambda - 150, lambda, domain='ZZ')"
1141-
11421141
```
11431142

11441143

11451144
As an aside, we can get prettier output by adjusting how `lambda` should print, as follows:
11461145

1147-
```
1146+
```julia
11481147
julia> @syms lambda=>"λ"
11491148
(λ,)
11501149

@@ -1210,7 +1209,7 @@ julia> m = Sym[-2*cosh(q/3) exp(-q) 1; exp(q) -2*cosh(q/3) 1; 1 1 -2*cosh(q/3)]
12101209
3×3 Matrix{Sym}:
12111210
-2*cosh(q/3) exp(-q) 1
12121211
exp(q) -2*cosh(q/3) 1
1213-
1 1 -2*cosh(q/3)
1212+
1 1 -2*cosh(q/3)
12141213
12151214
julia> m.nullspace()
12161215
1-element Vector{Matrix{Sym}}:
@@ -1335,4 +1334,3 @@ SymPy issue tracker [#sympyissues-fn]_ to get detailed help from the community.
13351334
* [#mathematicazero-fn] How mathematica tests zero https://reference.wolfram.com/language/ref/PossibleZeroQ.html
13361335
* [#matlabzero-fn] How matlab tests zero https://www.mathworks.com/help/symbolic/mupad_ref/iszero.html
13371336
* [#sympyissues-fn] https://github.com/sympy/sympy/issues
1338-

docs/src/Tutorial/solvers.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ julia> aug = [A b]
228228
1 1 2 3
229229
230230
julia> linsolve(aug, (x,y,z)) # {(-y - 1, y, 2)};
231-
┌ Warning: `vendor()` is deprecated, use `BLAS.get_config()` and inspect the output instead
232-
│ caller = npyinitialize() at numpy.jl:67
233-
└ @ PyCall ~/.julia/packages/PyCall/L0fLP/src/numpy.jl:67
231+
234232
```
235233

236234
Finally, linear equations are solved in `Julia` with the `\` (backslash) operator:
@@ -740,10 +738,7 @@ julia> dsolve(D(f)(x) - f(x), f(x), ics = Dict(f(0) => a)) |> string
740738
To solve the simple harmonic equation, where two initial conditions are specified, we combine the tuple for each within another tuple:
741739

742740
```jldoctest solvers
743-
julia> ics = Dict(f(0) => 1, D(f)(0) => 2)
744-
Dict{Sym, Int64} with 2 entries:
745-
f(0) => 1
746-
Subs(Derivative(f(x), x), x, 0) => 2
741+
julia> ics = Dict(f(0) => 1, D(f)(0) => 2);
747742
748743
julia> dsolve(D(D(f))(x) - f(x), f(x), ics=ics) |> string
749744
"Eq(f(x), 3*exp(x)/2 - exp(-x)/2)"

docs/src/introduction.md

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ julia> @syms xs[1:5]
6565
(Sym[xs₁, xs₂, xs₃, xs₄, xs₅],)
6666
6767
julia> ys = [Sym("y$i") for i in 1:5]
68-
julia> 5-element Vector{Sym}:
69-
y₁
70-
y₂
71-
y₃
72-
y₄
73-
y₅
7468
5-element Vector{Sym}:
7569
y₁
7670
y₂
@@ -236,18 +230,10 @@ This calling style will be equivalent to the last:
236230
```jldoctest introduction
237231
julia> ex(x=>1, y=>pi)
238232
z + 1 + π
239-
240233
```
241234

242-
A straight call is also possble, where the order of the variables is determined by `free_symbols`:
243-
244-
```jldoctest introduction
245-
julia> ex(1, pi)
246-
x + 1 + π
247-
248-
```
249-
250-
This is useful for expressions of a single variable, but being more explicit through the use of paired values would be recommended.
235+
A straight call is also possble, where the order of the variables is determined by `free_symbols`.
236+
This is useful for expressions of a single variable, but being more explicit through the use of paired values is recommended.
251237

252238
## Conversion from symbolic to numeric
253239

@@ -730,7 +716,7 @@ root. The `roots` function of SymPy does.
730716

731717
The output of calling `roots` will be a dictionary whose keys are the roots and values the multiplicity.
732718

733-
```jldoctest introduction
719+
```julia
734720
julia> roots(p)
735721
Dict{Any, Any} with 7 entries:
736722
-1 => 1
@@ -750,7 +736,7 @@ julia> p = x^5 - x + 1
750736
5
751737
x - x + 1
752738
753-
julia> roots(p)
739+
julia> sympy.roots(p)
754740
Dict{Any, Any}()
755741
756742
```
@@ -927,12 +913,10 @@ julia> exs = [2x+3y-6, 3x-4y-12]
927913
2-element Vector{Sym}:
928914
2⋅x + 3⋅y - 6
929915
3⋅x - 4⋅y - 12
916+
```
930917

931-
julia> d = solve(exs)
932-
Dict{Any, Any} with 2 entries:
933-
x => 60/17
934-
y => -6/17
935-
918+
```jldoctest introduction
919+
julia> d = solve(exs); # Dict(x=>60/17, y=>-6/17)
936920
```
937921

938922

@@ -970,7 +954,7 @@ unknowns. When that is not the case, one can specify the variables to
970954
solve for as a vector. In this example, we find a quadratic polynomial
971955
that approximates $\cos(x)$ near $0$:
972956

973-
```jldoctest introduction
957+
```julia
974958
julia> a,b,c,h = symbols("a,b,c,h", real=true)
975959
(a, b, c, h)
976960

@@ -998,7 +982,7 @@ Dict{Any, Any} with 3 entries:
998982
Again, a dictionary is returned. The polynomial itself can be found by
999983
substituting back in for `a`, `b`, and `c`:
1000984

1001-
```jldoctest introduction
985+
```julia
1002986
julia> quad_approx = p.subs(d); string(quad_approx)
1003987
"x^2*(-cos(h)/h^2 + cos(2*h)/(2*h^2) + 1/(2*h^2)) + x*(2*cos(h)/h - cos(2*h)/(2*h) - 3/(2*h)) + 1"
1004988

@@ -1010,7 +994,7 @@ Finally for `solve`, we show one way to re-express the polynomial $a_2x^2 + a_1x
1010994
as $b_2(x-c)^2 + b_1(x-c) + b_0$ using `solve` (and not, say, an
1011995
expansion theorem.)
1012996

1013-
```jldoctest introduction
997+
```julia
1014998
julia> n = 3
1015999
3
10161000

@@ -1023,13 +1007,9 @@ julia> @syms as[1:3]
10231007
julia> @syms bs[1:3]
10241008
(Sym[bs₁, bs₂, bs₃],)
10251009

1026-
julia> p = sum([as[i+1]*x^i for i in 0:(n-1)])
1027-
2
1028-
2
1010+
julia> p = sum([as[i+1]*x^i for i in 0:(n-1)]);
10291011

1030-
julia> q = sum([bs[i+1]*(x-c)^i for i in 0:(n-1)])
1031-
2
1032-
2
1012+
julia> q = sum([bs[i+1]*(x-c)^i for i in 0:(n-1)]);
10331013

10341014
julia> solve(p-q, bs)
10351015
Dict{Any, Any} with 3 entries:
@@ -1069,7 +1049,7 @@ julia> solve(x ⩵ 1)
10691049

10701050
Here is an alternative way of asking a previous question on a pair of linear equations:
10711051

1072-
```jldoctest introduction
1052+
```julia
10731053
julia> x, y = symbols("x,y", real=true)
10741054
(x, y)
10751055

@@ -1079,13 +1059,6 @@ julia> exs = [2x+3y ⩵ 6, 3x-4y ⩵ 12] ## Using \Equal[tab]
10791059
3x - 4y = 12
10801060

10811061
julia> d = solve(exs)
1082-
/Users/verzani/.julia/conda/3/lib/python3.7/site-packages/sympy/matrices/repmatrix.py:102: SymPyDeprecationWarning:
1083-
1084-
non-Expr objects in a Matrix has been deprecated since SymPy 1.9. Use
1085-
list of lists, TableForm or some other data structure instead. See
1086-
https://github.com/sympy/sympy/issues/21497 for more info.
1087-
1088-
deprecated_since_version="1.9"
10891062
Dict{Any, Any} with 2 entries:
10901063
x => 60/17
10911064
y => -6/17
@@ -1246,15 +1219,15 @@ julia> limit(ex, x => a)
12461219

12471220
In a previous example, we defined `quad_approx`:
12481221

1249-
```jldoctest introduction
1222+
```julia
12501223
julia> quad_approx |> string
12511224
"x^2*(-cos(h)/h^2 + cos(2*h)/(2*h^2) + 1/(2*h^2)) + x*(2*cos(h)/h - cos(2*h)/(2*h) - 3/(2*h)) + 1"
12521225

12531226
```
12541227

12551228
The limit as `h` goes to $0$ gives `1 - x^2/2`, as expected:
12561229

1257-
```jldoctest introduction
1230+
```julia
12581231
julia> limit(quad_approx, h => 0)
12591232
2
12601233
x
@@ -1302,7 +1275,7 @@ f (generic function with 1 method)
13021275

13031276
A numeric attempt might be done along these lines:
13041277

1305-
```jldoctest introduction
1278+
```julia
13061279
julia> hs = [10.0^(-i) for i in 6:16]
13071280
11-element Vector{Float64}:
13081281
1.0e-6
@@ -1763,7 +1736,7 @@ julia> integrate(x^2, (x, 0, 1))
17631736

17641737
Tedious problems, such as those needing multiple integration-by-parts steps can be done easily:
17651738

1766-
```jldoctest introduction
1739+
```julia
17671740
julia> integrate(x^5*sin(x), x)
17681741
5 4 3 2
17691742
- x cos(x) + 5x sin(x) + 20x cos(x) - 60x sin(x) - 120xcos(x) + 120sin(x)
@@ -1776,7 +1749,7 @@ The SymPy tutorial says:
17761749
17771750
The tutorial gives the following example:
17781751

1779-
```jldoctest introduction
1752+
```julia
17801753
julia> ex = (x^4 + x^2*exp(x) - x^2 - 2*x*exp(x) - 2*x - exp(x))*exp(x)/((x - 1)^2*(x + 1)^2*(exp(x) + 1))
17811754
4 2 x 2 x x⎞ x
17821755
⎝x + x - x - 2x- 2x - ℯ ⎠
@@ -1788,7 +1761,7 @@ julia> ex = (x^4 + x^2*exp(x) - x^2 - 2*x*exp(x) - 2*x - exp(x))*exp(x)/((x - 1)
17881761

17891762
With indefinite integral:
17901763

1791-
```jldoctest introduction
1764+
```julia
17921765
julia> integrate(ex, x) |> string
17931766
"log(exp(x) + 1) + exp(x)/(x^2 - 1)"
17941767

@@ -2024,7 +1997,7 @@ julia> M = [1 x; x 1]
20241997
Construction of symbolic matrices can *also* be done through the `Matrix` constructor, which must be qualified. It is passed a vector or row vectors but any symbolic values *must* be converted into `PyObject`s:
20251998

20261999
```jldoctest introduction
2027-
julia> import PyCall: PyObject
2000+
julia> import SymPy.PyCall: PyObject
20282001
20292002
julia> A = sympy.Matrix([[1,PyObject(x)], [PyObject(y), 2]])
20302003
2×2 Matrix{Sym}:

0 commit comments

Comments
 (0)