Skip to content

Commit

Permalink
Enable MSML_ParameterLocalVarName for the full solution (#4833)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Feb 13, 2020
1 parent 333f765 commit 229ef37
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 199 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ dotnet_diagnostic.MSML_NoBestFriendInternal.severity = none
# MSML_NoInstanceInitializers: No initializers on instance fields or properties
dotnet_diagnostic.MSML_NoInstanceInitializers.severity = none

# MSML_ParameterLocalVarName: Parameter or local variable name not standard
dotnet_diagnostic.MSML_ParameterLocalVarName.severity = none

[test/Microsoft.ML.CodeAnalyzer.Tests/**.cs]
# BaseTestClass does not apply for analyzer testing.
# MSML_ExtendBaseTestClass: Test classes should be derived from BaseTestClass
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.Extensions.ML.Tests/UriLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void no_reload_no_change()

class UriLoaderMock : UriModelLoader
{
public Func<Uri, string, bool> ETagMatches { get; set; } = (_, __) => false;
public Func<Uri, string, bool> ETagMatches { get; set; } = delegate { return false; };

public UriLoaderMock(IOptions<MLOptions> contextOptions,
ILogger<UriModelLoader> logger) : base(contextOptions, logger)
Expand Down
6 changes: 3 additions & 3 deletions test/Microsoft.ML.AutoML.Tests/UserInputValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ public void ValidateFeaturesColInvalidType()
[Fact]
public void ValidateTextColumnNotText()
{
const string TextPurposeColName = "TextColumn";
const string textPurposeColName = "TextColumn";
var schemaBuilder = new DataViewSchema.Builder();
schemaBuilder.AddColumn(DefaultColumnNames.Features, NumberDataViewType.Single);
schemaBuilder.AddColumn(DefaultColumnNames.Label, NumberDataViewType.Single);
schemaBuilder.AddColumn(TextPurposeColName, NumberDataViewType.Single);
schemaBuilder.AddColumn(textPurposeColName, NumberDataViewType.Single);
var schema = schemaBuilder.ToSchema();
var dataView = DataViewTestFixture.BuildDummyDataView(schema);

var columnInfo = new ColumnInformation();
columnInfo.TextColumnNames.Add(TextPurposeColName);
columnInfo.TextColumnNames.Add(textPurposeColName);

foreach (var task in new[] { TaskKind.Recommendation, TaskKind.Regression })
{
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.ML.Benchmarks/ImageClassificationBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ public static void UnZip(String gzArchiveName, String destFolder)

public static string GetAbsolutePath(string relativePath)
{
FileInfo _dataRoot = new FileInfo(typeof(
FileInfo dataRoot = new FileInfo(typeof(
ImageClassificationBench).Assembly.Location);

string assemblyFolderPath = _dataRoot.Directory.FullName;
string assemblyFolderPath = dataRoot.Directory.FullName;

string fullPath = Path.Combine(assemblyFolderPath, relativePath);

Expand Down
12 changes: 6 additions & 6 deletions test/Microsoft.ML.Benchmarks/PredictionEngineBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void SetupIrisPipeline()
PetalWidth = 5.1f,
};

string _irisDataPath = BaseTestClass.GetDataPath("iris.txt");
string irisDataPath = BaseTestClass.GetDataPath("iris.txt");

var env = new MLContext(seed: 1);

Expand All @@ -53,7 +53,7 @@ public void SetupIrisPipeline()
};
var loader = new TextLoader(env, options: options);

IDataView data = loader.Load(_irisDataPath);
IDataView data = loader.Load(irisDataPath);

var pipeline = new ColumnConcatenatingEstimator(env, "Features", new[] { "SepalLength", "SepalWidth", "PetalLength", "PetalWidth" })
.Append(env.Transforms.Conversion.MapValueToKey("Label"))
Expand All @@ -73,7 +73,7 @@ public void SetupSentimentPipeline()
SentimentText = "Not a big fan of this."
};

string _sentimentDataPath = BaseTestClass.GetDataPath("wikipedia-detox-250-line-data.tsv");
string sentimentDataPath = BaseTestClass.GetDataPath("wikipedia-detox-250-line-data.tsv");

var mlContext = new MLContext(seed: 1);

Expand All @@ -89,7 +89,7 @@ public void SetupSentimentPipeline()
};
var loader = new TextLoader(mlContext, options: options);

IDataView data = loader.Load(_sentimentDataPath);
IDataView data = loader.Load(sentimentDataPath);

var pipeline = mlContext.Transforms.Text.FeaturizeText("Features", "SentimentText")
.Append(mlContext.BinaryClassification.Trainers.SdcaNonCalibrated(
Expand All @@ -108,7 +108,7 @@ public void SetupBreastCancerPipeline()
Features = new[] { 5f, 1f, 1f, 1f, 2f, 1f, 3f, 1f, 1f }
};

string _breastCancerDataPath = BaseTestClass.GetDataPath("breast-cancer.txt");
string breastCancerDataPath = BaseTestClass.GetDataPath("breast-cancer.txt");

var env = new MLContext(seed: 1);

Expand All @@ -124,7 +124,7 @@ public void SetupBreastCancerPipeline()
};
var loader = new TextLoader(env, options: options);

IDataView data = loader.Load(_breastCancerDataPath);
IDataView data = loader.Load(breastCancerDataPath);

var pipeline = env.BinaryClassification.Trainers.SdcaNonCalibrated(
new SdcaNonCalibratedBinaryTrainer.Options { NumberOfThreads = 1, ConvergenceTolerance = 1e-2f, });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ private float NextFloat(Random rand, int expRange)
private int GetSeed()
{
int seed = DefaultSeed;
string CPUMATH_SEED = Environment.GetEnvironmentVariable("CPUMATH_SEED");
string cpumathSeed = Environment.GetEnvironmentVariable("CPUMATH_SEED");

if (CPUMATH_SEED != null)
if (cpumathSeed != null)
{
if (!int.TryParse(CPUMATH_SEED, out seed))
if (!int.TryParse(cpumathSeed, out seed))
{
if (string.Equals(CPUMATH_SEED, "random", StringComparison.OrdinalIgnoreCase))
if (string.Equals(cpumathSeed, "random", StringComparison.OrdinalIgnoreCase))
{
seed = new Random().Next();
}
Expand Down
8 changes: 4 additions & 4 deletions test/Microsoft.ML.NugetPackageVersionUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ private static void UpdatePackageVersion(string projectFiles, IDictionary<string

foreach (var projectFilePath in projectFilePaths)
{
var CsprojDoc = new XmlDocument();
CsprojDoc.Load(projectFilePath);
var csprojDoc = new XmlDocument();
csprojDoc.Load(projectFilePath);

var packageReferenceNodes = CsprojDoc.DocumentElement.SelectNodes(packageReferencePath);
var packageReferenceNodes = csprojDoc.DocumentElement.SelectNodes(packageReferencePath);

for (int i = 0; i < packageReferenceNodes.Count; i++)
{
Expand All @@ -75,7 +75,7 @@ private static void UpdatePackageVersion(string projectFiles, IDictionary<string
Console.WriteLine($"Can't find newer version of Package {packageName} from NuGet source, don't need to update version.");
}

CsprojDoc.Save(projectFilePath);
csprojDoc.Save(projectFilePath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed class FastTreeParallelInterfaceChecker : Trainers.FastTree.IPara
private bool _isInitTreeLearner = false;
private bool _isInitIteration = false;
private bool _isCache = false;
public void CacheHistogram(bool isSmallerLeaf, int featureIdx, int subfeature, SufficientStatsBase sufficientStatsBase, bool HasWeights)
public void CacheHistogram(bool isSmallerLeaf, int featureIdx, int subfeature, SufficientStatsBase sufficientStatsBase, bool hasWeights)
{
Assert.True(_isInitEnv);
Assert.True(_isInitTreeLearner);
Expand Down
20 changes: 10 additions & 10 deletions test/Microsoft.ML.TestFramework/RemoteExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,35 @@ private static void RemoteInvoke(MethodInfo method, string[] args, RemoteInvokeO
CheckProcess(Process.Start(psi), options);
}

private static void CheckProcess(Process process, RemoteInvokeOptions Options)
private static void CheckProcess(Process process, RemoteInvokeOptions options)
{
if (process != null)
{
// A bit unorthodox to do throwing operations in a Dispose, but by doing it here we avoid
// needing to do this in every derived test and keep each test much simpler.
try
{
Assert.True(process.WaitForExit(Options.TimeOut),
$"Timed out after {Options.TimeOut}ms waiting for remote process {process.Id}");
Assert.True(process.WaitForExit(options.TimeOut),
$"Timed out after {options.TimeOut}ms waiting for remote process {process.Id}");

if (File.Exists(Options.ExceptionFile))
if (File.Exists(options.ExceptionFile))
{
throw new RemoteExecutionException(File.ReadAllText(Options.ExceptionFile));
throw new RemoteExecutionException(File.ReadAllText(options.ExceptionFile));
}

if (Options.CheckExitCode)
if (options.CheckExitCode)
{
int expected = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Options.ExpectedExitCode : unchecked((sbyte)Options.ExpectedExitCode);
int expected = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? options.ExpectedExitCode : unchecked((sbyte)options.ExpectedExitCode);
int actual = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? process.ExitCode : unchecked((sbyte)process.ExitCode);

Assert.True(expected == actual, $"Exit code was {process.ExitCode} but it should have been {Options.ExpectedExitCode}");
Assert.True(expected == actual, $"Exit code was {process.ExitCode} but it should have been {options.ExpectedExitCode}");
}
}
finally
{
if (File.Exists(Options.ExceptionFile))
if (File.Exists(options.ExceptionFile))
{
File.Delete(Options.ExceptionFile);
File.Delete(options.ExceptionFile);
}

// Cleanup
Expand Down
10 changes: 5 additions & 5 deletions test/Microsoft.ML.Tests/OnnxSequenceTypeWithAttributesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public void OnnxSequenceTypeWithColumnNameAttributeTest()

FloatInput input = new FloatInput() { Input = new float[] { 1.0f, 2.0f, 3.0f } };
var output = predictor.Predict(input);
var onnx_out = output.Output.FirstOrDefault();
Assert.True(onnx_out.Count == 3, "Output missing data.");
var keys = new List<string>(onnx_out.Keys);
for(var i =0; i < onnx_out.Count; ++i)
var onnxOut = output.Output.FirstOrDefault();
Assert.True(onnxOut.Count == 3, "Output missing data.");
var keys = new List<string>(onnxOut.Keys);
for(var i =0; i < onnxOut.Count; ++i)
{
Assert.Equal(onnx_out[keys[i]], input.Input[i]);
Assert.Equal(onnxOut[keys[i]], input.Input[i]);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void TensorFlowTransforCifarEndToEndTest2()
{
var imageHeight = 32;
var imageWidth = 32;
var model_location = "cifar_model/frozen_model.pb";
var modelLocation = "cifar_model/frozen_model.pb";
var dataFile = GetDataPath("images/images.tsv");
var imageFolder = Path.GetDirectoryName(dataFile);

Expand All @@ -125,7 +125,7 @@ public void TensorFlowTransforCifarEndToEndTest2()
var pipeEstimator = new ImageLoadingEstimator(mlContext, imageFolder, ("ImageReal", "ImagePath"))
.Append(new ImageResizingEstimator(mlContext, "ImageCropped", imageHeight, imageWidth, "ImageReal"))
.Append(new ImagePixelExtractingEstimator(mlContext, "Input", "ImageCropped", interleavePixelColors: true))
.Append(mlContext.Model.LoadTensorFlowModel(model_location).ScoreTensorFlowModel("Output", "Input"))
.Append(mlContext.Model.LoadTensorFlowModel(modelLocation).ScoreTensorFlowModel("Output", "Input"))
.Append(new ColumnConcatenatingEstimator(mlContext, "Features", "Output"))
.Append(new ValueToKeyMappingEstimator(mlContext, "Label"))
.AppendCacheCheckpoint(mlContext)
Expand Down Expand Up @@ -345,7 +345,7 @@ private class TypesData
public void TensorFlowTransformInputOutputTypesTest()
{
// This an identity model which returns the same output as input.
var model_location = "model_types_test";
var modelLocation = "model_types_test";

//Data
var data = new List<TypesData>(
Expand Down Expand Up @@ -382,7 +382,7 @@ public void TensorFlowTransformInputOutputTypesTest()

var inputs = new string[] { "f64", "f32", "i64", "i32", "i16", "i8", "u64", "u32", "u16", "u8", "b" };
var outputs = new string[] { "o_f64", "o_f32", "o_i64", "o_i32", "o_i16", "o_i8", "o_u64", "o_u32", "o_u16", "o_u8", "o_b" };
var trans = mlContext.Model.LoadTensorFlowModel(model_location).ScoreTensorFlowModel(outputs, inputs).Fit(loader).Transform(loader); ;
var trans = mlContext.Model.LoadTensorFlowModel(modelLocation).ScoreTensorFlowModel(outputs, inputs).Fit(loader).Transform(loader); ;

using (var cursor = trans.GetRowCursorForAllColumns())
{
Expand Down Expand Up @@ -546,8 +546,8 @@ public void TensorFlowTransformInceptionTest()
public void TensorFlowInputsOutputsSchemaTest()
{
var mlContext = new MLContext(seed: 1);
var model_location = "mnist_model/frozen_saved_model.pb";
var schema = TensorFlowUtils.GetModelSchema(mlContext, model_location);
var modelLocation = "mnist_model/frozen_saved_model.pb";
var schema = TensorFlowUtils.GetModelSchema(mlContext, modelLocation);
Assert.Equal(86, schema.Count);
Assert.True(schema.TryGetColumnIndex("Placeholder", out int col));
var type = (VectorDataViewType)schema[col].Type;
Expand Down Expand Up @@ -607,8 +607,8 @@ public void TensorFlowInputsOutputsSchemaTest()
Assert.Equal(1, inputOps.Length);
Assert.Equal("sequential/dense_1/BiasAdd", inputOps.GetValues()[0].ToString());

model_location = "model_matmul/frozen_saved_model.pb";
schema = TensorFlowUtils.GetModelSchema(mlContext, model_location);
modelLocation = "model_matmul/frozen_saved_model.pb";
schema = TensorFlowUtils.GetModelSchema(mlContext, modelLocation);
char name = 'a';
for (int i = 0; i < schema.Count; i++)
{
Expand Down Expand Up @@ -663,7 +663,7 @@ public void TensorFlowTransformMNISTLRTrainingTest()
{
const double expectedMicroAccuracy = 0.72173913043478266;
const double expectedMacroAccruacy = 0.67482993197278918;
var model_location = "mnist_lr_model";
var modelLocation = "mnist_lr_model";
try
{
var mlContext = new MLContext(seed: 1);
Expand All @@ -686,7 +686,7 @@ public void TensorFlowTransformMNISTLRTrainingTest()
labelColumnName: "OneHotLabel",
dnnLabel: "Label",
optimizationOperation: "SGDOptimizer",
modelPath: model_location,
modelPath: modelLocation,
lossOperation: "Loss",
epoch: 10,
learningRateOperation: "SGDOptimizer/learning_rate",
Expand Down Expand Up @@ -724,16 +724,16 @@ public void TensorFlowTransformMNISTLRTrainingTest()
{
// This test changes the state of the model.
// Cleanup folder so that other test can also use the same model.
CleanUp(model_location);
CleanUp(modelLocation);
}
}

private void CleanUp(string model_location)
private void CleanUp(string modelLocation)
{
var directories = Directory.GetDirectories(model_location, "variables-*");
var directories = Directory.GetDirectories(modelLocation, "variables-*");
if (directories != null && directories.Length > 0)
{
var varDir = Path.Combine(model_location, "variables");
var varDir = Path.Combine(modelLocation, "variables");
if (Directory.Exists(varDir))
Directory.Delete(varDir, true);
Directory.Move(directories[0], varDir);
Expand Down
Loading

0 comments on commit 229ef37

Please sign in to comment.