ScaffCC - A Framework for Compilation and Analysis of Quantum Computing Programs

Scaffold

Scaffold is a high level, C-like programming language for expressing quantum algorithms. Its purpose is to aid in the design and evaluation of applications for quantum computers. For example, Schrödinger's cat:

qmodule catN(qbit *bit, const int n) {
  H(bit[0]);
  for (int i = 1; i < n; i++) {
    CNOT(bit[i], bit[i - 1]);
  }
}

qmodule unCatN(qbit *bit, const int n) {
  for (int i = n - 1; i > 0; i--) {
    CNOT(bit[i], bit[i - 1]);
  }
  H(bit[0]);
}

int main() {
  qbit bits[4];
  catN(bits, 4);
  return 0;
}
    

ScaffCC

ScaffCC is a compiler and scheduler for the Scaffold programing language. It is written using the LLVM open-source infrastructure. It is for the purpose of writing and analyzing code for quantum computing applications.

ScaffCC enables researchers to compile quantum applications written in Scaffold to a low-level quantum assembly format (QASM), for example, cat_state.n04.qasmf:

qubit bits0
qubit bits1
qubit bits2
qubit bits3
H bits0
CNOT bits1,bits0
CNOT bits2,bits1
CNOT bits3,bits2
    

apply error correction, and generate time and area metrics. It is written to be scalable up to problem sizes in which quantum algorithms outperform classical ones, and as such provide valuable insight into the overheads involved and possible optimizations for a realistic implementation on a future device technology.

ScaffCC also implements a number of optimization and resource estimation passes:

ScaffCC is based on LLVM 3.1, but migrated to LLVM 6.0 for better optimization and performance.

Build for Fedora 25

$ sudo dnf upgrade --refresh
$ sudo dnf install clang cmake boost-devel gmp-devel mpfr-devel
$ git clone https://github.com/ScaffCC/ScaffCC.git
$ cd ScaffCC
$ git clone https://github.com/ScaffCC/scaff-llvm.git llvm
$ git clone https://github.com/ScaffCC/scaff-clang.git clang
$ make DISABLE_STATIC=1
    

Simulate

$ ./scaffold.sh -fkR Algorithms/Cat_State/cat_state.n04.scaffold
$ ./cat_state.n04_qasm 
H bits0
CNOT bits1,bits0
CNOT bits2,bits1
CNOT bits3,bits2
$ ./scaffold.sh -s Algorithms/Cat_State/cat_state.n04.scaffold
$ ./qx_simulator_1.0.beta_linux_x86_64 cat_state.n04.qc 

  =======================================================================================================
       _______                                                                                       
      /  ___   \   _  __      ____   ____   __  ___  __  __   __    ___   ______  ____    ___         
     /  /   /  |  | |/_/     / __/  /  _/  /  |/  / / / / /  / /   / _ | /_  __/ / __ \  / _ \        
    /  /___/  /  _>  <      _\ \   _/ /   / /|_/ / / /_/ /  / /__ / __ |  / /   / /_/ / / , _/        
    \______/\__\ /_/|_|    /___/  /___/  /_/  /_/  \____/  /____//_/ |_| /_/    \____/ /_/|_|         
                                                                                              [v0.1 beta]
  _______________________________________________________________________________________________________
  [version 0.1 beta - Nader Khammassi - TU Delft, QuTech - 2016 - report bugs to: n.khammassi@tudelft.nl]
  [released under Apache License 2.0 terms, license copy at:  http://www.apache.org/licenses/LICENSE-2.0]
  ======================================================================================================= 

[+] loading circuit from 'cat_state.n04.qc' ...
[-] loading quantum_code file 'cat_state.n04.qc'...
[+] code loaded successfully. 
[+] initializing xpu...
[+] initialized.
[+] creating quantum register of 4 qubits... 
[+] executing circuit 'default' (1 iter) ...
--------------[quantum state]-------------- 
   (+0.707107,+0.000000) |0000> +
   (+0.707107,+0.000000) |1111> +
------------------------------------------- 
[>>] measurement prediction:  | X | X | X | X |
------------------------------------------- 
[>>] measurement register  :  | 0 | 0 | 0 | 0 |
------------------------------------------- 
[+] circuit execution time: +0.000396 sec.