Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Add preCommand option to support configuring experimental environment by user #2875

Merged
merged 6 commits into from
Sep 21, 2020

Conversation

J-shang
Copy link
Contributor

@J-shang J-shang commented Sep 8, 2020

It can be used in remote mode by set preCommand in experiment config. It is an optional key with string value.
An example is as below:

...
machineList:
  - ip: ${replace_to_your_remote_machine_ip}
    username: ${replace_to_your_remote_machine_username}
    sshKeyPath: ${replace_to_your_remote_machine_sshKeyPath}
    # Pre-command will be executed before the remote machine executes other commands.
    # Below is an example of specifying python path.
    # If you want to execute multiple commands, please use "&&" to connect them.
    preCommand: export PATH=${replace_to_python_environment_path_in_your_remote_machine}:$PATH
...

@QuanluZhang QuanluZhang mentioned this pull request Sep 9, 2020
79 tasks
@QuanluZhang
Copy link
Contributor

export PATH=${replace_to_python_environment_path_in_your_remote_machine}:$PATH. since only this part replace_to_python_environment_path_in_your_remote_machine can be changed, why not directly write this part in this field without export PATH=...

@J-shang
Copy link
Contributor Author

J-shang commented Sep 10, 2020

@QuanluZhang The example may not be particularly clear. It is an example for export python path directly, but not only ${replace_to_python_environment_path_in_your_remote_machine} can be changed.
Maybe you want to use
preCommand: source "${replace_absolute_path_recommended_here}/bin/activate" to activate a virtualenv
or
preCommand: source /${replace_to_conda_path}/bin/activate ${replace_to_conda_env_name} to activate a conda env
User can use any commands they need to configure the experimental environment.

@QuanluZhang
Copy link
Contributor

@QuanluZhang The example may not be particularly clear. It is an example for export python path directly, but not only ${replace_to_python_environment_path_in_your_remote_machine} can be changed.
Maybe you want to use
preCommand: source "${replace_absolute_path_recommended_here}/bin/activate" to activate a virtualenv
or
preCommand: source /${replace_to_conda_path}/bin/activate ${replace_to_conda_env_name} to activate a conda env
User can use any commands they need to configure the experimental environment.

got it. so it is not specifically for specifying python environment, it is a general command which is executed before trial code. suggest to make it clear how to specify python environment with this command in doc

@J-shang
Copy link
Contributor Author

J-shang commented Sep 10, 2020

Indeed, I will add more detailed instructions in the doc.

@J-shang J-shang force-pushed the machinelist-precommand branch from bae7a1a to 37a1401 Compare September 13, 2020 12:55
@SparkSnail
Copy link
Contributor

It can be used in remote mode by set preCommand in experiment config. It is an optional key with string value.
An example is as below:

...
machineList:
  - ip: ${replace_to_your_remote_machine_ip}
    username: ${replace_to_your_remote_machine_username}
    sshKeyPath: ${replace_to_your_remote_machine_sshKeyPath}
    # Pre-command will be executed before the remote machine executes other commands.
    # Below is an example of specifying python path.
    # If you want to execute multiple commands, please use "&&" to connect them.
    preCommand: export PATH=${replace_to_python_environment_path_in_your_remote_machine}:$PATH
...

This preCommand is added per machine, and only works when the machine is set preCommand? In remote mode, the trial is scheduled randomly on different machine, then the trial code will be executed randomly in different preCommand?

@J-shang
Copy link
Contributor Author

J-shang commented Sep 15, 2020

It can be used in remote mode by set preCommand in experiment config. It is an optional key with string value.
An example is as below:

...
machineList:
  - ip: ${replace_to_your_remote_machine_ip}
    username: ${replace_to_your_remote_machine_username}
    sshKeyPath: ${replace_to_your_remote_machine_sshKeyPath}
    # Pre-command will be executed before the remote machine executes other commands.
    # Below is an example of specifying python path.
    # If you want to execute multiple commands, please use "&&" to connect them.
    preCommand: export PATH=${replace_to_python_environment_path_in_your_remote_machine}:$PATH
...

This preCommand is added per machine, and only works when the machine is set preCommand? In remote mode, the trial is scheduled randomly on different machine, then the trial code will be executed randomly in different preCommand?

Yes, if user don't set preCommand, the process will run in the default environment as before.
I think the trial code will be executed randomly in different preCommand, this may be mainly caused by different configuration methods in different machines. Like source /YOUR_CONDA_PATH/bin/activate your_env in Linux and call activate your_env in Windows.

```

Files in `codeDir` will be uploaded to remote machines automatically. You can run below command on Windows, Linux, or macOS to spawn trials on remote Linux machines:
Files in `codeDir` will be uploaded to remote machines automatically. The `preCommand` will be executed before the remote machine executes other commands. So if you need to configure the experimental environment such as activate the conda environment, set `preCommand`. You can run below command on Windows, Linux, or macOS to spawn trials on remote Linux machines:

Copy link
Contributor

Choose a reason for hiding this comment

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

suggest to use a subsection to explain how to config python environment with preCommand

@J-shang J-shang force-pushed the machinelist-precommand branch from 37a1401 to 5128de3 Compare September 16, 2020 03:13
@J-shang J-shang force-pushed the machinelist-precommand branch from 5128de3 to 1fd74c5 Compare September 16, 2020 03:17
@J-shang J-shang requested a review from QuanluZhang September 16, 2020 03:18
@chicm-ms
Copy link
Contributor

Please add UT and/or IT test cases.

@chicm-ms
Copy link
Contributor

chicm-ms commented Sep 16, 2020

Since this preCommand will be added to all commands executed on remote machine, so in doc/config example, please mention that: user should not use those commands may make changes to system, like mkdir, touch, etc

@chicm-ms
Copy link
Contributor

remote machine support windows as local / remote system, have we checked whether it works on windows?

@J-shang
Copy link
Contributor Author

J-shang commented Sep 16, 2020

Please add UT and/or IT test cases.

Got it.

Since this preCommand will be added to all commands executed on remote machine, so in doc/config example, please mention that: user should not use those commands may make changes to system, like mkdir, touch, etc

This should indeed remind users. I will add note for it.

remote machine support windows as local / remote system, have we checked whether it works on windows?

Yes, it works on windows.

@chicm-ms chicm-ms closed this Sep 18, 2020
@chicm-ms chicm-ms reopened this Sep 18, 2020
preCommand: command1 && command2 && command3
```

__Note__: Because __preCommand__ will execute before other commands each time, it is strongly not recommended to set __preCommand__ that will make changes to system, i.e. `mkdir` or `touch`.
Copy link
Contributor

Choose a reason for hiding this comment

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

this doc is very clear!

preCommand: call activate ${replace_to_conda_env_name}
```

If there are multiple commands want to execute, you can use `&&` to connect these commands:
Copy link
Contributor

Choose a reason for hiding this comment

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

"If there are multiple commands want to execute" -> "If you want multiple commands to be executed"

@J-shang J-shang force-pushed the machinelist-precommand branch from a1bb3e0 to 01020d8 Compare September 21, 2020 04:11
@chicm-ms chicm-ms merged commit f892ed6 into microsoft:master Sep 21, 2020
@J-shang J-shang deleted the machinelist-precommand branch October 19, 2020 02:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants