Skip to content

Commit

Permalink
Deprecated streaming_extract, and changed the name of `modified_ext…
Browse files Browse the repository at this point in the history
…ract` to `extract_circuit` to make it the main circuit extraction algorithm
  • Loading branch information
jvdwetering committed May 19, 2020
1 parent 97910ea commit caa3740
Show file tree
Hide file tree
Showing 13 changed files with 3,316 additions and 4,477 deletions.
891 changes: 461 additions & 430 deletions demos/AllFeatures.ipynb

Large diffs are not rendered by default.

43 changes: 19 additions & 24 deletions demos/Challenge_circuit_extraction.ipynb

Large diffs are not rendered by default.

5,681 changes: 2,546 additions & 3,135 deletions demos/Optimising almost-Clifford circuits.ipynb

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions demos/STRING2019.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions demos/T-count Benchmark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
" self.time_simpl = time.time() - t\n",
" t = time.time()\n",
" c_opt = zx.Circuit.from_graph(g).split_phase_gates().to_basic_gates()\n",
" #c_opt = zx.extract.streaming_extract(g).to_basic_gates()\n",
" #c_opt = zx.extract_circuit(g).to_basic_gates()\n",
" c_opt = zx.optimize.basic_optimization(c_opt).to_basic_gates()\n",
" self.c_opt = c_opt\n",
" if validate:\n",
Expand All @@ -96,7 +96,7 @@
" self.extracts = True\n",
" self.time_extr = 0.0\n",
"# try: \n",
"# c2 = zx.extract.streaming_extract(g,quiet=True)\n",
"# c2 = zx.extract_circuit(g,quiet=True)\n",
"# self.time_extr = time.time() - t\n",
"# except Exception:\n",
"# self.extracts = False\n",
Expand Down
30 changes: 15 additions & 15 deletions demos/example-gtsimp.ipynb

Large diffs are not rendered by default.

420 changes: 213 additions & 207 deletions demos/gettingstarted.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyzx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .drawing import *
from .simplify import *
from .optimize import *
from .extract import *
from .io import *
from .tensor import *
from .circuit.qasmparser import qasm
Expand Down
570 changes: 7 additions & 563 deletions pyzx/extract.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyzx/scripts/circ2circ.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def main(args):
if options.simp == 'cliff':
simplify.clifford_simp(g,quiet=(not options.verbose))
if options.verbose: print("Extracting circuit...")
c2 = extract.streaming_extract(g)
c2 = extract.extract_circuit(g)
if options.verbose: print("Optimizing...")
if options.phasepoly:
c3 = optimize.full_optimize(c2.to_basic_gates())
Expand Down
18 changes: 5 additions & 13 deletions tests/long_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pyzx.tensor import compare_tensors
from pyzx.generate import cliffordT
from pyzx.simplify import *
from pyzx.extract import *
from pyzx.extract import extract_circuit
from pyzx.circuit import Circuit
from pyzx.optimize import *

Expand All @@ -50,8 +50,8 @@ def do_tests(qubits, depth, iterations, test_clifford_graph=True):
steps.append("clifford_simp")
if test_clifford_graph: compare(t, g)

c = streaming_extract(g)
steps.append("streaming_extract")
c = extract_circuit(g)
steps.append("extract_circuit")
compare(t, c, False)

c = c.to_basic_gates()
Expand All @@ -68,18 +68,10 @@ def do_tests(qubits, depth, iterations, test_clifford_graph=True):
steps.append("full_reduce")
if test_clifford_graph: compare(t, g)

c = modified_extract(g)
steps.append("modified_extract")
c = extract_circuit(g)
steps.append("extract_circuit")
compare(t,c,False)

steps = []
g = circ.copy()
full_reduce(g, quiet=True)
steps.append("full_reduce")
c = streaming_extract(g).to_basic_gates()
steps.append("streaming_extract")
compare(t, c, False)

steps = []
g = circ.copy()
#to_gh(g)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from pyzx.generate import cliffordT, cliffords
from pyzx.simplify import clifford_simp
from pyzx.extract import streaming_extract
from pyzx.extract import extract_circuit
from pyzx.circuit import Circuit

SEED = 1337
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_circuit_extract_preserves_semantics(self):
g = cliffordT(5, 70, 0.15)
t = g.to_tensor(False)
clifford_simp(g, quiet=True)
c = streaming_extract(g)
c = extract_circuit(g)
t2 = c.to_tensor(False)
self.assertTrue(compare_tensors(t,t2,False))

Expand Down
49 changes: 4 additions & 45 deletions tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,22 @@
from pyzx.circuit.gates import CNOT
from pyzx.generate import cliffordT, cliffords
from pyzx.simplify import clifford_simp
from pyzx.extract import streaming_extract, modified_extract
from pyzx.extract import extract_circuit

SEED = 1337


@unittest.skipUnless(np, "numpy needs to be installed for this to run")
class TestExtract(unittest.TestCase):

# def test_clifford_extract(self):
# random.seed(SEED)
# tests = 0
# tries = 0
# while True:
# tries += 1
# circ = cliffords(5,70)
# clifford_simp(circ,quiet=True)
# circ.normalise()
# if circ.depth()>3: continue # It is not in normal form, so skip this one
# tests += 1
# with self.subTest(test=tests,tries=tries):
# t = tensorfy(circ)
# clifford_extract(circ,1,2)
# t2 = tensorfy(circ)
# self.assertTrue(compare_tensors(t,t2))
# if tests>5: break

# def test_greedy_cut_extract(self):
# random.seed(SEED)
# for i in range(5):
# circ = cliffordT(4,50,0.1)
# clifford_simp(circ,quiet=True)
# circ.normalise()
# with self.subTest(i=i):
# t = tensorfy(circ)
# greedy_cut_extract(circ)
# t2 = tensorfy(circ)
# self.assertTrue(compare_tensors(t,t2))

# def test_circuit_extract(self):
# random.seed(SEED)
# for i in range(5):
# circ = cliffordT(4,50,0.1)
# clifford_simp(circ,quiet=True)
# with self.subTest(i=i):
# t = tensorfy(circ)
# circuit_extract(circ)
# t2 = tensorfy(circ)
# self.assertTrue(compare_tensors(t,t2))

def test_streaming_extract(self):
def test_extract_circuit(self):
random.seed(SEED)
for i in range(5):
circ = cliffordT(4,50,0.1)
t = tensorfy(circ,False)
clifford_simp(circ,quiet=True)
with self.subTest(i=i):
c = streaming_extract(circ)
c = extract_circuit(circ)
t2 = c.to_tensor(False)
self.assertTrue(compare_tensors(t,t2,False))

Expand All @@ -101,7 +60,7 @@ def test_cz_optimise_extract(self):

g = c.to_graph()
clifford_simp(g,quiet=True)
c2 = modified_extract(g)
c2 = extract_circuit(g)
cnot_count = 0
for gate in c2.gates:
if isinstance(gate, CNOT):
Expand Down

0 comments on commit caa3740

Please sign in to comment.