Exemplo n.º 1
0
        /// <summary>
        /// Callback method for the OnOperationStart event.
        /// </summary>
        public void CountOperationCalls(ICallable op, IApplyData data)
        {
            // Count all operations, grouped by operation
            if (_operationsCount.ContainsKey(op.ToString()))
            {
                _operationsCount[op.ToString()]++;
            }
            else
            {
                _operationsCount[op.ToString()] = 1;
            }

            // Check if the operation has multiple qubit parameters, if yes, count it
            int nQubits = 0;

            using (IEnumerator <Qubit> enumerator = data?.Qubits?.GetEnumerator())
            {
                if (enumerator is null)
                {
                    // The operation doesn't have qubit parameters
                    return;
                }
                while (enumerator.MoveNext())
                {
                    nQubits++;
                }
            }

            if (_arityOperationsCount.ContainsKey(nQubits))
            {
                _arityOperationsCount[nQubits]++;
            }
            else
            {
                _arityOperationsCount[nQubits] = 1;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Getter method for _operationsCount designed to be accessed from C# code.
 /// See GetOracleCallsCount for accessing within Q#.
 /// </summary>
 public int GetOperationCount(ICallable op)
 {
     return(_operationsCount.TryGetValue(op.ToString(), out var value) ? value : 0);
 }