Example #1
0
 /// <summary>
 /// Execute the given <code>qasmExe.code</code> launching <code>qasmExe.shots</code> executions.
 /// When the result is ready, the <code>onExecuted</code> callback will be called.
 /// The <see cref="OnExecuted"/> will recieve <see cref="QASMExecutionResult"/>
 /// with the per shot results as rawResult.
 /// If the backends does not supports memory feature, the raw result will be simulated with
 /// accumulated results.
 /// </summary>
 /// <param name="qasmExe">Executable configuration</param>
 /// <param name="onExecuted">The callback called when execution ends</param>
 public void ExecuteCodeRawResult(QASMExecutable qasmExe, OnExecuted onExecuted)
 {
     RequestBackendConfig((_) => {
         GenericExecution(qasmExe, useMemory: _backendConfig.supportsMemory, (jsonResult) => {
             if (_backendConfig.supportsMemory)
             {
                 onExecuted(ReadRawDataJSON(jsonResult));
             }
             else
             {
                 QASMExecutionResult result = ReadCountJSON(jsonResult);
                 result.SimulateRawResult();
                 onExecuted(result);
             }
         });
     });
 }
Example #2
0
        /// <summary>
        /// Extracts from a clean json (see <see cref="GetResultJSON(string)"/>)
        /// the pershot qasm results.
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        private static QASMExecutionResult ReadRawDataJSON(string jsonText)
        {
            if (string.IsNullOrEmpty(jsonText))
            {
                return(null);
            }

            jsonText = jsonText.TrimStart('[');
            jsonText = jsonText.TrimEnd(']');
            jsonText = jsonText.Replace("\"", "");

            string[]            rawResultCollection = jsonText.Split(',');
            QASMExecutionResult executionResult     = new QASMExecutionResult();

            foreach (string rawResult in rawResultCollection)
            {
                executionResult.Add(System.Convert.ToInt32(rawResult, 2));
            }

            return(executionResult);
        }
Example #3
0
        /// <summary>
        /// Extracts from a clean json (see <see cref="GetResultJSON(string)"/>)
        /// the accumulated qasm results.
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        private static QASMExecutionResult ReadCountJSON(string jsonText)
        {
            if (string.IsNullOrEmpty(jsonText))
            {
                return(null);
            }

            jsonText = jsonText.TrimStart('{');
            jsonText = jsonText.TrimEnd('}');

            string[]            rawResultCollection = jsonText.Split(',');
            QASMExecutionResult executionResult     = new QASMExecutionResult();

            foreach (string rawResult in rawResultCollection)
            {
                string[] keyValue = rawResult.Split(':');
                keyValue[0] = keyValue[0].Trim('"');
                executionResult.Add(System.Convert.ToInt32(keyValue[0], 2), System.Convert.ToInt32(keyValue[1]));
            }

            return(executionResult);
        }