boschmitt / tweedledum

C++17 Library for analysis, compilation/synthesis, and optimization of quantum circuits
MIT License
98 stars 36 forks source link

Synthesis of bitflip and phaseflip circuits. #147

Closed boschmitt closed 3 years ago

boschmitt commented 3 years ago

Description

Two functions that can be quite handy when synthesizing oracles. They take as input a BoolFunction and synthesize it to either a bitflip or a phaseflip circuit implementation of the function.

from tweedledum.bool_function_compiler import BitVec, BoolFunction, phaseflip_circuit

def f(v0, v1, v2, v3 : BitVec(1)) -> BitVec(1):
    return (v0 != v1) and (v2 != v3) and (v0 != v2) and (v1 != v3)

oracle_func = BoolFunction(f)
oracle_circuit = phaseflip_circuit(oracle_func, 'pkrm')

Result:

       ╭───╮     
__q3 : ┤ z ├──◯──
       ╰─┬─╯╭─┴─╮
__q2 : ──◯──┤ z ├
         │  ╰─┬─╯
__q1 : ──◯────●──
         │    │  
__q0 : ──●────◯──

Suggested changelog entry:

Synthesis of bitflip and phaseflip circuits.