Skip to content

Commit

Permalink
Install torch in GitHub actions (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 19, 2024
1 parent c0bc9fd commit c602d43
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ jobs:
- version: '1'
os: ubuntu-latest
arch: x64
env:
JULIA_CONDAPKG_BACKEND: "Null"
JULIA_PYTHONCALL_EXE: "python3"
steps:
- uses: actions/checkout@v4
# Install pytorch
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install pytorch
run: |
pip3 install torch --index-url https://download.pytorch.org/whl/cpu
pip3 install numpy
# Install Julia
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
env:
GKSwstype: nul
DATADEPS_ALWAYS_ACCEPT: true
JULIA_CONDAPKG_BACKEND: "Null"
JULIA_PYTHONCALL_EXE: "python3"
steps:
- uses: actions/checkout@v4
# Install pytorch
Expand All @@ -24,7 +26,8 @@ jobs:
python-version: '3.10'
- name: Install pytorch
run: |
pip3 install torch --index-url https://download.pytorch.org/whl/cpu
pip3 install torch --index-url https://download.pytorch.org/whl/cpu
pip3 install numpy
# Install Julia
- uses: julia-actions/setup-julia@latest
with:
Expand Down
7 changes: 2 additions & 5 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ function _literate_directory(dir)
rm(filename)
end
for filename in _file_list(dir, dir, ".jl")
if endswith(filename, "pytorch.jl")
continue # Skip for now
end
# `include` the file to test it before `#src` lines are removed. It is
# in a testset to isolate local variables between files.
Test.@testset "$(filename)" begin
Expand Down Expand Up @@ -80,14 +77,14 @@ Documenter.makedocs(;
"manual/Flux.md",
"manual/GLM.md",
"manual/Lux.md",
# "manual/PyTorch.md",
"manual/PyTorch.md",
],
"Tutorials" => [
"tutorials/student_enrollment.md",
"tutorials/decision_trees.md",
"tutorials/mnist.md",
"tutorials/mnist_lux.md",
# "tutorials/pytorch.md",
"tutorials/pytorch.md",
"tutorials/gaussian.md",
],
"Developers" => ["developers/design_principles.md"],
Expand Down
17 changes: 13 additions & 4 deletions docs/src/tutorials/pytorch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@
# over how to link Julia to an existing Python environment. For example, if you
# have an existing Python installation (with PyTorch installed), and it is
# available in the current conda environment, set:

ENV["JULIA_CONDAPKG_BACKEND"] = "Current"

#
# ```julia
# ENV["JULIA_CONDAPKG_BACKEND"] = "Current"
# ```
#
# before importing PythonCall.jl. If the Python installation can be found on
# the path and it is not in a conda environment, set:

#
# ```julia
# ENV["JULIA_CONDAPKG_BACKEND"] = "Null"
# ```
#
# If `python` is not on your path, you may additionally need to set
# `JULIA_PYTHONCALL_EXE`, for example, to:
#
# ```julia
# ENV["JULIA_PYTHONCALL_EXE"] = "python3"
# ```

# ## Required packages

Expand Down
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[deps]
AbstractGPs = "99985d1d-32ba-4be9-9821-2ec096f28918"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DecisionTree = "7806a523-6efd-50cb-b5f6-3fa6f1930dbb"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
13 changes: 8 additions & 5 deletions test/test_PythonCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import PythonCall
is_test(x) = startswith(string(x), "test_")

function runtests()
try
PythonCall.pyimport("torch")
catch
@warn("Skipping PythonCall tests because we cannot import PyTorch.")
return
# If we're running the tests locally, allow skipping Python tests
if get(ENV, "CI", "false") == "false"
try
PythonCall.pyimport("torch")
catch
@warn("Skipping PythonCall tests because we cannot import PyTorch.")
return
end
end
@testset "$name" for name in filter(is_test, names(@__MODULE__; all = true))
getfield(@__MODULE__, name)()
Expand Down

2 comments on commit c602d43

@odow
Copy link
Collaborator Author

@odow odow commented on c602d43 Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/117624

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" c602d43f49689560ac37278e39c61775c165a204
git push origin v0.1.0

Please sign in to comment.