Skip to content

Commit

Permalink
Merge pull request #118 from tylerjthomas9/master
Browse files Browse the repository at this point in the history
Libstdcxx patch, remove load_boston examples
  • Loading branch information
cstjean authored Dec 21, 2022
2 parents 69608df + 3c0eb17 commit 55ee9e6
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 92 deletions.
38 changes: 8 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,12 @@ jobs:
julia-arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}
- name: Cache artifacts
uses: actions/cache@v2
env:
cache-name: cache-artifacts
with:
path: |
~/.julia/artifacts
~/.julia/registries
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v1 # https://github.com/julia-actions/cache
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/[email protected]
Expand All @@ -57,23 +45,13 @@ jobs:
Documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: 1
- name: Cache artifacts
uses: actions/cache@v2
env:
cache-name: cache-artifacts
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
path: |
~/.julia/artifacts
~/.julia/registries
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/docs/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
version: 1.6
arch: x64
- uses: julia-actions/cache@v1 # https://github.com/julia-actions/cache
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-docdeploy@releases/v1
env:
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ScikitLearn"
uuid = "3646fa90-6ef7-5e7e-9f22-8aca16db6324"
version = "0.6.5"
version = "0.6.6"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand All @@ -21,12 +21,12 @@ VersionParsing = "81def892-9a0e-5fdd-b105-ffc91e053289"

[compat]
Compat = "2.2, 3, 4"
Conda = "1.5.2"
Conda = "1.5.2, 1.6, 1.7"
DataFrames = "0.20, 0.21, 0.22, 1"
IterTools = "1.2, 1.3"
MacroTools = "0.5"
Parameters = "0.12"
PyCall = "1.92"
PyCall = "1.92, 1.93, 1.94"
ScikitLearnBase = "0.5"
StatsBase = "0.33"
VersionParsing = "1.2"
Expand Down
8 changes: 4 additions & 4 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
DataFrames = "0.21"
DataFrames = "1"
Documenter = "0.24"
GaussianMixtures = "0.3"
GaussianProcesses = "0.12"
JLD = "0.9, 0.10"
PyCall = "1.91"
PyCall = "1.92"
PyCallJLD = "0.2"
PyPlot = "2.9"
RDatasets = "0.6"
PyPlot = ">=2.9"
RDatasets = ">=0.6"
10 changes: 1 addition & 9 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
using Conda
if Base.VERSION <= v"1.6.2"
# GLIBCXX_3.4.26
Conda.add("libstdcxx-ng>=3.4,<9.2", channel="conda-forge")
else
# GLIBCXX_3.4.29
# checked up to v1.8.0
Conda.add("libstdcxx-ng>=3.4,<11.4", channel="conda-forge")
end

using Pkg
using Documenter
using ScikitLearn
ScikitLearn.Skcore.import_sklearn() #preinstalls scikit-learn
using PyPlot #pre-installs matplotlib
import PyCall
PyCall.pyimport_conda("sklearn", "scikit-learn") #preinstalls scikit-learn


pages = [
Expand Down
26 changes: 18 additions & 8 deletions examples/Cross_Validated_Predictions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,26 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mFailed to start the Kernel. \n",
"\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
]
}
],
"source": [
"using ScikitLearn\n",
"using ScikitLearn.CrossValidation: cross_val_predict\n",
"\n",
"@sk_import datasets: load_boston\n",
"@sk_import datasets: fetch_california_housing\n",
"@sk_import linear_model: LinearRegression\n",
"using PyPlot"
]
Expand All @@ -57,12 +67,12 @@
],
"source": [
"lr = LinearRegression()\n",
"boston = load_boston()\n",
"y = boston[\"target\"]\n",
"data = fetch_california_housing()\n",
"y = data[\"target\"]\n",
"\n",
"# cross_val_predict returns an array of the same size as `y` where each entry\n",
"# is a prediction obtained by cross validated:\n",
"predicted = cross_val_predict(lr, boston[\"data\"], y, cv=10)\n",
"predicted = cross_val_predict(lr, data[\"data\"], y, cv=10)\n",
"\n",
"scatter(y, predicted)\n",
"plot([minimum(y), maximum(y)], [minimum(y), maximum(y)], \"k--\", lw=4)\n",
Expand All @@ -73,9 +83,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.4.5",
"display_name": "Julia 1.7.3",
"language": "julia",
"name": "julia-0.4"
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
Expand Down
121 changes: 84 additions & 37 deletions src/Skcore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,56 +115,103 @@ symbols_in(e::Expr) = union(symbols_in(e.head), map(symbols_in, e.args)...)
symbols_in(e::Symbol) = Set([e])
symbols_in(::Any) = Set()

# https://github.com/cjdoris/CondaPkg.jl/blob/main/src/resolve.jl#L77
const _compatible_libstdcxx_ng_versions = [
(v"3.4.31", ">=3.4,<=13.1"),
(v"3.4.30", ">=3.4,<13.0"),
(v"3.4.29", ">=3.4,<12.0"),
(v"3.4.28", ">=3.4,<11.0"),
(v"3.4.27", ">=3.4,<9.3"),
(v"3.4.26", ">=3.4,<9.2"),
(v"3.4.25", ">=3.4,<9.0"),
(v"3.4.24", ">=3.4,<8.0"),
(v"3.4.23", ">=3.4,<7.2"),
(v"3.4.22", ">=3.4,<7.0"),
(v"3.4.21", ">=3.4,<6.0"),
(v"3.4.20", ">=3.4,<5.0"),
(v"3.4.19", ">=3.4,<4.9"),
]

"""
_compatible_libstdcxx_ng_version()
Version of libstdcxx-ng compatible with the libstdc++ loaded into Julia.
Specifying the package "libstdcxx-ng" with version "<=julia" will replace the version with
this one. This should be used by anything which embeds Python into the Julia process - for
instance it is used by PythonCall.
"""
function _compatible_libstdcxx_ng_version()
if !Sys.islinux()
return
end
# bound = get(ENV, "JULIA_CONDAPKG_LIBSTDCXX_VERSION_BOUND", "")
# if bound != ""
# return bound
# end
loaded_libstdcxx_version = Base.BinaryPlatforms.detect_libstdcxx_version()
if loaded_libstdcxx_version === nothing
return
end
for (version, bound) in _compatible_libstdcxx_ng_versions
if loaded_libstdcxx_version version
return bound
end
end
return "" # no bound for unknown libstcxx versions
end

mkl_checked= false #neccessary for hack
libstdcxx_solved = false # skip libstdcxx install if it was already done
function import_sklearn()
global mkl_checked
global libstdcxx_solved

@static if Sys.isapple()
mod = try
#
if PyCall.conda && !mkl_checked
try
# check for existence of mkl-service.
# Numpy, sklearn, etc. requires either `mkl` or `no-mkl` service to run
# By default Conda comes with mkl
# For this package to run on MacOS the `no-mkl` versions of Numpy, sklearn is needed
pyimport("mkl")
if PyCall.conda && !mkl_checked
try
# check for existence of mkl-service.
# Numpy, sklearn, etc. requires either `mkl` or `no-mkl` service to run
# By default Conda comes with mkl
# For this package to run on MacOS the `no-mkl` versions of Numpy, sklearn is needed
pyimport("mkl")

#following Code runs only if mkl-service exists otherwise jumps to catch branch
@info "Installing non-mkl versions of sci-kit learn via Conda"
#use non-mkl versions of python packages when ENV["PYTHON"]="Conda" or "" is used
#when a different non-conda local python is used everthing works fine
Conda.add("nomkl")
Conda.rm("mkl")#This also removes mkl-service
#force reinstall of scikit-learn replacing any previous mkl version
Conda.add("scikit-learn")
Conda.add("openblas")
Conda.add("llvm-openmp", channel = "conda-forge")
mkl_checked = true
#following Code runs only if mkl-service exists otherwise jumps to catch branch
@info "Installing non-mkl versions of sci-kit learn via Conda"
#use non-mkl versions of python packages when ENV["PYTHON"]="Conda" or "" is used
#when a different non-conda local python is used everthing works fine
Conda.add("nomkl")
Conda.rm("mkl")#This also removes mkl-service
#force reinstall of scikit-learn replacing any previous mkl version
Conda.add("scikit-learn")
Conda.add("openblas")
Conda.add("llvm-openmp", channel = "conda-forge")
mkl_checked = true
catch
mkl_checked = true
mkl_checked = true
end
end
#
Conda.add("llvm-openmp", channel = "conda-forge")
PyCall.pyimport_conda("sklearn", "scikit-learn")

catch
@info("scikit-learn isn't properly installed."*
"Please use PyCall default Conda or non-conda local python")
rethrow()
end
Conda.add("llvm-openmp", channel = "conda-forge")
PyCall.pyimport_conda("sklearn", "scikit-learn")

catch
@info("scikit-learn isn't properly installed."*
"Please use PyCall default Conda or non-conda local python")
rethrow()
end

elseif Sys.islinux()
if Base.VERSION <= v"1.6.2"
# GLIBCXX_3.4.26
Conda.add("libstdcxx-ng>=3.4,<9.2", channel="conda-forge")
else
# GLIBCXX_3.4.29
# checked up to v1.8.0
Conda.add("libstdcxx-ng>=3.4,<11.4", channel="conda-forge")
end
if !libstdcxx_solved
version = _compatible_libstdcxx_ng_version()
Conda.add("conda", channel="anaconda")
Conda.add("libstdcxx-ng$version", channel="conda-forge")
if version == ">=3.4,<12.0"
# https://github.com/scikit-learn/scikit-learn/pull/23990
Conda.add("scikit-learn<1.1", channel="conda-forge")
end
libstdcxx_solved = true
end

mod = PyCall.pyimport_conda("sklearn", "scikit-learn")
else
mod = PyCall.pyimport_conda("sklearn", "scikit-learn")
Expand Down
2 changes: 1 addition & 1 deletion test/test_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function test_score_sample_weight()
estimators = [DecisionTreeClassifier(max_depth=2),
DecisionTreeRegressor(max_depth=2)]
sets = Any[datasets.load_iris(),
datasets.load_boston()]
datasets.fetch_california_housing()]

for (est, ds) in zip(estimators, sets)
fit!(est, ds["data"], ds["target"])
Expand Down

4 comments on commit 55ee9e6

@cstjean
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator registerer

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Error while trying to register: Action not recognized: registerer

@cstjean
Copy link
Owner Author

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/74475

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.6.6 -m "<description of version>" 55ee9e6063a83b0e933bd752aee13fb32946c881
git push origin v0.6.6

Please sign in to comment.