epiqc / ScaffCC

Compilation, analysis and optimization framework for the Scaffold quantum programming language.
BSD 2-Clause "Simplified" License
188 stars 53 forks source link

Toffoli decomposition not working (?) #47

Closed evmckinney9 closed 2 years ago

evmckinney9 commented 2 years ago

I am unsure I am using the commands correctly so any help is appreciated. For test_cases/All_Gates_Example/all_gates.scaffold, I am interesting in compiling into OpenQasm with all ccx gates decomposed. all_gates.scaffold contains these lines of code which will contain cxx gates.

...
Toffoli ( q[0], q[1], q[2] );
Fredkin ( q[0], q[1], q[2] );

First, I run ./scaffold.sh -b all_gates.scaffold and the Toffoli and Fredkin gates are written as

...
cx q[0], q[1];
ccx q[0], q[1], q[2];
cx q[1], q[2];
ccx q[0], q[1], q[2];
cx q[1], q[2];

Next, I run ./scaffold.sh -b -T all_gates.scaffold and the Toffoli gate is decmoposed.

h q[2];
t q[0];
t q[1];
t q[2];
cx q[1], q[0];
cx q[2], q[1];
cx q[0], q[2];
tdg q[1];
t q[2];
cx q[0], q[1];
tdg q[0];
tdg q[1];
cx q[2], q[1];
cx q[0], q[2];
cx q[1], q[0];
h q[2];
cx q[1], q[2];
ccx q[0], q[1], q[2];
cx q[1], q[2];

Except I still have ccx gates from the Fredkin gate, so I change the level of recursion flag and run ./scaffold.sh -b -T -l 2 all_gates.qasm (I tested various levels of recursion between 2 and 10).

The inclusion of recursion does not eliminate the remaining ccx gates. The resulting .qasm code is exactly the same as from before without the recursion flag.

How I can I eliminate all ccx gates? I want to use ScaffCC and TriQ together, but TriQ does not allow for these gates. Thanks

AndrewLitteken commented 2 years ago

This was due to the fact that Fredkin Gates were decomposed after Toffoli gates were decomposed in the pipeline. It should now fully decompose that Toffoli as well when -T is provided with the latest commit.

AndrewLitteken commented 2 years ago

Let me know if this fixes the problem please.

evmckinney9 commented 2 years ago

the new commit does not pass regression_test.sh image

evmckinney9 commented 2 years ago

Generating OpenQASM fails image

AndrewLitteken commented 2 years ago

With the last commit, it should work. There was an issue with the changes in the makefil