Skip to content

Commit

Permalink
Merge pull request #263 from amirebrahimi/fix-cliffordTmeas
Browse files Browse the repository at this point in the history
Allow generating single qubit Clifford+T circuits
  • Loading branch information
jvdwetering authored Jul 30, 2024
2 parents 0e40c60 + db94613 commit e8a0de5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
8 changes: 5 additions & 3 deletions pyzx/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def cliffordTmeas(
else: rest -= p_s
if p_hsh is None: num += 1.0
else: rest -= p_hsh
if p_cnot is None: num += 1.0
if p_cnot is None: num += 1.0 if qubits > 1 else 0.0
else: rest -= p_cnot
if p_meas is None: num += 1.0
else: rest -= p_meas
Expand All @@ -298,13 +298,15 @@ def cliffordTmeas(
if p_t is None: p_t = rest / num
if p_s is None: p_s = rest / num
if p_hsh is None: p_hsh = rest / num
if p_cnot is None: p_cnot = rest / num
if p_cnot is None: p_cnot = rest / num if qubits > 1 else 0.0
if p_meas is None: p_meas = rest / num

if p_cnot > 0 and qubits <= 1: raise ValueError("Cannot have p_cnot > 0 with a single qubit.")

#p_s = (1 - p_t) / 3.0
#p_hsh = (1 - p_t) / 3.0
#p_cnot = (1 - p_t) / 3.0

inputs = []
outputs = []

Expand Down
19 changes: 12 additions & 7 deletions tests/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,18 @@ def test_load_quipper_from_file(self):
self.assertListEqual(c2.gates,c2.gates)

def test_cliffordT_preserves_graph_semantics(self):
random.seed(SEED)
g = cliffordT(4,20,0.2)
c = Circuit.from_graph(g)
g2 = c.to_graph()
t = tensorfy(g,False)
t2 = tensorfy(g2,False)
self.assertTrue(compare_tensors(t,t2, False))
for i in range(1,5):
with self.subTest(i):
random.seed(SEED)
g = cliffordT(i,20,0.2)
c = Circuit.from_graph(g)
g2 = c.to_graph()
t = tensorfy(g,False)
t2 = tensorfy(g2,False)
self.assertTrue(compare_tensors(t,t2, False))

def test_cliffordT_raises_exception_with_pcnot(self):
self.assertRaises(ValueError, cliffordT, 1, 1, p_cnot=0.1)

def test_cliffords_preserves_graph_semantics(self):
random.seed(SEED)
Expand Down

0 comments on commit e8a0de5

Please sign in to comment.