Unverified Commit 0f285ba0 authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub
Browse files

Merge pull request #193 from tnguyen-ornl/tnguyen/wip-ir-workshop-demo

Update QCOR demo for PIRQ
parents 0713007e 5d719bae
Loading
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
# QCOR - XACC IR Demo


QCOR IDE set-up: https://aide-qc.github.io/deploy/getting_started/


## Launch QCOR IDE: 

```
aide-qc --start
```

## Access:

```
http://CADES-IP:8080
```


## IDE Docker set-up

- Add `.ibm_config` and `.ionq_config`
 No newline at end of file
+1 −4
Original line number Diff line number Diff line
@@ -14,9 +14,6 @@

- Trotter circuit (e.g., 2-3 qubits): print gate count before and after optimization; examine the results (e.g. expectations and simulation runtime with and without optimization). 

- Topology placement: QAOA (max-cut) circuits => hardware mapping. 

- Noise-aware mapping: Bell test (H-CX); select an IBM backend with more qubits; should pick the pair with low CX error rate.

- [Skipped] Topology placement: QAOA (max-cut) circuits => hardware mapping. 

+8 −3
Original line number Diff line number Diff line
/// qaoa_placement.cpp: Topology placement example
/// qcor -qpu ibm:ibmq_paris  qaoa_placement.cpp -print-final-submission

/// Using the default placement:
/// qcor -qpu aer:ibmq_guadalupe  qaoa_placement.cpp -print-final-submission
/// Change the placement:
/// qcor -qpu aer:ibmq_guadalupe -placement enfield qaoa_placement.cpp -print-final-submission
/// Can add -opt 1 to further combine single-qubit gates (mixer terms).
__qpu__ void qaoa_maxcut(qreg q, std::vector<double> gamma,
                  std::vector<double> beta,
                  std::vector<std::pair<int, int>> graph_edges) {
@@ -26,12 +29,14 @@ __qpu__ void qaoa_maxcut(qreg q, std::vector<double> gamma,
      exp_i_theta(q, beta[step], ref_ham_term);
    }
  }

  Measure(q);
}

int main(int argc, char **argv) {
  auto q = qalloc(5);
  // Ring graph
  std::vector<std::pair<int, int>> graph{{0, 1}, {1, 2}, {2, 3}, {3, 4}};
  std::vector<std::pair<int, int>> graph{{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 0}};
  // One step
  int p = 1;
  std::vector<double> gammas{1.0};
+33 −0
Original line number Diff line number Diff line
// trotter_decompose.cpp: Demonstrate runtime optimization passes (acting on XACC IR)
// (with runtime information -> resolved/flattened circuit -> optimization)
// Simplify Trotter circuit with many iterations to a shorter form
// $qcor -opt 1 -print-opt-stats -print-final-submission trotter_decompose.cpp
// $qcor -opt 2 -print-opt-stats -print-final-submission trotter_decompose.cpp
// Run:
// ./a.out -dt xxx -steps yyy
__qpu__ void trotter_evolve(qreg q, Operator hamiltonian, double dt, int nbSteps) {
  for (int i = 0; i < nbSteps; ++i) {
    exp_i_theta(q, dt, hamiltonian);
  }
}

int main() {
int main(int argc, char **argv) {
  auto qbits = qalloc(2);
  auto H = X(0) * X(1);
  // Multi-term Hamiltonian
  auto H = X(0) * X(1) + Z(0) + Z(1);
  // Default params:
  double dt = 0.01;
  int nbSteps = 100;

  // Parse user-supplied params (if any)
  std::vector<std::string> arguments(argv + 1, argv + argc);
  for (int i = 0; i < arguments.size(); i++) {
    if (arguments[i] == "-dt") {
      dt = std::stod(arguments[i + 1]);
    }
    if (arguments[i] == "-steps") {
      nbSteps = std::stoi(arguments[i + 1]);
    }
  }
  std::cout << "Trotter for dt = " << dt << "; steps = " << nbSteps << "\n";
  trotter_evolve(qbits, H, dt, nbSteps);
}
 No newline at end of file
Loading