Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom shared projects for julia_project #197

Merged
merged 18 commits into from
Sep 26, 2022

Conversation

MilesCranmer
Copy link
Owner

This will fix #196. If you specify an @ in your julia_project string, like julia_project="@my_project", then this will be designated a shared project (just as if you had specified ]activate @my_project in the Julia REPL.

cc @mkitti

test/test_env.py Outdated Show resolved Hide resolved
test/test_env.py Outdated
Main = julia_helpers.init_julia(julia_project=test_env_name)
Main.eval("using SymbolicRegression")
# TODO: Test that we are actually in the correct env.
# TODO: Delete the env at the end.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Not sure if there is any way to do this? I suppose I need to create a temp env instead (but that's a different question).

Copy link
Contributor

Choose a reason for hiding this comment

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

You could pushfirst! a temp directory into DEPOT_PATH. Then the shared environment would be created in the temp directory. Then you can pop! the tempdir off DEPOT_PATH and recursively delete it.

Copy link
Owner Author

Choose a reason for hiding this comment

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

If the DEPOT_PATH changes, and you activate a new environment, will it correctly update? It seems like it is not switching to the new setting for some reason (see error)

Traceback (most recent call last):
  File "/Users/mcranmer/Documents/PySR/test/test_env.py", line 24, in test_custom_shared_env
    self.assertEqual(cur_project_dir, potential_shared_project_dirs)
AssertionError: '/Users/mcranmer/.julia/environments' != '/var/folders/1h/xyppkvx52cl6w3_h8bw_gdqh0000gr/T/tmp8dknp59s/environments'

i.e., the current project is still in /Users/mcranmer/.julia/environments rather than the new depot

@mkitti
Copy link
Contributor

mkitti commented Sep 22, 2022

Merge conda-forge/pysr-feedstock#51 to unpin openlibm then the test here will pass

@MilesCranmer
Copy link
Owner Author

Ah, I think I see an issue (at least, for testing this). Right now the init_julia only sets the environment via an environment variable - rather than the activate() command. The only time activate() is used explicitly is in the install part:

Main.eval(
f'Pkg.activate("{_escape_filename(julia_project)}", shared = Bool({int(is_shared)}), {io_arg})'
)

So I think what we should actually do is call activate() if Julia has already been initialized. (Since changing the environment variable won't change the env!)

@mkitti
Copy link
Contributor

mkitti commented Sep 22, 2022

So I think what we should actually do is call activate() if Julia has already been initialized. (Since changing the environment variable won't change the env!)

Correct. The only reason I used the environment variable earlier was to select the environment where we expect PyCall to be, which may not be the default environment.

@MilesCranmer
Copy link
Owner Author

Okay so now the DEPOT_PATH correctly sets the project. However, for some reason, julia.install() switches the environment back to the normal DEPOT_PATH... Not sure why.

from pysr.julia_helpers import init_julia, install

Main = init_julia()
Main.eval('pushfirst!(DEPOT_PATH, "/tmp/1")')
Main = init_julia("@test2")

This correctly goes to the /tmp/1/environments. However! When you do:

install("@test2")

this sets to the normal DEPOT_PATH...

  Activating project at `~/.julia/environments/test2`

Is this something in PyJulia maybe?

@mkitti
Copy link
Contributor

mkitti commented Sep 22, 2022

However! When you do:

install("@test2")

this sets to the normal DEPOT_PATH...

  Activating project at `~/.julia/environments/test2`

Is this something in PyJulia maybe?

In this case it seems you have not manipulated DEPOT_PATH, so I'm guessing that DEPOT_PATH is just the default value.

Note that the DEPOT_PATH global is specific to each Julia session. Manipulating it does not influence the corresponding environment variable JULIA_DEPOT_PATH. Thus if the environment variable JULIA_DEPOT_PATH is not set and you have not manipulated DEPOT_PATH, the depot will be at its default location.

@MilesCranmer
Copy link
Owner Author

Thanks - the weird thing is that those commands are from the same Python session. So the DEPOT_PATH should stick around through the install() call…

@mkitti
Copy link
Contributor

mkitti commented Sep 22, 2022

Is this happening on all versions of Julia or just particular ones, perhaps less than Julia 1.7.0?

I'm thinking about the subprocess and _get_julia_env_dir stuff that we did. The Julia process run by subprocess would have no idea about changes you may have made within the current Julia process.

@MilesCranmer
Copy link
Owner Author

Okay I think that got it. It wasn't the subprocess - it was the JULIA_DEPOT_PATH that was missing! Good catch.

@MilesCranmer
Copy link
Owner Author

Cool:

  Activating project at `/var/folders/1h/xyppkvx52cl6w3_h8bw_gdqh0000gr/T/tmpmrkyi7cm/environments/pysr_test_env`

Not sure what the conda errors are though.

@MilesCranmer
Copy link
Owner Author

Ah, the conda errors were just because the environment.yml wasn't updated to the new Julia 1.8.0 requirement for openlibm - have since unpinned it and seems to be happy.

@mkitti
Copy link
Contributor

mkitti commented Sep 26, 2022

This looks like an improvement to me. I still think we should figure out how to generalize this to non-shared environments at some point.

@MilesCranmer MilesCranmer merged commit 3532c08 into master Sep 26, 2022
@MilesCranmer MilesCranmer deleted the custom-julia-project branch November 4, 2022 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] SymbolicRegressions.jl is not installed into julia_project
2 participants