def test_daggered_gate_tex_str(): daggered_gate = _metagates.DaggeredGate(Y) str_Y = Y.tex_str() if hasattr(Y, 'tex_str') else str(Y) assert daggered_gate.tex_str() == str_Y + r"${}^\dagger$" # test for a gate with tex_str method rx = Rx(0.5) daggered_rx = _metagates.DaggeredGate(rx) str_rx = rx.tex_str() if hasattr(rx, 'tex_str') else str(rx) assert daggered_rx.tex_str() == str_rx + r"${}^\dagger$"
from projectq.ops import All, H, T, Rx, Ry, Z, C, Measure from math import pi import random, time # prepare gate set Xroot, Yroot = Rx(pi/2), Ry(pi/2) Xroot.tex_str = lambda: '$X^{1/2}$' Yroot.tex_str = lambda: '$Y^{1/2}$' def pick_gate(prev_gate): gates = [Xroot, Yroot, T] #!!! does paper contain error?? gates.remove(prev_gate) # "cycle" selectively includes/excludes C gates return random.choice(gates) def apply_random_circuit(qubits, circ_depth, engine): # prepare structures num_qubits = len(qubits) has_toffo = [False]*num_qubits prev_gate = [None]*num_qubits prev_sing = [T]*num_qubits curr_gate = [H]*num_qubits c_start_i = -1 # don't include init-state in timing engine.flush() engine.backend.set_wavefunction([1], qubits) engine.backend.collapse_wavefunction(qubits, [0]*num_qubits)