/// # Summary /// Runs a specified quantum operation with different parameters `ns`, /// saving the resource estimates as a csv file to a specified location. /// /// # Inputs /// ## runner /// The quantum operation being tested (must also match the type `Qop`). /// This operation must take a boolean `isControlled` and an integer parameter /// ## ns /// An array of integer parameters. This method will run the quantum operation /// with each parameter /// ## isControlled /// A boolean argument to pass to the quantum operation. The intention is that /// it tells the operator whether to test a controlled or uncontrolled version. /// ## filename /// The filename, including directory, of where to save the results /// ## full_depth /// If true, counts all gates as depth 1; if false, only counts T-gates as depth 1, /// all others as depth 0 private static void BasicResourceTest <TypeQop>(RunQop runner, int[] ns, bool isControlled, string filename, bool full_depth, bool isThreaded) { if (full_depth) { filename += "-all-gates"; } if (isControlled) { filename += "-controlled"; } filename += ".csv"; string estimation = string.Empty; // Headers for the table if (!System.IO.File.Exists(filename)) { estimation += " operation, CNOT count, 1-qubit Clifford count, T count, R count, M count, "; if (full_depth) { estimation += "Full depth, "; } else { estimation += "T depth, "; } estimation += "initial width, extra width, comment, size"; System.IO.File.WriteAllText(filename, estimation); } // Run the test for every size ReaderWriterLock locker = new ReaderWriterLock(); for (int i = 0; i < ns.Length; i++) { if (isThreaded) { var thisThreadParameter = ns[i]; Thread oneParameterTest = new Thread(() => SingleResourceTest <TypeQop>( runner, locker, thisThreadParameter, isControlled, filename, full_depth)); oneParameterTest.Start(); } else { // Single thread SingleResourceTest <TypeQop>(runner, locker, ns[i], isControlled, filename, full_depth); } } }
/// # Summary /// Runs a specified quantum operation with different parameters `ns`, /// saving the resource estimates as a csv file to a specified location. /// /// # Inputs /// ## runner /// The quantum operation being tested (must also match the type `Qop`). /// This operation must take a boolean `isControlled` and an integer parameter /// ## ns /// An array of integer parameters. This method will run the quantum operation /// with each parameter /// ## isControlled /// A boolean argument to pass to the quantum operation. The intention is that /// it tells the operator whether to test a controlled or uncontrolled version. /// ## filename /// The filename, including directory, of where to save the results /// ## full_depth /// If true, counts all gates as depth 1; if false, only counts T-gates as depth 1, /// all others as depth 0 private static void BasicResourceTest <TypeQop>(RunQop runner, int[] ns, bool isControlled, string filename, bool full_depth, bool isThreaded) { if (full_depth) { filename += "-all-gates"; } if (isControlled) { filename += "-controlled"; } filename += ".csv"; string estimation = string.Empty; // Headers for the table if (!System.IO.File.Exists(filename)) { estimation += DisplayCSV.GetHeader(full_depth) + ", size"; System.IO.File.WriteAllText(filename, estimation); } // Run the test for every size ReaderWriterLock locker = new ReaderWriterLock(); for (int i = 0; i < ns.Length; i++) { if (isThreaded) { var thisThreadParameter = ns[i]; Thread oneParameterTest = new Thread(() => SingleResourceTest <TypeQop>( runner, locker, thisThreadParameter, isControlled, filename, full_depth)); oneParameterTest.Start(); } else { // Single thread SingleResourceTest <TypeQop>(runner, locker, ns[i], isControlled, filename, full_depth); } } }
private static void SingleResourceTest <TypeQop>(RunQop runner, ReaderWriterLock locker, int n, bool isControlled, string filename, bool full_depth) { QCTraceSimulator estimator = GetTraceSimulator(full_depth); // construct simulator object // we must generate a new simulator in each round, to clear previous estimates var res = runner(estimator, n, isControlled).Result; // run test // Create string of a row of parameters string thisCircuitCosts = DisplayCSV.CSV(estimator.ToCSV(), typeof(TypeQop).FullName, false, string.Empty, false, string.Empty); // add the row to the string of the csv thisCircuitCosts += $"{n}"; try { locker.AcquireWriterLock(int.MaxValue); // absurd timeout value System.IO.File.AppendAllText(filename, thisCircuitCosts); } finally { locker.ReleaseWriterLock(); } }