Skip to content

Commit

Permalink
Merge pull request #30 from OSC/user-ijulia-1.0
Browse files Browse the repository at this point in the history
Conditionally add IJulia 1.x kernel only if the user has it installed for themselves
  • Loading branch information
MorganRodgers authored Nov 5, 2019
2 parents c3e6863 + e2f416c commit c8c372f
Showing 1 changed file with 96 additions and 2 deletions.
98 changes: 96 additions & 2 deletions template/script.sh.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,82 @@
#!/usr/bin/env bash

<%-
require 'pathname'

# @returns [[major_minor_version, "lmod_load_string"], ["0.6", "julia/0.6.4"]]
def get_lmod_julia_versions
`ssh -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no owens.osc.edu 'bash --login -c "module spider julia"' 2>&1`.scan(
/julia\/(?:(?<maj>\d+)\.(?<min>\d+)\.(?<pat>\d+))/
).uniq.map do |mtch|
[
"#{mtch[0]}.#{mtch[1]}",
"#{mtch.join('.')}"
]
end
end

# @returns [[major_minor_version, kernel_version], ["1.0", "1.20.0"]]
def get_active_user_ijulia_kernel_versions
user_julia_envs = Pathname.new("~/.julia/environments/").expand_path

if ! user_julia_envs.exist?
[]
else
user_julia_envs.children.select do |child|
child.directory? && child.to_s.match?(/v\d+\.\d+/) && child.join('Manifest.toml').exist?
end.map do |child|
[
child.basename.to_s.gsub('v', ''),
child.join('Manifest.toml').read.match(/\[\[IJulia\]\].+?version\s*=\s*"(?<version>\d+\.\d+\.\d+)"\n/m)
]
end.select do |pair|
pair[-1]
end.map do |pair|
pair[-1] = pair[-1][:version]
pair
end
end
end

# @returns [[kernel_version, path_to_kernel], ["1.19.0", #<Pathname:/users/PZS0710/zyou/.julia/packages/IJulia/cwvsj/src/kernel.jl>]]
def get_installed_user_ijulia_kernels
ijulia_installation_root = Pathname.new("~/.julia/packages/IJulia").expand_path

if ! ijulia_installation_root.exist?
[]
else
ijulia_installation_root.children.select do |child|
child.join('Project.toml').exist?
end.map do |child|
[
child.join('Project.toml').read.match(/version\s*=\s*"(?<version>\d+\.\d+\.\d+)"/)[:version],
child.join('src/kernel.jl').to_s
]
end
end
end

def kernel_hash(
cuda:, installation:, lmod_version:, wrapper:
)
{
display_name: "User Defined Julia #{lmod_version}" + ((cuda.empty?) ? "" : " [#{cuda}]"),
language: "julia",
argv: [
wrapper,
"julia",
"-i",
"--startup-file=yes",
"--color=yes",
installation,
"{connection_file}"
],
env: {
MODULES: "xalt/latest julia/#{lmod_version} #{cuda}"
}
}
end
cuda = (context.node_type == "gpu") ? context.cuda_version : ""
wrapper = session.staged_root.join("launch_wrapper.sh")
wrapper_log = session.staged_root.join("launch_wrapper.log")
Expand Down Expand Up @@ -96,7 +172,7 @@
],
env: {
MODULES: "xalt/latest julia/0.6.4 #{cuda}"
}
},
},
julia100: {
display_name: "Julia 1.0.0 [julia/1.0.0 #{cuda}]",
Expand All @@ -114,7 +190,25 @@
MODULES: "xalt/latest julia/1.0.0 #{cuda}"
}
},
}
}.tap do |hsh|
# Any existing Julia kernelspec may be clobbered if the user has their own version of that kernel installed
lmod_julia_versions = Hash[get_lmod_julia_versions]
installed_user_ijulia_kernels = Hash[get_installed_user_ijulia_kernels]
get_active_user_ijulia_kernel_versions.each do |maj_min_ver, kernel_version|
lmod_version = lmod_julia_versions[maj_min_ver]
next unless lmod_version
next unless installed_user_ijulia_kernels[kernel_version]
hsh["julia#{lmod_version.gsub('.', '')}".to_sym] = kernel_hash(
cuda: cuda,
installation: installed_user_ijulia_kernels[kernel_version],
lmod_version: lmod_version,
wrapper: wrapper
)
end
end
-%>
echo "Starting main script..."
Expand Down

0 comments on commit c8c372f

Please sign in to comment.