Exemple #1
0
        /// <returns>True if item was added. False if it already existed in the range.</returns>
        override public bool TryAdd(Dictionary <string, string> row, string fileName)
        {
            Helper.CheckCondition(row.ContainsKey("rowIndex"), string.Format(@"When auditing tabulation a ""rowIndex"" column is required. (File ""{0}"")", fileName));
            Helper.CheckCondition(row.ContainsKey("rowCount"), string.Format(@"When auditing tabulation a ""rowCount"" column is required. (File ""{0}"")", fileName));

            RangeCollection rowIndexRange = RangeCollection.Parse(row["rowIndex"]);
            long            rowCount      = long.Parse(row["rowCount"]);

            Helper.CheckCondition(rowIndexRange.IsBetween(0, rowCount - 1), string.Format(@"rowIndex must be at least zero and less than rowCount (File ""{0}"")", fileName));
            if (RowCountSoFar == long.MinValue)
            {
                RowCountSoFar = rowCount;
            }
            else
            {
                Helper.CheckCondition(RowCountSoFar == rowCount, string.Format("A different row count was at rowIndex {0} in file {1}", rowIndexRange, fileName));
            }

            bool tryAdd = RowIndexRangeCollection.TryAddRangeCollection(rowIndexRange);

            return(tryAdd);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try {
                // before using the ArgCollection class, let the DigipedeClient grab its args.
                DigipedeClient client = new DigipedeClient();
                args = client.ProcessArguments(args, true);
                ArgCollection argCollection = ArgCollection.GetInstance(args);

                // show help, if requested
                if (argCollection.ExtractOptionalFlag("help"))
                {
                    Console.WriteLine("");
                    Console.WriteLine(UsageMessage);
                    Console.WriteLine(HelpMessage);
                    return;
                }

                // fail if the DigipedeClient doesn't have the args
                SpecialFunctions.CheckCondition(client.IsInitialized, "Digipede Client didn't initialize.");



                string keepTestName = argCollection.ExtractOptional("keepTest", "AlwaysKeep");
                string skipRowIndexFileNameOrNull = argCollection.ExtractOptional <string>("skipRowIndexFile", null);
                string optimizerName = argCollection.ExtractOptional("optimizer", "BrentThenGrid");

                argCollection.CheckNoMoreOptions();

                int pieceCount = argCollection.ExtractNext <int>("pieceCount");
                //int taskPerJobCount = argCollection.ExtractNext<int>("taskPerJobCount");  -- we're not using this -- keep it in case we want to put it back
                string          treeFileName          = argCollection.ExtractNext <string>("treeFile");
                string          predictorFileName     = argCollection.ExtractNext <string>("predictorFile");
                string          targetFileName        = argCollection.ExtractNext <string>("targetFile");
                string          leafDistributionName  = argCollection.ExtractNext <string>("leafDistribution");
                string          nullDataGeneratorName = argCollection.ExtractNext <string>("nullDataGenerator");
                string          niceName                 = argCollection.ExtractNext <string>("niceName");
                string          outputDirectoryName      = argCollection.ExtractNext <string>("outputDirectory");
                RangeCollection nullIndexRangeCollection = argCollection.ExtractNext <RangeCollection>("nullIndexRange");
                SpecialFunctions.CheckCondition(nullIndexRangeCollection.IsBetween(-1, int.MaxValue), "nullIndex must be at least -1");

                argCollection.CheckThatEmpty();

                Directory.CreateDirectory(outputDirectoryName);

                // Define a JobTemplate for PhyloD.
                JobTemplate jobTemplate = CreateJobTemplate();
                // Require 32 bit (ensures we use WOW64 on 64-bit machines) since SpecialFunctions.dll built for x86.
                jobTemplate.Control.UseWow64On64Bit = true;
                // allow task failures (all but one failure will result in job success)
                jobTemplate.JobDefaults.MaxFailures = pieceCount - 1;
                // allow multiple concurrent tasks (one for each core); each isolated in its own process.
                jobTemplate.Control.Concurrency           = ApplicationConcurrency.MultiplePerCore;
                jobTemplate.Control.ProcessHostingOptions = HostingOptions.ManySingleUse;


                // create a Job based on that JobTemplate
                Job job = jobTemplate.NewJob();

                // add job-specific data / files
                FileDefCollection fileDefs = job.FileDefs;
                // files
                Utility.GetNamedFileDef(fileDefs, Constants.TreeFileDefName).RemoteName      = treeFileName;
                Utility.GetNamedFileDef(fileDefs, Constants.PredictorFileDefName).RemoteName = predictorFileName;
                Utility.GetNamedFileDef(fileDefs, Constants.TargetFileDefName).RemoteName    = targetFileName;
                // skipRowIndex file is more complicated because it may not exist, but the JobTemplate requires it.
                FileDef fileDef = Utility.GetNamedFileDef(fileDefs, Constants.SkipRowIndexFileDefName);
                if (skipRowIndexFileNameOrNull == null || skipRowIndexFileNameOrNull == "null")
                {
                    // stream an empty file
                    fileDef.Stream = new MemoryStream(0);
                }
                else
                {
                    // stream the actual file
                    fileDef.LocalName = skipRowIndexFileNameOrNull;
                }

                // Create the tasks for the template
                for (int pieceIndex = 0; pieceIndex < pieceCount; pieceIndex++)
                {
                    // Create a Task for this piece
                    Task task = job.NewTask();
                    // Create an InputData object to encapsulate all input data in one place
                    InputData inputData = new InputData(optimizerName, keepTestName, leafDistributionName, nullDataGeneratorName,
                                                        niceName, outputDirectoryName, pieceIndex, pieceCount, nullIndexRangeCollection.ToString());
                    // create a Worker for this task
                    task.Worker = new PhyloDWorker(inputData);
                }

                // Wire events to catch result data.  Note that retrieving data isn't necessary here --
                // data can be requested in a server call from another process.
                job.TaskCompleted += job_TaskCompleted;

                // Write an event to catch any monitoring errors
                client.MonitoringError += client_MonitoringError;

                // submit the job
                SubmissionResult sr = client.SubmitJob(jobTemplate, job);
                Console.WriteLine("Submitted job {0} with {1} tasks.", sr.JobId, job.Tasks.Count);

                // wait for the result
                JobStatusSummary jss = client.WaitForJobWithStatus(sr.JobId);
                Console.WriteLine("Job finished with status of {0}", jss.Status);
            }
            catch (Exception exception)
            {
                Console.WriteLine("");
                Console.WriteLine(exception.Message);
                if (exception.InnerException != null)
                {
                    Console.WriteLine(exception.InnerException.Message);
                }

                Console.WriteLine("");
                Console.WriteLine(UsageMessage);
                throw;
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            try
            {
                ArgCollection argCollection = ArgCollection.GetInstance(args);

                if (argCollection.ExtractOptionalFlag("help"))
                {
                    Console.WriteLine("");
                    Console.WriteLine(UsageMessage);
                    Console.WriteLine(HelpMessage);
                    return;
                }

                string optimizerName = argCollection.ExtractOptional <string>("optimizer", "BrentThenGrid");
                string keepTestName  = argCollection.ExtractOptional <string>("keepTest", "AlwaysKeep");
                string skipRowIndexFileNameOrNull = argCollection.ExtractOptional <string>("skipRowIndexFile", null);

                argCollection.CheckNoMoreOptions();

                string          treeFileName          = argCollection.ExtractNext <string>("treeFile");
                string          predictorFileName     = argCollection.ExtractNext <string>("predictorFile");
                string          targetFileName        = argCollection.ExtractNext <string>("targetFile");
                string          leafDistributionName  = argCollection.ExtractNext <string>("leafDistribution");
                string          nullDataGeneratorName = argCollection.ExtractNext <string>("nullDataGenerator");
                string          niceName                  = argCollection.ExtractNext <string>("niceName");
                string          outputDirectory           = argCollection.ExtractNext <string>("outputDirectory");
                RangeCollection pieceIndexRangeCollection = argCollection.ExtractNext <RangeCollection>("pieceIndexRange");
                int             pieceCount                = argCollection.ExtractNext <int>("pieceCount");
                RangeCollection nullIndexRangeCollection  = argCollection.ExtractNext <RangeCollection>("nullIndexRange");

                argCollection.CheckThatEmpty();

                if (!PhyloDDriver.ValidateDistribution(leafDistributionName))
                {
                    Console.WriteLine("{0} is not a recognized distribution name. Please choose a name from the following list:", leafDistributionName);
                    foreach (string name in PhyloDDriver.GetDistributionNames())
                    {
                        Console.WriteLine("\t{0}", name);
                    }
                    throw new ArgumentException("Invalid distribution name.");
                }
                RangeCollection skipRowIndexRangeCollectionOrNull = (null == skipRowIndexFileNameOrNull) || skipRowIndexFileNameOrNull == "null" ? null : RangeCollection.Parse(File.ReadAllText(skipRowIndexFileNameOrNull));
                KeepTest <Dictionary <string, string> > keepTest  = KeepTest <Dictionary <string, string> > .GetInstance(null, keepTestName);

                SpecialFunctions.CheckCondition(pieceIndexRangeCollection.IsBetween(0, pieceCount - 1), "pieceIndex must be at least 0 and less than pieceCount");
                SpecialFunctions.CheckCondition(nullIndexRangeCollection.IsBetween(-1, int.MaxValue), "nullIndex must be at least -1");

                PhyloTree aPhyloTree = PhyloTree.GetInstance(treeFileName, null);

                ModelScorer    modelScorer    = ModelScorer.GetInstance(aPhyloTree, leafDistributionName, optimizerName);
                ModelEvaluator modelEvaluator = ModelEvaluator.GetInstance(leafDistributionName, modelScorer);
                PhyloDDriver   driver         = PhyloDDriver.GetInstance();

                driver.Run(
                    modelEvaluator,
                    predictorFileName, targetFileName,
                    leafDistributionName, nullDataGeneratorName,
                    keepTest, skipRowIndexRangeCollectionOrNull,
                    niceName,
                    outputDirectory,
                    pieceIndexRangeCollection, pieceCount,
                    nullIndexRangeCollection,
                    optimizerName);

                //Console.Write("Press enter to exist.");
                //Console.Read();
            }
            catch (Exception exception)
            {
                Console.WriteLine("");
                Console.WriteLine(exception.Message);
                if (exception.InnerException != null)
                {
                    Console.WriteLine(exception.InnerException.Message);
                }

                Console.WriteLine("");
                Console.WriteLine(UsageMessage);
                throw;
            }
        }