def test_validation(): with pytest.raises(ValueError): circuit_to_svg(cirq.Circuit()) q0 = cirq.LineQubit(0) with pytest.raises(ValueError): circuit_to_svg(cirq.Circuit([cirq.Moment([cirq.X(q0)]), cirq.Moment([])]))
def test_svg_noise(): noise_model = cirq.ConstantQubitNoiseModel(cirq.DepolarizingChannel(p=1e-3)) q = cirq.LineQubit(0) circuit = cirq.Circuit(cirq.X(q)) circuit = cirq.Circuit(noise_model.noisy_moments(circuit.moments, [q])) svg = circuit_to_svg(circuit) assert '>D(0.001)</text>' in svg
def test_empty_moments(): a, b = cirq.LineQubit.range(2) svg_1 = circuit_to_svg( cirq.Circuit( cirq.Moment(), cirq.Moment(cirq.CNOT(a, b)), cirq.Moment(), cirq.Moment(cirq.SWAP(a, b)), cirq.Moment(cirq.Z(a)), cirq.Moment(cirq.measure(a, b, key='z')), cirq.Moment(), )) assert '<svg' in svg_1 assert '</svg>' in svg_1 svg_2 = circuit_to_svg(cirq.Circuit(cirq.Moment())) assert '<svg' in svg_2 assert '</svg>' in svg_2
def test_svg(): a, b, c = cirq.LineQubit.range(3) svg_text = circuit_to_svg( cirq.Circuit( cirq.CNOT(a, b), cirq.CZ(b, c), cirq.SWAP(a, c), cirq.PhasedXPowGate(exponent=0.123, phase_exponent=0.456).on(c), cirq.Z(a), cirq.measure(a, b, c, key='z'))) assert '<svg' in svg_text assert '</svg>' in svg_text
print(len(list(circuit.all_operations()))) # latex file with open('circuits/circuit_cirq_n=2.tex', 'w') as file: file.write('\\documentclass[draft]{beamer}\n') file.write( '\\usepackage[size=custom,height=39,width=120,scale=0.7]{beamerposter}\n' ) file.write('\\usepackage[braket]{qcircuit}\n') file.write('\\begin{document}\n') file.write(circuit_to_latex_using_qcircuit(circuit)) file.write('\\end{document}') # circuit svg file with open('circuits/circuit_cirq_n=2.svg', 'w') as file: file.write(circuit_to_svg(circuit)) # convert to OpenQASM # with open('circuitQASM.qasm', 'w') as file: # file.write(circuit.to_qasm()) # ------------------------------------------------------------------------------ # Checking Results successTot = 0 validRuns = 0 bCount = 0 for i in range(numRuns): d = [] for j in range(n):
def test_validation(): with pytest.raises(ValueError): circuit_to_svg(cirq.Circuit())