public void ResetSimulation()
        {
            if (_hs == null || _recurrenceVector == null)
            {
                throw new Exception("Cannot reset simulation because it has not yet been initialized.");
            }

            _totalStepCount             = 0;
            _currentStep                = (IHSExplicitVectorValue <HSEdgeState>)(IHSExplicitVector <HSEdgeState> .ZeroVector(_hs) + __qwGetStartVector(IQGVertex.StartVertex));
            this.CurrentSimulationState = new QwasiEvaluationState(_currentStep, _totalStepCount);

            this.RaiseSimulationStartedEvent(new QwasiSimulationStepEventArgs(this.CurrentSimulationState, 0, _totalStepCount));
            this.ApplySimulationGraphVisualizations();
        }
        public QwasiAnalyticsData CompileAnalytics(int stepInterval, int stepRangeStart, int stepRangeEnd)
        {
            if (stepRangeEnd < stepRangeStart)
            {
                return(new QwasiAnalyticsData());
            }

            __initializeMath();
            _currentStep = (IHSExplicitVectorValue <HSEdgeState>)(IHSExplicitVector <HSEdgeState> .ZeroVector(_hs) + __qwGetStartVector(IQGVertex.StartVertex));
            QwasiAnalyticsData analyticsData = new QwasiAnalyticsData()
            {
                StepInterval = stepInterval, MaxStepValue = 0
            };
            QwasiEvaluationState currentState = new QwasiEvaluationState(__performStepOperation(stepRangeStart), stepRangeStart);

            analyticsData.StateEvaluationList.Add(currentState);

            int stepCount;

            for (stepCount = stepRangeStart; stepCount + stepInterval <= stepRangeEnd; stepCount += stepInterval)
            {
                currentState = new QwasiEvaluationState(__performStepOperation(stepInterval), stepCount + stepInterval);
                analyticsData.StateEvaluationList.Add(currentState);
            }
            analyticsData.MaxStepValue = stepCount;

            List <QGEdge> updatedEdges = new List <QGEdge>();

            foreach (HSEdgeState edgeState in analyticsData.BasisStates)
            {
                QGEdge edge = edgeState.Vertex1.GetEdge(edgeState.Vertex2);
                if (updatedEdges.Contains(edge))
                {
                    continue;
                }

                this.AnalyticsEdgeLabels[edge].LoadAnalyticsData(analyticsData);

                updatedEdges.Add(edge);
            }

            this.CurrentAnalyticsData = analyticsData;
            this.RaiseAnalyticsDataCompiledEvent(new QwasiAnalyticsEventArgs(analyticsData));

            return(analyticsData);
        }
        private void __exitSimulationMode()
        {
            foreach (var kvp in this.SimulationEdgeLabels)
            {
                kvp.Value.Unpin();
                __unbindSimulationEdgeLabelEvents(kvp.Key);
            }

            foreach (QGEdge edge in this.AllEdges)
            {
                edge.ReleaseColorOverride();
            }

            _hs = null;
            _recurrenceVector           = null;
            _currentStep                = null;
            this.CurrentSimulationState = null;
        }
        public void EvaluateSimulationStep(int stepCount)
        {
            if (_recurrenceVector == null)
            {
                throw new Exception("The recurrence relation for the step function has not been created.");
            }

            if (_currentStep == null)
            {
                throw new Exception("The start vector for the compiled Hilbert space has not been determined.");
            }

            _totalStepCount            += stepCount;
            this.CurrentSimulationState = new QwasiEvaluationState(__performStepOperation(stepCount), _totalStepCount);

            this.RaiseSimulationStepPerformedEvent(new QwasiSimulationStepEventArgs(this.CurrentSimulationState, stepCount, _totalStepCount));
            this.ApplySimulationGraphVisualizations();
        }
        private IEnumerable <(double Coef, int StepNumber)> __downsampleData(HSEdgeState basisState, int sampleCount)
        {
            double dataPointsPerSample = (double)this.LoadedAnalyticsData.StateEvaluationCount / (double)sampleCount;

            int j = 0;

            for (int i = 1; i <= sampleCount; i++)
            {
                int samplePoint = (int)Math.Round(((double)i) * dataPointsPerSample);

                double pointMax       = 0;
                int    firstStepValue = this.LoadedAnalyticsData.StateEvaluationList[j].StepNumber;
                for (; j < samplePoint; j++)
                {
                    QwasiEvaluationState es = this.LoadedAnalyticsData.StateEvaluationList[j];
                    pointMax = Math.MaxMagnitude(pointMax, es.GetCoefficient(basisState));
                }
                int lastStepValue = this.LoadedAnalyticsData.StateEvaluationList[j - 1].StepNumber;

                int retStepValue;
                if (i == 1)
                {
                    retStepValue = firstStepValue;
                }
                else if (i == sampleCount)
                {
                    retStepValue = lastStepValue;
                }
                else
                {
                    retStepValue = (int)Math.Floor(((double)firstStepValue + (double)lastStepValue) / 2d);
                }

                yield return(pointMax, retStepValue);
            }
        }
 public QwasiSimulationStepEventArgs(QwasiEvaluationState simulationState, int opStepCount, int totalStepCount)
 {
     this.SimulationState      = simulationState;
     this.StepCountOfOperation = opStepCount;
     this.TotalStepCount       = totalStepCount;
 }