public void PlannerRespectsTaskOrder() { var planner = new MyDefaultExecutionPlanner(); var taskOrderNode = new TaskOrderNode(); MyNodeInfo.CollectNodeInfo(taskOrderNode.GetType()); MyExecutionBlock execBlock = planner.CreateNodeExecutionPlan(taskOrderNode, initPhase: false); var lastOrder = -1; foreach (IMyExecutable task in execBlock.Children) { var taskInfo = task.GetType().GetCustomAttribute <MyTaskInfoAttribute>(true); if (taskInfo == null) { continue; } Assert.True(lastOrder <= taskInfo.Order, "Task order must be greater or equal to the previous task order"); lastOrder = taskInfo.Order; } }
public virtual MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan) { if (!m_isAfterChangeModelExecute) { // this if is true at the beginning of simulation return(defaultPlan); } m_isAfterChangeModelExecute = false; var executionPlanner = TypeMap.GetInstance <IMyExecutionPlanner>(); IMyExecutable[] thisWorldTasks = defaultPlan.Children; var blocks = new List <IMyExecutable>(); // The default plan will only contain one block with: signals in, world tasks, signals out. blocks.Add(thisWorldTasks.First()); blocks.Add(AdapterInputStep); var worldPlan = executionPlanner.CreateNodeExecutionPlan(CurrentWorld.World, false); blocks.AddRange(worldPlan.Children.Where(x => x != CurrentWorld.GetWorldRenderTask())); blocks.Add(LearningStep); blocks.Add(CurrentWorld.GetWorldRenderTask()); blocks.Add(AdapterOutputStep); blocks.Add(thisWorldTasks.Last()); return(new MyExecutionBlock(blocks.ToArray())); }
public virtual MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan) { switch (LoopType) { case MyLoopOperation.All: { var res = new MyLoopBlock( x => x < Iterations, new MyExecutionBlock( m_oneShotTasks, defaultPlan ) ); return(res); } case MyLoopOperation.Normal: default: { return(new MyLoopBlock( x => x < Iterations, defaultPlan )); } } }
public void PlannerKeepsOrderOfTasksWithoutOrderAttribute() { var planner = new MyDefaultExecutionPlanner(); var unorderedTasksNode = new UnorderedTasksNode(); MyNodeInfo.CollectNodeInfo(unorderedTasksNode.GetType()); MyExecutionBlock execBlock = planner.CreateNodeExecutionPlan(unorderedTasksNode, initPhase: false); // This is maybe a bit fragile. Remove the test if it breaks due to unrelated and intended changes. Assert.Equal("CherryTask", execBlock.Children[1].Name); Assert.Equal("BananaTask", execBlock.Children[2].Name); Assert.Equal("AppleTask", execBlock.Children[3].Name); }
public MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan) { //get rid of signal tasks IMyExecutable[] content = new IMyExecutable[defaultPlan.Children.Length - 2]; Array.Copy(defaultPlan.Children, 1, content, 0, defaultPlan.Children.Length - 2); //place if block inside return(new MyExecutionBlock( defaultPlan.Children[0], new MyIfBlock(IsActive, content), defaultPlan.Children.Last()) { Name = defaultPlan.Name }); }
public virtual MyExecutionBlock CreateCustomInitPhasePlan(MyExecutionBlock defaultInitPhasePlan) { m_oneShotTasks = defaultInitPhasePlan; switch (LoopType) { case MyLoopOperation.All: { return(new MyExecutionBlock()); } case MyLoopOperation.Normal: default: { return(defaultInitPhasePlan); } } }
void SimulationHandler_StateChanged(object sender, MySimulationHandler.StateEventArgs e) { MySimulationHandler simulationHandler = sender as MySimulationHandler; runToolButton.Enabled = simulationHandler.CanStart; stepInButton.Enabled = simulationHandler.CanStepInto; stepOutButton.Enabled = simulationHandler.CanStepOut; stepOverButton.Enabled = simulationHandler.CanStepOver; pauseToolButton.Enabled = simulationHandler.CanPause; UpdateDebugListView(); if (e.NewState == MySimulationHandler.SimulationState.PAUSED) { if (simulationHandler.Simulation.InDebugMode) { noDebugLabel.Visible = false; MyExecutionBlock currentBlock = simulationHandler.Simulation.CurrentDebuggedBlock; m_selectedNodeView = null; if (currentBlock != null && currentBlock.CurrentChild != null) { m_selectedNodeView = debugTreeView.AllNodes.FirstOrDefault(node => (node.Tag is MyDebugNode && (node.Tag as MyDebugNode).Executable == currentBlock.CurrentChild)); } ; } debugTreeView.Invalidate(); //debugTreeView.Invoke((MethodInvoker)(() => debugTreeView.SelectedNode = m_selectedNodeView)); } else if (e.NewState == MySimulationHandler.SimulationState.STOPPED) { m_executionPlan = null; debugTreeView.Model = null; noDebugLabel.Visible = true; if (this.IsFloat) { this.Hide(); } } breakpointCheckBox.EditEnabled = simulationHandler.Simulation.InDebugMode; }
public virtual MyExecutionBlock CreateCustomInitPhasePlan(MyExecutionBlock defaultInitPhasePlan) { if (!m_isAfterChangeModelInit) { // this if is true at the beginning of simulation return(defaultInitPhasePlan); } m_isAfterChangeModelInit = false; var executionPlanner = TypeMap.GetInstance <IMyExecutionPlanner>(); MyExecutionBlock plan = executionPlanner.CreateNodeExecutionPlan(CurrentWorld.World, true); // add init tasks that initialize the adapter, but not the InitSchool task, // which should be run only once at the very beginning var blocks = new List <IMyExecutable>(); blocks.AddRange(defaultInitPhasePlan.Children.Where(x => x != InitSchool)); MyExecutionBlock initPhasePlanPruned = new MyExecutionBlock(blocks.ToArray()); return(new MyExecutionBlock(initPhasePlanPruned, plan, LearningStep)); }
public MyExecutionBlock CreateCustomInitPhasePlan(MyExecutionBlock defaultInitPhasePlan) { return(defaultInitPhasePlan); }
public MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan) { m_defaultPlan = defaultPlan; return(new MyExecutionBlock(ExecuteScript)); }
public override void Cleanup() { m_defaultPlan = null; }
public virtual MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan) { List <IMyExecutable> selected = new List <IMyExecutable>(); List <IMyExecutable> newPlan = new List <IMyExecutable>(); // copy default plan content to new plan content foreach (IMyExecutable groupTask in defaultPlan.Children) { if (groupTask is MyExecutionBlock) { foreach (IMyExecutable nodeTask in (groupTask as MyExecutionBlock).Children) { newPlan.Add(nodeTask); // add individual node tasks } } else { newPlan.Add(groupTask); // add group tasks } } // remove group backprop tasks (they should be called from the individual layers) selected = newPlan.Where(task => task is MyAbstractBackpropTask).ToList(); newPlan.RemoveAll(selected.Contains); // move MyCreateDropoutMaskTask(s) before the first MyForwardTask selected = newPlan.Where(task => task is MyCreateDropoutMaskTask).ToList(); newPlan.RemoveAll(selected.Contains); newPlan.InsertRange(newPlan.IndexOf(newPlan.Find(task => task is IMyForwardTask)), selected); // move reversed MyOutputDeltaTask(s) after the last MyForwardTask (usually there is only one) selected = newPlan.Where(task => task is IMyOutputDeltaTask).ToList(); newPlan.RemoveAll(selected.Contains); selected.Reverse(); newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected); // move reversed MyDeltaTask(s) after the last MyOutputDeltaTask selected = newPlan.Where(task => task is IMyDeltaTask).ToList(); newPlan.RemoveAll(selected.Contains); selected.Reverse(); newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyOutputDeltaTask)) + 1, selected); // move MyGradientCheckTask after the last MyDeltaTask selected = newPlan.Where(task => task is MyGradientCheckTask).ToList(); newPlan.RemoveAll(selected.Contains); newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyDeltaTask)) + 1, selected); // move MyUpdateWeightsTask(s) after the last MyGradientCheckTask selected = newPlan.Where(task => task is IMyUpdateWeightsTask).ToList(); newPlan.RemoveAll(selected.Contains); newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is MyGradientCheckTask)) + 1, selected); // move MyQLearningTask after the last MyForwardTask selected = newPlan.Where(task => task is MyQLearningTask).ToList(); newPlan.RemoveAll(selected.Contains); newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected); // move MyRestoreValuesTask after the last MyAbstractBackPropTask selected = newPlan.Where(task => task is MyRestoreValuesTask).ToList(); newPlan.RemoveAll(selected.Contains); newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyUpdateWeightsTask)) + 1, selected); // move MySaveActionTask to the end of the task list selected = newPlan.Where(task => task is MySaveActionTask).ToList(); newPlan.RemoveAll(selected.Contains); newPlan.AddRange(selected); // return new plan as MyExecutionBlock return(new MyExecutionBlock(newPlan.ToArray())); }
public virtual MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan) { List <IMyExecutable> selected = new List <IMyExecutable>(); List <IMyExecutable> newPlan = new List <IMyExecutable>(); List <IMyExecutable> BPTTSingleStep = new List <IMyExecutable>(); List <IMyExecutable> BPTTAllSteps = new List <IMyExecutable>(); // copy default plan content to new plan content foreach (IMyExecutable groupTask in defaultPlan.Children) { if (groupTask.GetType() == typeof(MyExecutionBlock)) { foreach (IMyExecutable nodeTask in (groupTask as MyExecutionBlock).Children) { newPlan.Add(nodeTask); // add individual node tasks } } else { newPlan.Add(groupTask); // add group tasks } } // remove group backprop tasks (they should be called from the individual layers) // DO NOT remove RBM tasks // DO NOT remove the currently selected backprop task (it handles batch learning) selected = newPlan.Where(task => task is MyAbstractBackpropTask && !(task.Enabled) && !(task is MyRBMLearningTask || task is MyRBMReconstructionTask)).ToList(); newPlan.RemoveAll(selected.Contains); // bbpt single step BPTTSingleStep.AddRange(newPlan.Where(task => task is IMyDeltaTask).ToList().Reverse <IMyExecutable>()); BPTTSingleStep.AddRange(newPlan.Where(task => task is MyLSTMPartialDerivativesTask).ToList()); BPTTSingleStep.AddRange(newPlan.Where(task => task is MyGradientCheckTask).ToList()); BPTTSingleStep.Add(DecrementTimeStep); // backprop until unfolded (timestep=0) MyExecutionBlock BPTTLoop = new MyLoopBlock(i => TimeStep != -1, BPTTSingleStep.ToArray() ); // if learning is globally disabled, removed update weights tasks MyExecutionBlock UpdateWeightsIfNotDisabled = new MyIfBlock(() => GetActiveBackpropTask() != null && GetActiveBackpropTask().DisableLearning == false, newPlan.Where(task => task is IMyUpdateWeightsTask).ToArray() ); if (GetActiveBackpropTask() != null && GetActiveBackpropTask().DisableLearning) { MyLog.WARNING.WriteLine("Learning is globally disabled for the network " + this.Name + " in the " + GetActiveBackpropTask().Name + " backprop task."); } // bptt architecture BPTTAllSteps.Add(BPTTLoop); BPTTAllSteps.Add(IncrementTimeStep); BPTTAllSteps.Add(RunTemporalBlocksMode); BPTTAllSteps.Add(UpdateWeightsIfNotDisabled); BPTTAllSteps.Add(DecrementTimeStep); // if current time is time for bbp, do it MyExecutionBlock BPTTExecuteBPTTIfTimeCountReachedSequenceLength = new MyIfBlock(() => TimeStep == SequenceLength - 1, BPTTAllSteps.ToArray() ); // remove group backprop tasks (they should be called from the individual layers) newPlan.RemoveAll(newPlan.Where(task => task is MyAbstractBackpropTask && !(task is MyRBMLearningTask || task is MyRBMReconstructionTask)).ToList().Contains); //TODO - include dropout in the new version of planner newPlan.RemoveAll(newPlan.Where(task => task is MyCreateDropoutMaskTask).ToList().Contains); //newPlan.RemoveAll(newPlan.Where(task => task is IMyOutputDeltaTask).ToList().Contains); newPlan.RemoveAll(newPlan.Where(task => task is IMyDeltaTask).ToList().Contains); newPlan.RemoveAll(newPlan.Where(task => task is MyGradientCheckTask).ToList().Contains); newPlan.RemoveAll(newPlan.Where(task => task is IMyUpdateWeightsTask).ToList().Contains); newPlan.RemoveAll(newPlan.Where(task => task is MyLSTMPartialDerivativesTask).ToList().Contains); newPlan.RemoveAll(newPlan.Where(task => task is MyIncrementTimeStepTask).ToList().Contains); newPlan.RemoveAll(newPlan.Where(task => task is MyDecrementTimeStepTask).ToList().Contains); newPlan.RemoveAll(newPlan.Where(task => task is MyRunTemporalBlocksModeTask).ToList().Contains); //selected = newPlan.Where(task => task is IMyOutputDeltaTask).ToList(); //newPlan.RemoveAll(selected.Contains); // after FF add deltaoutput and bptt if needed, then increment one step :) newPlan.Insert(0, IncrementTimeStep); // Move output delta tasks after all forward tasks. selected = newPlan.Where(task => task is IMyOutputDeltaTask).ToList(); newPlan.RemoveAll(selected.Contains); newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected.Reverse <IMyExecutable>()); // Move Q-learning tasks between forward tasks and output delta tasks. selected = newPlan.Where(task => task is MyQLearningTask || task is MyQLearningBatchTask).ToList(); newPlan.RemoveAll(selected.Contains); newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected.Reverse <IMyExecutable>()); newPlan.Add(BPTTExecuteBPTTIfTimeCountReachedSequenceLength); // return new plan as MyExecutionBlock return(new MyExecutionBlock(newPlan.ToArray())); }