Commit 2ce1fe8f authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

setup tracer to print total n gates and total 2 qbit gates. add benchmarks to folder

parent dfbfcc81
Loading
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
OPENQASM 3;

const nb_qubits = 5;

def oracle() qubit[nb_qubits]:r {
  int nb_steps = 100;
  double step_size = .01;
  double Jz = 1.0;
  double h = 1.0;
  // -h*sigma_x layers
  for step in [0:nb_steps] {
    // -h*sigma_x layers
    rx(-h * step_size) r;
    
    // -Jz*sigma_z*sigma_z layers
    for i in [0:nb_qubits - 1] {
      cx r[i], r[i+1];
      rz(-Jz * step_size) r[i + 1];
      cx r[i], r[i+1];
    } 
  }
}

def oracle_compute_action() qubit[nb_qubits]:r {
  int nb_steps = 100;
  double step_size = .01;
  double Jz = 1.0;
  double h = 1.0;

  // -h*sigma_x layers
  for step in [0:nb_steps] {
    // -h*sigma_x layers
    rx (-h * step_size) r;

    // -Jz*sigma_z*sigma_z layers
    for i in [0:nb_qubits - 1] {
      compute {
        cx r[i], r[i+1];
      } action {
        rz(-Jz * step_size) r[i + 1];
      }
    } 
  }
}

qubit r[nb_qubits], c;

ctrl @ oracle_compute_action c, r;
// ctrl @ oracle c, r;
+13 −0
Original line number Diff line number Diff line
#!/bin/bash

# From 6 to 50 qubits, even only, 
# create the benchmark qasm code, compile it with -O3
# and execute collecting total number of gates
# Change 'Total G' to 'Total C' to count total 
# ctrl opertions
for NQUBITS in `seq 6 2 50`
do
	sed "s/nb_qubits =.*/nb_qubits = $NQUBITS;/" bench.qasm > bench$NQUBITS.qasm 
    qcor -O3 bench$NQUBITS.qasm -qrt ftqc -qpu tracer
    ./a.out | grep 'Total G' | sed 's/.*\: //'
done
+21 −2
Original line number Diff line number Diff line
#include "ResourcesTracerAccelerator.hpp"
#include <iomanip>
#include <random>
#include "xacc_service.hpp"

using namespace xacc;
namespace qcor {
void TracerAccelerator::initialize(const HeterogeneousMap &params) {
@@ -62,8 +64,7 @@ void TracerAccelerator::printResourcesEstimationReport() {
  // Currently, simply print gate count:
  std::cout << "Resources Estimation Result:\n";
  std::cout << "Number of qubit required: " << qubit_idxs.size() << "\n";
  std::cout << "Gate Count Report: \n";
  size_t totalNumberGates = 0;
  size_t totalNumberGates = 0, totalCtrlOperations = 0;
  std::stringstream stream;
  const size_t nbColumns = 2;
  const size_t columnWidth = 8;
@@ -81,10 +82,28 @@ void TracerAccelerator::printResourcesEstimationReport() {
    stream << std::setw(8) << count << " |\n";
  };

  auto insts = xacc::getServices<xacc::Instruction>();
  std::vector<std::string> two_qubit_names;
  for (auto inst : insts) {
    if (inst->nRequiredBits() > 1) {
      two_qubit_names.push_back(inst->name());
    }
  }

  // Print each row, and count total number of instructions, and 
  // count any 2 qubit control operations.
  for (const auto &[gateName, count] : gateNameToCount) {
    printEachRow(gateName, count);
    totalNumberGates += count;
    if (xacc::container::contains(two_qubit_names, gateName)) {
      totalCtrlOperations += count;
    }
  }

  stream << std::string(totalWidth, '-') << "\n";
  std::cout << "Total Gates: " << totalNumberGates << "\n";
  std::cout << "Total Control Operations: " << totalCtrlOperations << "\n";
  std::cout << "Gate Count Report: \n";
  std::cout << stream.str();
}
} // namespace qcor