private static QVoid ExecuteConditionalStatementInternal(QuantumProcessorDispatcher Simulator, long statement, ICallable onEqualOp, ICallable onNonEqualOp, OperationFunctor type, IQArray <Qubit>?ctrls) { bool run; run = Simulator.QuantumProcessor.RunThenClause(statement); while (run) { RunClause(onEqualOp, type, ctrls); run = Simulator.QuantumProcessor.RepeatThenClause(statement); } run = Simulator.QuantumProcessor.RunElseClause(statement); while (run) { RunClause(onNonEqualOp, type, ctrls); run = Simulator.QuantumProcessor.RepeatElseClause(statement); } Simulator.QuantumProcessor.EndConditionalStatement(statement); return(QVoid.Instance); }
public SourceLocationAttribute(string sourceFile, OperationFunctor kind, int startLine, int endLine) { this.SourceFile = sourceFile; this.SpecializationKind = kind; this.StartLine = startLine; this.EndLine = endLine; }
public void OnOperationStart(HashedString name, OperationFunctor variant, object[] qubitsTraceData) { AddToCallStack(name, variant); operationCallStack.Peek().InputWidth = qubitsTraceData.Length; operationCallStack.Peek().QubitsAllocatedAtStart = allocatedQubits; operationCallStack.Peek().MaxAllocated = allocatedQubits; }
private void TestOneProxy <I, O>(string name, string fullName, OperationFunctor variant, string signature, Operation <I, O> .DebuggerProxy proxy) { Assert.Equal(name, proxy.Name); Assert.Equal(fullName, proxy.FullName); Assert.Equal(variant, proxy.Variant); Assert.Equal(signature, proxy.Signature); }
/// <summary> /// Returns a statistic of a given metric for a top level operation. /// </summary> /// /// <param name="metric"> /// The name of the metric requested for the top level /// operation specified by <typeparamref name="T"/>. /// </param> /// /// <param name="statistic"> /// The name of a statistic of the specified metric for the specified top level operation. /// </param> /// /// <typeparam name="T"> /// The C# type corresponding to the Q# operation for which the metric is requested. /// </typeparam> /// /// <param name="functor"> /// The functor specialization of the operation for which the metric is requested. /// If not specified, this defaults to the "body" variant. /// </param> /// /// <remarks> /// For a more detailed discussion of metrics, statistics, call graph edges and /// operation specializations, see the Remarks section of the <see cref="QCTraceSimulator"/> class /// documentation. /// </remarks> public double GetMetricStatistic <T>( string metric, string statistic, OperationFunctor functor = OperationFunctor.Body) { return(GetMetricStatistic(GetOperationName <T>(), metric, statistic, functor: functor)); }
private void TestOneProxy(string name, string fullName, OperationFunctor variant, string signature, GenericCallable op) { var proxy = new GenericCallable.DebuggerProxy(op); Assert.Equal(name, proxy.Name); Assert.Equal(fullName, proxy.FullName); Assert.Equal(variant, proxy.Variant); }
/// <summary> /// Returns a statistic of a given metric associated with an edge of the call graph. /// </summary> /// /// <param name="metric"> /// The name of the metric requested for the specified call graph edge. /// </param> /// /// <param name="statistic"> /// The name of the statistic of the metric requested for a given call graph edge. /// </param> /// /// /// <typeparam name="TOperation"> /// The C# type corresponding to the Q# operation for which the metric is requested. /// </typeparam> /// /// <typeparam name="TCaller"> /// The C# type corresponding to the caller of the Q# operation for which the metric is requested. /// </typeparam> /// /// <param name="functor"> /// The functor specialization of the operation for which the metric is requested. /// If not specified, this defaults to the "body" specialization. /// </param> /// /// <param name="callerFunctor"> /// The functor specialization of the caller of the operation /// for which the metric is requested. /// If not specified, this defaults to the "body" specialization. /// </param> /// /// <remarks> /// For a more detailed discussion of metrics, statistics, call graph edges and /// operation specializations, see the Remarks section of the <see cref="QCTraceSimulator"/> class /// documentation. /// </remarks> public double GetMetricStatistic <TOperation, TCaller>( string metric, string statistic, OperationFunctor functor = OperationFunctor.Body, OperationFunctor callerFunctor = OperationFunctor.Body) { return(GetMetricStatistic(GetOperationName <TOperation>(), metric, statistic, GetOperationName <TCaller>(), functor: functor, callerFunctor: callerFunctor)); }
private void AddToCallStack(HashedString operationName, OperationFunctor variant) { operationCallStack.Push( new OperationCallRecord() { OperationName = operationName, QubitsAllocatedAtStart = allocatedQubits, Variant = variant }); }
public CallGraphEdge( HashedString operationName, HashedString operationCallerName, OperationFunctor functorSpecialization, OperationFunctor callerFunctorSpecialization) { OperationName = operationName; OperationCallerName = operationCallerName; FunctorSpecialization = functorSpecialization; CallerFunctorSpecialization = callerFunctorSpecialization; hashCode = InternalHashCode(); }
public void OnOperationStart(HashedString name, OperationFunctor functorSpecialization, object[] qubitsTraceData) { Debug.Assert(qubitsTraceData != null); OperationCallRecord opRec = new OperationCallRecord(); opRec.FunctorSpecialization = functorSpecialization; opRec.OperationName = name; opRec.InputQubitMetrics = Utils.UnboxAs <QubitTimeMetrics>(qubitsTraceData); opRec.MaxOperationStartTime = QubitsMetricsUtils.MaxQubitAvailableTime(opRec.InputQubitMetrics); opRec.MinOperationStartTime = QubitsMetricsUtils.MinQubitAvailableTime(opRec.InputQubitMetrics); operationCallStack.Push(opRec); }
protected double GetMetricStatistic( string operationName, string metric, string statistic, string callerName = CallGraphEdge.CallGraphRoot, OperationFunctor functor = OperationFunctor.Body, OperationFunctor callerFunctor = OperationFunctor.Body) { ICallGraphStatistics st = metricNameToListener[metric]; return(st.Results.GetStatistic(new CallGraphEdge((HashedString)operationName, (HashedString)callerName, functor, callerFunctor), metric, statistic)); }
private static void RunClause(ICallable op, OperationFunctor type, IQArray <Qubit>?ctrls) { switch (type) { case OperationFunctor.Body: op.Apply(QVoid.Instance); break; case OperationFunctor.Adjoint: ((IAdjointable)(op)).Adjoint.Apply(QVoid.Instance); break; case OperationFunctor.Controlled: ((IControllable)(op)).Controlled.Apply((ctrls, QVoid.Instance)); break; case OperationFunctor.ControlledAdjoint: ((IUnitary)(op)).Controlled.Adjoint.Apply((ctrls, QVoid.Instance)); break; } }
public int GetNumberOfCalls(OperationFunctor functor, T tag) { var key = Key(functor, tag); if (_log.ContainsKey(key)) { return(_log[key]); } else { return(0); } }
/// <summary> /// If a controlled functor is being used with no controls, this will change it /// to the appropriate non-controlled functor. Otherwise, the given functor is returned. /// </summary> private static OperationFunctor AdjustForNoControls(OperationFunctor type, IQArray <Qubit>?ctrls) { if (ctrls == null || ctrls.Count == 0) { type = type switch { OperationFunctor.Controlled => OperationFunctor.Body, OperationFunctor.ControlledAdjoint => OperationFunctor.Adjoint, _ => type, }; } return(type); }
public QVoid Record(OperationFunctor functor, T tag) { var key = Key(functor, tag); if (_log.ContainsKey(key)) { _log[key] = _log[key] + 1; } else { _log[key] = 1; } return(QVoid.Instance); }
protected double GetMetric( string operationName, string metric, string callerName = CallGraphEdge.CallGraphRoot, OperationFunctor functor = OperationFunctor.Body, OperationFunctor callerFunctor = OperationFunctor.Body) { double min = GetMetricStatistic(operationName, metric, MinMaxStatistic.Statistics.Min, callerName, functor, callerFunctor); double max = GetMetricStatistic(operationName, metric, MinMaxStatistic.Statistics.Max, callerName, functor, callerFunctor); if (min != max) { throw new Exception($"Given metric value is a distribution. {nameof(GetMetricStatistic)} to get the distribution parameters"); } return(min); }
private static QVoid ExecuteConditionalStatement(QuantumProcessorDispatcher Simulator, Result measurementResult, Result resultValue, ICallable onEqualOp, ICallable onNonEqualOp, OperationFunctor type, IQArray <Qubit>?ctrls) { long statement = Simulator.QuantumProcessor.StartConditionalStatement(measurementResult, resultValue); return(ExecuteConditionalStatementInternal(Simulator, statement, onEqualOp, onNonEqualOp, type, ctrls)); }
public string FullOperationName(string operation, OperationFunctor functor = OperationFunctor.Body) { return(operation + ":" + functorNames[functor]); }
/// <summary> /// This is a wrapper for an if-statement that will run either onZero if the /// given measurement result is Zero, or onOne otherwise. /// </summary> private static QVoid ExecuteConditionalStatement(Result measurementResult, ICallable onZero, ICallable onOne, OperationFunctor type, IQArray <Qubit>?ctrls) { if (measurementResult == Result.Zero) { RunClause(onZero, type, ctrls); } else { RunClause(onOne, type, ctrls); } return(QVoid.Instance); }
private void TestOneOp <I, O>(string name, string fullName, OperationFunctor variant, string signature, Operation <I, O> op) { TestOneProxy(name, fullName, variant, signature, new Operation <I, O> .DebuggerProxy(op)); }
private void TestOneOp <I, O>(string name, string fullName, OperationFunctor variant, string signature, ControlledOperation <I, O> op) { var proxy = new ControlledOperation <I, O> .DebuggerProxy(op); TestOneProxy(name, fullName, variant, signature, proxy); }
public int GetNumberOfCalls(string name, OperationFunctor variant, object data) => _log.Where(r => r.callable.FullName == name && r.callable.Variant == variant && EqualData(data, r.data.Value)).Count();
public int GetNumberOfCalls(string name, OperationFunctor variant) => _log.Where(r => r.callable.FullName == name && r.callable.Variant == variant).Count();
/// <summary> /// This is a wrapper for an if-statement that will run either onEqualOp if the /// given measurement result are pairwise-equal to the given comparison results, /// or onNonEqualOp otherwise. Pairwise-equality between the qubit arrays is /// determined by the AreEqual static method. /// </summary> private static QVoid ExecuteConditionalStatement(IQArray <Result> measurementResults, IQArray <Result> comparisonResults, ICallable onEqualOp, ICallable onNonEqualOp, OperationFunctor type, IQArray <Qubit>?ctrls) { if (AreEqual(measurementResults, comparisonResults)) { RunClause(onEqualOp, type, ctrls); } else { RunClause(onNonEqualOp, type, ctrls); } return(QVoid.Instance); }
public CallGraphEdge(HashedString operationName, OperationFunctor operationVariant) : this(operationName, CallGraphRootHashed, operationVariant, OperationFunctor.Body) { }
public string Key(OperationFunctor functor, T tag) => $"{functor}:{tag}";