-
Notifications
You must be signed in to change notification settings - Fork 4.3k
better logging for ports and versions #3048
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ namespace MLAgents | |
public abstract class Academy : MonoBehaviour | ||
{ | ||
const string k_ApiVersion = "API-12"; | ||
const int k_EditorTrainingPort = 5004; | ||
|
||
/// Temporary storage for global gravity value | ||
/// Used to restore oringal value when deriving Academy modifies it | ||
|
@@ -149,7 +150,7 @@ public void LazyInitialization() | |
} | ||
|
||
// Used to read Python-provided environment parameters | ||
static int ReadArgs() | ||
static int ReadPortFromArgs() | ||
{ | ||
var args = System.Environment.GetCommandLineArgs(); | ||
var inputPort = ""; | ||
|
@@ -161,7 +162,22 @@ static int ReadArgs() | |
} | ||
} | ||
|
||
return int.Parse(inputPort); | ||
try | ||
{ | ||
return int.Parse(inputPort); | ||
} | ||
catch | ||
{ | ||
// No arg passed, or malformed port number. | ||
#if UNITY_EDITOR | ||
// Try connecting on the default editor port | ||
return k_EditorTrainingPort; | ||
#else | ||
// This is an executable, so we don't try to connect. | ||
return -1; | ||
#endif | ||
} | ||
|
||
} | ||
|
||
/// <summary> | ||
|
@@ -179,23 +195,15 @@ void InitializeEnvironment() | |
|
||
|
||
// Try to launch the communicator by using the arguments passed at launch | ||
try | ||
var port = ReadPortFromArgs(); | ||
if (port > 0) | ||
{ | ||
Communicator = new RpcCommunicator( | ||
new CommunicatorInitParameters | ||
{ | ||
port = ReadArgs() | ||
}); | ||
} | ||
catch | ||
{ | ||
#if UNITY_EDITOR | ||
Communicator = new RpcCommunicator( | ||
new CommunicatorInitParameters | ||
{ | ||
port = 5004 | ||
}); | ||
#endif | ||
port = port | ||
} | ||
); | ||
} | ||
|
||
if (Communicator != null) | ||
|
@@ -217,6 +225,10 @@ void InitializeEnvironment() | |
} | ||
catch | ||
{ | ||
Debug.Log($"" + | ||
$"Couldn't connect to trainer on port {port} using API version {k_ApiVersion}. " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hope this is OK, I want some information to make sure we're using the same port as python, but also want to make it clear that this is expected sometimes (when doing inference). |
||
"Will perform inference instead." | ||
); | ||
Communicator = null; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,12 +59,11 @@ def from_argparse(args: Any) -> "CommandLineOptions": | |
|
||
|
||
def get_version_string() -> str: | ||
return f""" Version information:\n | ||
ml-agents: {mlagents.trainers.__version__}, | ||
ml-agents-envs: {mlagents.envs.__version__}, | ||
Communicator API: {UnityEnvironment.API_VERSION}, | ||
TensorFlow: {tf_utils.tf.__version__} | ||
""" | ||
return f""" Version information: | ||
ml-agents: {mlagents.trainers.__version__}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just trimmed up the whitespace here. |
||
ml-agents-envs: {mlagents.envs.__version__}, | ||
Communicator API: {UnityEnvironment.API_VERSION}, | ||
TensorFlow: {tf_utils.tf.__version__}""" | ||
|
||
|
||
def parse_command_line(argv: Optional[List[str]] = None) -> CommandLineOptions: | ||
|
@@ -170,7 +169,7 @@ def parse_command_line(argv: Optional[List[str]] = None) -> CommandLineOptions: | |
"--cpu", default=False, action="store_true", help="Run with CPU only" | ||
) | ||
|
||
parser.add_argument("--version", action="version", version=get_version_string()) | ||
parser.add_argument("--version", action="version", version="") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
eng_conf = parser.add_argument_group(title="Engine Configuration") | ||
eng_conf.add_argument( | ||
|
@@ -438,6 +437,7 @@ def main(): | |
) | ||
except Exception: | ||
print("\n\n\tUnity Technologies\n") | ||
print(get_version_string()) | ||
options = parse_command_line() | ||
trainer_logger = logging.getLogger("mlagents.trainers") | ||
env_logger = logging.getLogger("mlagents.envs") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The try/catch here was really for the ReadArgs(); RpcCommunicator never throws.