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

#492 #493

Merged
merged 22 commits into from
Jul 24, 2024
Merged

#492 #493

merged 22 commits into from
Jul 24, 2024

Conversation

JoeyC12
Copy link
Contributor

@JoeyC12 JoeyC12 commented Jul 1, 2024

#492

‘garden-ai hpc-notebook start --working-directory $(pwd)/tmp --notebooks-dir $(pwd)/notebooks’ starts a Jupyter notebook in an Apptainer Container.


📚 Documentation preview 📚: https://garden-ai--493.org.readthedocs.build/en/493/

@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2024

Codecov Report

Attention: Patch coverage is 15.00000% with 51 lines in your changes missing coverage. Please review.

Project coverage is 74.06%. Comparing base (1d34837) to head (c569100).
Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
garden_ai/app/hpc_notebook.py 15.00% 51 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #493      +/-   ##
==========================================
- Coverage   75.50%   74.06%   -1.45%     
==========================================
  Files          55       56       +1     
  Lines        3695     4288     +593     
==========================================
+ Hits         2790     3176     +386     
- Misses        905     1112     +207     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@WillEngler WillEngler left a comment

Choose a reason for hiding this comment

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

This is a solid start, good job getting Jupyter running from inside Singularity/Apptainer. The biggest issue to address is making sure that the user can run this command from outside the Garden repo

Singularity.def Outdated

%startscript

exec /bin/bash -c "jupyter notebook --notebook-dir=/notebooks --ip 0.0.0.0 --no-browser --allow-root"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need allow-root here?

try:
# Ensure the definition file exists
if not os.path.isfile(definition_file):
logger.error(f"Definition file {definition_file} not found.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this approach rely on the user being in the root directory of the project where Singularity.def is? Let's make sure the user can run this command in any directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

# Step 3: Build the Apptainer container
build_command = ["apptainer", "build", container_image, definition_file]
subprocess.run(build_command, check=True)
logger.info("Apptainer container built successfully.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this command give you a way to reuse an image if you've already built it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I add a rerun command

Singularity.def Outdated
@@ -0,0 +1,25 @@
Bootstrap: docker
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sort of file shouldn't live at the root of the project. Our Docker building script is in scripts. Can you move this there or create a new appropriate directory for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -0,0 +1 @@
Place to store notebooks
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the intent is that this is for users' notebook files, it doesn't belong in the project repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted

tmp/tmp.md Outdated
@@ -0,0 +1 @@
Place to store temporary file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly, a tmp directory for the user should not be committed to the project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted

"notebook",
"--no-browser",
"--ip=0.0.0.0",
"--allow-root",
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this command will use the default Jupyter port. I'd recommend reusing the find_available_port helper to avoid the (likely) scenario of colliding with another user on the login node using the default Jupyter port

typer.echo("🚧🌱🚧 Failed to start Jupyter Notebook 🚧🌱🚧")
except Exception as e:
logger.error(f"An error occurred: {e}")
typer.echo("🚧🌱🚧 An unexpected error occurred 🚧🌱🚧")
Copy link
Collaborator

Choose a reason for hiding this comment

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

How should the user shut down their Singularity container when they're done? It's ok to not build in really robust cleanup handling right now, but ideally we could handle the happy path of the user hitting ctrl-c. Or at least we should print instructions to the user for how they can manually end their session.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@JoeyC12 Can you address this question?

):
root = os.path.dirname(os.path.abspath(__file__))
root = os.path.dirname(root)
root = os.path.dirname(root)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think saving the sif file next to where the user has installed the Python code is pretty surprising. That will make it hard to find and clean up. Can we instead save it by default in the directory where the user ran the garden-ai command? (Maybe with an option to specify a different directory?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also it looks like there are some repeated lines here


script_dir = os.path.dirname(os.path.abspath(__file__))
script_dir = os.path.dirname(script_dir)
script_dir = os.path.dirname(script_dir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

script_dir = os.path.dirname(script_dir) goes to parent directory. I am locating the definition file here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. This is pretty unintuitive for a reader of this code. Can you either find a different way to express this or add a comment explaining this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Friendly ping on this comment @JoeyC12

typer.echo("🚧🌱🚧 Failed to start Jupyter Notebook 🚧🌱🚧")
except Exception as e:
logger.error(f"An error occurred: {e}")
typer.echo("🚧🌱🚧 An unexpected error occurred 🚧🌱🚧")
Copy link
Collaborator

Choose a reason for hiding this comment

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

@JoeyC12 Can you address this question?


tmp_dir = os.path.join(working_directory, "tmp")
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the Python tempfile utils always return different filenames, so I don't think this cleanup step does much in practice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted this line

os.makedirs(notebooks_dir)

# Step 1: Create temporary directory if it doesn't exist
working_directory = tempfile.mkdtemp()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be least surprising if we make the singularity working directory the user's current working directory. (ie, where they executed garden-ai).

If you want to go with temp dirs instead, we'll need to clean it up properly. (ie, use the TemporaryDirectory context manager)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@JoeyC12 Can you address this?

Copy link
Collaborator

@WillEngler WillEngler left a comment

Choose a reason for hiding this comment

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

Thanks for getting these edits in! This looks good to merge

@WillEngler WillEngler merged commit b6ebc9e into main Jul 24, 2024
6 of 7 checks passed
@WillEngler WillEngler deleted the issue-492 branch July 24, 2024 18:39
@WillEngler WillEngler restored the issue-492 branch July 24, 2024 18:39
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.

4 participants