from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister

# Build a quantum circuit
circuit = QuantumCircuit(3, 3)

circuit.x(1)
circuit.h(range(3))
circuit.cx(0, 1)
circuit.measure(range(3), range(3));

print(circuit)

circuit.draw()

# Matplotlib Drawing
circuit.draw(output='mpl')

# Draw a new circuit with barriers and more registers

q_a = QuantumRegister(3, name='qa')
q_b = QuantumRegister(5, name='qb')
c_a = ClassicalRegister(3)
c_b = ClassicalRegister(5)

circuit = QuantumCircuit(q_a, q_b, c_a, c_b)

circuit.x(q_a[1])
circuit.x(q_b[1])
circuit.x(q_b[2])
circuit.x(q_b[4])
circuit.barrier()
circuit.h(q_a)
circuit.barrier(q_a)
circuit.h(q_b)
circuit.cswap(q_b[0], q_b[1], q_b[2])
circuit.cswap(q_b[2], q_b[3], q_b[4])
circuit.cswap(q_b[3], q_b[4], q_b[0])
circuit.barrier(q_b)
circuit.measure(q_a, c_a)
circuit.measure(q_b, c_b);

# Draw the circuit
circuit.draw(output='mpl')

# Draw the circuit with reversed bit order
circuit.draw(output='mpl', reverse_bits=True)

# Draw the circuit without barriers
circuit.draw(output='mpl', plot_barriers=False)

# Draw the circuit without barriers and reverse bit order
circuit.draw(output='mpl', plot_barriers=False, reverse_bits=True)

# Set line length to 80 for above circuit
circuit.draw(output='text')

# Change the background color in mpl

style = {'backgroundcolor': 'lightgreen'}

circuit.draw(output='mpl', style=style)

# Scale the mpl output to 1/2 the normal size
circuit.draw(output='mpl', scale=0.5)

from qiskit.tools.visualization import circuit_drawer

circuit_drawer(circuit, output='mpl', plot_barriers=False)

import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright

