Skip to content

Commit

Permalink
change command name and add pbar message (dotnet#380)
Browse files Browse the repository at this point in the history
* change command name and add pbar message

* fix tests

* added aliases

* duplicate alias

* added another alias for task
  • Loading branch information
srsaggam authored Apr 11, 2019
1 parent 9faceb2 commit ffd773b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
42 changes: 21 additions & 21 deletions src/mlnet.Test/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void TestMinimumCommandLineArgs()

var parser = new CommandLineBuilder()
// Parser
.AddCommand(CommandDefinitions.New(handler))
.AddCommand(CommandDefinitions.AutoTrain(handler))
.UseDefaults()
.UseExceptionHandler((e, ctx) =>
{
Expand All @@ -41,7 +41,7 @@ public void TestMinimumCommandLineArgs()

var trainDataset = Path.GetTempFileName();
var testDataset = Path.GetTempFileName();
string[] args = new[] { "new", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", "Label" };
string[] args = new[] { "auto-train", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", "Label" };
parser.InvokeAsync(args).Wait();
File.Delete(trainDataset);
File.Delete(testDataset);
Expand All @@ -63,7 +63,7 @@ public void TestCommandLineArgsFailTest()

var parser = new CommandLineBuilder()
// parser
.AddCommand(CommandDefinitions.New(handler))
.AddCommand(CommandDefinitions.AutoTrain(handler))
.UseDefaults()
.UseExceptionHandler((e, ctx) =>
{
Expand All @@ -76,22 +76,22 @@ public void TestCommandLineArgsFailTest()
var testDataset = Path.GetTempFileName();

//wrong value to ml-task
string[] args = new[] { "new", "--ml-task", "bad-value", "--train-dataset", trainDataset, "--label-column-name", "Label" };
string[] args = new[] { "auto-train", "--ml-task", "bad-value", "--train-dataset", trainDataset, "--label-column-name", "Label" };
parser.InvokeAsync(args).Wait();
Assert.IsFalse(parsingSuccessful);

// Incorrect invocation
args = new[] { "new", "binary-classification", "--train-dataset", trainDataset, "--label-column-name", "Label" };
args = new[] { "auto-train", "binary-classification", "--train-dataset", trainDataset, "--label-column-name", "Label" };
parser.InvokeAsync(args).Wait();
Assert.IsFalse(parsingSuccessful);

// Non-existent file test
args = new[] { "new", "--ml-task", "binary-classification", "--train-dataset", "nonexistentfile.csv", "--label-column-name", "Label" };
args = new[] { "auto-train", "--ml-task", "binary-classification", "--train-dataset", "nonexistentfile.csv", "--label-column-name", "Label" };
parser.InvokeAsync(args).Wait();
Assert.IsFalse(parsingSuccessful);

// No label column or index test
args = new[] { "new", "--ml-task", "binary-classification", "--train-dataset", trainDataset, "--test-dataset", testDataset };
args = new[] { "auto-train", "--ml-task", "binary-classification", "--train-dataset", trainDataset, "--test-dataset", testDataset };
parser.InvokeAsync(args).Wait();
File.Delete(trainDataset);
File.Delete(testDataset);
Expand Down Expand Up @@ -128,7 +128,7 @@ public void TestCommandLineArgsValuesTest()

var parser = new CommandLineBuilder()
// Parser
.AddCommand(CommandDefinitions.New(handler))
.AddCommand(CommandDefinitions.AutoTrain(handler))
.UseDefaults()
.UseExceptionHandler((e, ctx) =>
{
Expand All @@ -137,7 +137,7 @@ public void TestCommandLineArgsValuesTest()
.Build();

// Incorrect mltask test
string[] args = new[] { "new", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--validation-dataset", validDataset, "--test-dataset", testDataset, "--max-exploration-time", "5", "--name", name, "--output-path", outputPath, "--has-header", falseString };
string[] args = new[] { "auto-train", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--validation-dataset", validDataset, "--test-dataset", testDataset, "--max-exploration-time", "5", "--name", name, "--output-path", outputPath, "--has-header", falseString };
parser.InvokeAsync(args).Wait();
File.Delete(trainDataset);
File.Delete(testDataset);
Expand All @@ -164,7 +164,7 @@ public void TestCommandLineArgsMutuallyExclusiveArgsTest()

var parser = new CommandLineBuilder()
// Parser
.AddCommand(CommandDefinitions.New(handler))
.AddCommand(CommandDefinitions.AutoTrain(handler))
.UseDefaults()
.UseExceptionHandler((e, ctx) =>
{
Expand All @@ -173,17 +173,17 @@ public void TestCommandLineArgsMutuallyExclusiveArgsTest()
.Build();

// Incorrect arguments : specifying dataset and train-dataset
string[] args = new[] { "new", "--ml-task", "BinaryClassification", "--dataset", dataset, "--train-dataset", trainDataset, "--label-column-name", labelName, "--test-dataset", testDataset, "--max-exploration-time", "5" };
string[] args = new[] { "auto-train", "--ml-task", "BinaryClassification", "--dataset", dataset, "--train-dataset", trainDataset, "--label-column-name", labelName, "--test-dataset", testDataset, "--max-exploration-time", "5" };
parser.InvokeAsync(args).Wait();
Assert.IsFalse(parsingSuccessful);

// Incorrect arguments : specifying train-dataset and not specifying test-dataset
args = new[] { "new", "--ml-task", "BinaryClassification", "--train-dataset", trainDataset, "--label-column-name", labelName, "--max-exploration-time", "5" };
args = new[] { "auto-train", "--ml-task", "BinaryClassification", "--train-dataset", trainDataset, "--label-column-name", labelName, "--max-exploration-time", "5" };
parser.InvokeAsync(args).Wait();
Assert.IsFalse(parsingSuccessful);

// Incorrect arguments : specifying label column name and index
args = new[] { "new", "--ml-task", "BinaryClassification", "--train-dataset", trainDataset, "--label-column-name", labelName, "--label-column-index", "0", "--test-dataset", testDataset, "--max-exploration-time", "5" };
args = new[] { "auto-train", "--ml-task", "BinaryClassification", "--train-dataset", trainDataset, "--label-column-name", labelName, "--label-column-index", "0", "--test-dataset", testDataset, "--max-exploration-time", "5" };
parser.InvokeAsync(args).Wait();
File.Delete(trainDataset);
File.Delete(testDataset);
Expand Down Expand Up @@ -214,7 +214,7 @@ public void CacheArgumentTest()

var parser = new CommandLineBuilder()
// Parser
.AddCommand(CommandDefinitions.New(handler))
.AddCommand(CommandDefinitions.AutoTrain(handler))
.UseDefaults()
.UseExceptionHandler((e, ctx) =>
{
Expand All @@ -223,30 +223,30 @@ public void CacheArgumentTest()
.Build();

// valid cache test
string[] args = new[] { "new", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--cache", cache };
string[] args = new[] { "auto-train", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--cache", cache };
parser.InvokeAsync(args).Wait();
Assert.IsTrue(parsingSuccessful);

parsingSuccessful = false;

cache = "off";
// valid cache test
args = new[] { "new", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--cache", cache };
args = new[] { "auto-train", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--cache", cache };
parser.InvokeAsync(args).Wait();
Assert.IsTrue(parsingSuccessful);

parsingSuccessful = false;

cache = "auto";
// valid cache test
args = new[] { "new", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--cache", cache };
args = new[] { "auto-train", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--cache", cache };
parser.InvokeAsync(args).Wait();
Assert.IsTrue(parsingSuccessful);

parsingSuccessful = false;

// invalid cache test
args = new[] { "new", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--cache", "blah" };
args = new[] { "auto-train", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--cache", "blah" };
parser.InvokeAsync(args).Wait();
Assert.IsFalse(parsingSuccessful);

Expand Down Expand Up @@ -276,7 +276,7 @@ public void IgnoreColumnsArgumentTest()

var parser = new CommandLineBuilder()
// Parser
.AddCommand(CommandDefinitions.New(handler))
.AddCommand(CommandDefinitions.AutoTrain(handler))
.UseDefaults()
.UseExceptionHandler((e, ctx) =>
{
Expand All @@ -285,13 +285,13 @@ public void IgnoreColumnsArgumentTest()
.Build();

// valid cache test
string[] args = new[] { "new", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--ignore-columns", ignoreColumns };
string[] args = new[] { "auto-train", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--ignore-columns", ignoreColumns };
parser.InvokeAsync(args).Wait();
Assert.IsTrue(parsingSuccessful);

parsingSuccessful = false;

args = new[] { "new", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--ignore-columns", "a b c" };
args = new[] { "auto-train", "--ml-task", "binary-classification", "--dataset", trainDataset, "--label-column-name", labelName, "--ignore-columns", "a b c" };
parser.InvokeAsync(args).Wait();
Assert.IsFalse(parsingSuccessful);

Expand Down
7 changes: 3 additions & 4 deletions src/mlnet/CodeGenerator/CodeGenerationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,31 @@ public void GenerateCode()
{
using (var pbar = new FixedDurationBar(wait, "", options))
{
pbar.Message = Strings.WaitingForFirstIteration;
Thread t = default;
switch (taskKind)
{
case TaskKind.BinaryClassification:
t = new Thread(() => binaryRunDetails = automlEngine.ExploreBinaryClassificationModels(context, trainData, validationData, columnInformation, new BinaryExperimentSettings().OptimizingMetric, pbar));
t.Start();
break;
case TaskKind.Regression:
t = new Thread(() => regressionRunDetails = automlEngine.ExploreRegressionModels(context, trainData, validationData, columnInformation, new RegressionExperimentSettings().OptimizingMetric, pbar));
t.Start();
break;
case TaskKind.MulticlassClassification:
t = new Thread(() => multiRunDetails = automlEngine.ExploreMultiClassificationModels(context, trainData, validationData, columnInformation, new MulticlassExperimentSettings().OptimizingMetric, pbar));
t.Start();
break;
default:
logger.Log(LogLevel.Error, Strings.UnsupportedMlTask);
break;
}
t.Start();

if (!pbar.CompletedHandle.WaitOne(wait))
pbar.Message = $"{nameof(FixedDurationBar)} did not signal {nameof(FixedDurationBar.CompletedHandle)} after {wait}";

if (t.IsAlive == true)
{
string waitingMessage = "Waiting for the last iteration to complete ...";
string waitingMessage = Strings.WaitingForLastIteration;
string originalMessage = pbar.Message;
pbar.Message = waitingMessage;
t.Join();
Expand Down
30 changes: 15 additions & 15 deletions src/mlnet/Commands/CommandDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace Microsoft.ML.CLI.Commands
{
internal static class CommandDefinitions
{
internal static System.CommandLine.Command New(ICommandHandler handler)
internal static System.CommandLine.Command AutoTrain(ICommandHandler handler)
{
var newCommand = new System.CommandLine.Command("new", "Create a new .NET project using ML.NET to train and run a model", handler: handler)
var newCommand = new System.CommandLine.Command("auto-train", "Create a new .NET project using ML.NET to train and run a model", handler: handler)
{
Dataset(),
ValidationDataset(),
Expand Down Expand Up @@ -62,56 +62,56 @@ internal static System.CommandLine.Command New(ICommandHandler handler)
return newCommand;

Option Dataset() =>
new Option("--dataset", "File path to either a single dataset or a training dataset for train/test split approaches.",
new Option(new List<string>() { "--dataset", "-d" }, "File path to either a single dataset or a training dataset for train/test split approaches.",
new Argument<FileInfo>().ExistingOnly());

Option ValidationDataset() =>
new Option("--validation-dataset", "File path for the validation dataset in train/validation/test split approaches.",
new Option(new List<string>() { "--validation-dataset", "-v" }, "File path for the validation dataset in train/validation/test split approaches.",
new Argument<FileInfo>(defaultValue: default(FileInfo)).ExistingOnly());

Option TestDataset() =>
new Option("--test-dataset", "File path for the test dataset in train/test approaches.",
new Option(new List<string>() { "--test-dataset", "-t" }, "File path for the test dataset in train/test approaches.",
new Argument<FileInfo>(defaultValue: default(FileInfo)).ExistingOnly());

Option MlTask() =>
new Option("--ml-task", "Type of ML task to perform. Current supported tasks: regression, binary-classification, multiclass-classification.",
new Option(new List<string>() { "--ml-task", "--mltask", "--task", "-T" }, "Type of ML task to perform. Current supported tasks: regression, binary-classification, multiclass-classification.",
new Argument<string>().FromAmong(GetMlTaskSuggestions()));

Option LabelName() =>
new Option("--label-column-name", "Name of the label (target) column to predict.",
new Option(new List<string>() { "--label-column-name", "-n" }, "Name of the label (target) column to predict.",
new Argument<string>());

Option LabelColumnIndex() =>
new Option("--label-column-index", "Index of the label (target) column to predict.",
new Option(new List<string>() { "--label-column-index", "-i" }, "Index of the label (target) column to predict.",
new Argument<uint>());

Option MaxExplorationTime() =>
new Option("--max-exploration-time", "Maximum time in seconds for exploring models with best configuration.",
new Option(new List<string>() { "--max-exploration-time", "-x" }, "Maximum time in seconds for exploring models with best configuration.",
new Argument<uint>(defaultValue: 10));

Option Verbosity() =>
new Option(new List<string>() { "--verbosity" }, "Output verbosity choices: q[uiet], m[inimal] (by default) and diag[nostic].",
new Option(new List<string>() { "--verbosity", "-V" }, "Output verbosity choices: q[uiet], m[inimal] (by default) and diag[nostic].",
new Argument<string>(defaultValue: "m").FromAmong(GetVerbositySuggestions()));

Option Name() =>
new Option(new List<string>() { "--name" }, "Name for the output project or solution to create. ",
new Option(new List<string>() { "--name", "-N" }, "Name for the output project or solution to create. ",
new Argument<string>());

Option OutputPath() =>
new Option(new List<string>() { "--output-path" }, "Location folder to place the generated output. The default is the current directory.",
new Option(new List<string>() { "--output-path", "-o" }, "Location folder to place the generated output. The default is the current directory.",
new Argument<DirectoryInfo>(defaultValue: new DirectoryInfo(".")));

Option HasHeader() =>
new Option(new List<string>() { "--has-header" }, "Specify true/false depending if the dataset file(s) have a header row.",
new Option(new List<string>() { "--has-header", "-h" }, "Specify true/false depending if the dataset file(s) have a header row.",
new Argument<bool>(defaultValue: true));

Option Cache() =>
new Option(new List<string>() { "--cache" }, "Specify on/off/auto if you want cache to be turned on, off or auto determined.",
new Option(new List<string>() { "--cache", "-c" }, "Specify on/off/auto if you want cache to be turned on, off or auto determined.",
new Argument<string>(defaultValue: "auto").FromAmong(GetCacheSuggestions()));

// This is a temporary hack to work around having comma separated values for argument. This feature needs to be enabled in the parser itself.
Option IgnoreColumns() =>
new Option(new List<string>() { "--ignore-columns" }, "Specify the columns that needs to be ignored in the given dataset.",
new Option(new List<string>() { "--ignore-columns", "-I" }, "Specify the columns that needs to be ignored in the given dataset.",
new Argument<List<string>>(symbolResult =>
{
try
Expand Down
2 changes: 1 addition & 1 deletion src/mlnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void Main(string[] args)

var parser = new CommandLineBuilder()
// parser
.AddCommand(CommandDefinitions.New(handler))
.AddCommand(CommandDefinitions.AutoTrain(handler))
.UseDefaults()
.Build();

Expand Down
6 changes: 6 additions & 0 deletions src/mlnet/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,10 @@
<data name="LearningHttpLink" xml:space="preserve">
<value>https://aka.ms/mlnet-cli</value>
</data>
<data name="WaitingForFirstIteration" xml:space="preserve">
<value>Waiting for the first iteration to complete ...</value>
</data>
<data name="WaitingForLastIteration" xml:space="preserve">
<value>Waiting for the last iteration to complete ...</value>
</data>
</root>
Loading

0 comments on commit ffd773b

Please sign in to comment.