/qrot

Approximating Qubit Z-Rotation with H, S, T (Implementation of 1403.2975)

Primary LanguageC++MIT LicenseMIT

Approximating Qubit Z-Rotation with H, S, T {#mainpage}

This C++ implementation is based on the algorithm presented in the paper Optimal ancilla-free Clifford+T approximation of z-rotations. This program is developed as part of my study. Currenthly this program demonstrates notably poorer performance in comparison to the Haskell program GridSynth developed by the authors of the paper.

While GridSynth is distributed under the GPL license, my implementation has been developed independently without referencing the original code. Therefore, I am releasing this implementation under the MIT license.

Building and Testing

To build this library, use Boost.Multiprecision, Boost.Program_options, and GoogleTest. Follow these commands:

$ cmake -S . -B build
$ cmake --build build
$ ctest --test-dir build

Implemented Algorithms

TODO

  • Enhance Speed
    • The prime factorization process currently consumes a significant amount of time
    • Implement the Quadratic Sieve algorithm
    • Use OpenMP
  • Address numerical errors arising from floating-point calculations

Run Results

The execution time of gridsynth_cpp is notably influenced by the success or failure of prime factorization.

  • CPU: AMD Ryzen 7 3700X 8-Core Processor
$ time ./gridsynth_cpp pi/128 -d 10
TCount = 104
TSHTSHTHTHTHTSHTSHTSHTHTHTHTHTSHTHTSHTHTSHTSHTSHTHTHTSHTHTHTHTHTHTSHTSHTHTHTHTSHTSHTSHTHTHTSHTHTHTHTSHTSHTSHTHTHTHTSHTHTHTSHTSHTHTHTSHTSHTHTHTSHTSHTSHTSHTSHTSHTHTHTHTSHTSHTHTHTSHTSHTSHTSHTSHTSHTSHTHTSHTHTSHTHTHTSHTSHTSHTSHTSHTHTSHTSHTSHTHTSHTSHTSHTHTHTSHTSHTHTSHTSSSXS

real    0m0.288s
user    0m0.258s
sys     0m0.030s
$ time ./gridsynth_cpp pi/128 -d 20
TCount = 202
THTSHTHTSHTHTSHTSHTSHTHTHTSHTHTSHTHTHTSHTSHTSHTHTHTHTSHTSHTHTHTSHTSHTHTSHTHTHTSHTHTHTHTSHTSHTSHTSHTSHTSHTSHTHTSHTSHTSHTHTSHTSHTHTSHTHTSHTHTHTSHTSHTHTHTHTSHTSHTHTHTSHTHTH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