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

Update _get_env_from to handle cases better #398

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

carolineechen
Copy link
Collaborator

@carolineechen carolineechen commented Jan 26, 2024

improve 2 cases of _get_env_from, which is expected to return an Env type:

  1. input env = "base_env" -- falls through all the if statements and returns the string "base_env" instead of the Env object
  2. env is not saved in rns_client but exists on the cluster associated with the call. returns the env string instead of Env object

Copy link
Collaborator Author

carolineechen commented Jan 26, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @carolineechen and the rest of your teammates on Graphite Graphite


warning = f"Could not locate Env from value: {env}"
warning = f"{warning} on cluster {system.name}" if system else warning
logging.warning(warning)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dongreenberg can you double check my logic here and if this PR makes sense? and is there an instance where it still makes sense to return the input env if it doesn't satisfy any of the conditions or to simply throw an error?

most cases we expect an Env to be returned which will throw an error elsewhere if it returns a string and we try to call an env property on it. but there could also be cases where the output is simply used to populate a config etc, not sure if it's an issue if a string is returned if the corresponding Env could not be found.

Copy link
Contributor

Choose a reason for hiding this comment

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

tbh I'm nervous that passing system here is a little non-deterministic. Den and this system could have different configs for that env name, and the only thing determining which is returned is the order we've implemented here. What case are we solving for where we want to check on the cluster for the env config?

I also don't think I'd raise a warning here. We use this method all the time in instances where we don't necessarily expect and env to be found (but should construct one if it is), and it'll be pretty noisy for the user.

Copy link
Contributor

@dongreenberg dongreenberg left a comment

Choose a reason for hiding this comment

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

Tbh I think I'm missing some context, but there's some back and forth here with the cluster that seems a bit hairy to me. Let's chat about it live

Comment on lines +41 to 44
if isinstance(env, Resource) or env is None:
return env

from runhouse.resources.envs import Env
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if isinstance(env, Resource) or env is None:
return env
from runhouse.resources.envs import Env
from runhouse.resources.envs import Env
if isinstance(env, Env) or env is None:
return env

Comment on lines +56 to +64
if system.get(env):
return system.get(env)

# handle case where env is passed in as full rns address
name, _ = rns_client.split_rns_name_and_path(
rns_client.resolve_rns_path(env)
)
if system.get(name):
return system.get(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if system.get(env):
return system.get(env)
# handle case where env is passed in as full rns address
name, _ = rns_client.split_rns_name_and_path(
rns_client.resolve_rns_path(env)
)
if system.get(name):
return system.get(name)
# handle case where env is passed in as full rns address
name, _ = rns_client.split_rns_name_and_path(
rns_client.resolve_rns_path(env)
) if "/" in env else (env, None)
if system.get(name):
return system.get(name)

Copy link
Contributor

Choose a reason for hiding this comment

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

Just saves a get


warning = f"Could not locate Env from value: {env}"
warning = f"{warning} on cluster {system.name}" if system else warning
logging.warning(warning)
Copy link
Contributor

Choose a reason for hiding this comment

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

tbh I'm nervous that passing system here is a little non-deterministic. Den and this system could have different configs for that env name, and the only thing determining which is returned is the order we've implemented here. What case are we solving for where we want to check on the cluster for the env config?

I also don't think I'd raise a warning here. We use this method all the time in instances where we don't necessarily expect and env to be found (but should construct one if it is), and it'll be pretty noisy for the user.

@@ -317,7 +318,7 @@ def install_packages(
from runhouse.resources.envs.env import Env

self.check_server()
env = _get_env_from(env) or Env(name=env or Env.DEFAULT_NAME)
env = _get_env_from(env, system=self) or Env(name=env or Env.DEFAULT_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me a bit nervous - if the env contains package objects they will be serialized and sent back pointing to the cluster's local filesystem. Also not totally clear what's happening here, we're getting the env object from the system by name so we can then extract the name out of it?

@dongreenberg
Copy link
Contributor

I also think perhaps the base_env and base default naming business is confusing me here. We should probably rename those or eliminate the overlap asap.

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.

None yet

2 participants