# Quantum Circuits (qiskit.circuit)¶

## Overview¶

The fundamental element of quantum computing is the quantum circuit. A quantum circuit is a computational routine consisting of coherent quantum operations on quantum data, such as qubits. It is an ordered sequence of quantum gates, measurements and resets, which may be conditioned on real-time classical computation. A set of quantum gates is said to be universal if any unitary transformation of the quantum data can be efficiently approximated arbitrarily well as as sequence of gates in the set. Any quantum program can be represented by a sequence of quantum circuits and classical near-time computation.

In Qiskit, this core element is represented by the QuantumCircuit class. Below is an example of a quantum circuit that makes a three-qubit GHZ state defined as:

$|\psi\rangle = \left(|000\rangle+|111\rangle\right)/\sqrt{2}$
from qiskit import QuantumCircuit
# Create a circuit with a register of three qubits
circ = QuantumCircuit(3)
# H gate on qubit 0, putting this qubit in a superposition of |0> + |1>.
circ.h(0)
# A CX (CNOT) gate on control qubit 0 and target qubit 1 generating a Bell state.
circ.cx(0, 1)
# CX (CNOT) gate on control qubit 0 and target qubit 2 resulting in a GHZ state.
circ.cx(0, 2)
# Draw the circuit
circ.draw()

     ┌───┐
q_0: ┤ H ├──■────■──
└───┘┌─┴─┐  │
q_1: ─────┤ X ├──┼──
└───┘┌─┴─┐
q_2: ──────────┤ X ├
└───┘

## Quantum Circuit API¶

### Quantum Circuit Construction¶

 QuantumCircuit(*regs[, name, global_phase, ...]) Create a new circuit. QuantumRegister([size, name, bits]) Implement a quantum register. Qubit([register, index]) Implement a quantum bit. ClassicalRegister([size, name, bits]) Implement a classical register. Clbit([register, index]) Implement a classical bit. AncillaRegister([size, name, bits]) Implement an ancilla register. AncillaQubit([register, index]) A qubit used as ancillary qubit.

### Gates and Instructions¶

 Gate(name, num_qubits, params[, label]) Unitary gate. ControlledGate(name, num_qubits, params[, ...]) Controlled unitary gate. Delay(duration[, unit]) Do nothing and just delay/wait/idle for a specified duration. Instruction(name, num_qubits, num_clbits, params) Generic quantum instruction. InstructionSet([circuit_cregs, ...]) Instruction collection, and their contexts. EquivalenceLibrary(*[, base]) A library providing a one-way mapping of Gates to their equivalent implementations as QuantumCircuits.

### Control Flow Operations¶

 ControlFlowOp(name, num_qubits, num_clbits, ...) Abstract class to encapsulate all control flow operations. IfElseOp(condition, true_body[, false_body, ...]) A circuit operation which executes a program (true_body) if a provided condition (condition) evaluates to true, and optionally evaluates another program (false_body) otherwise. WhileLoopOp(condition, body[, label]) A circuit operation which repeatedly executes a subcircuit (body) until a condition (condition) evaluates as False. ForLoopOp(indexset, loop_parameter, body[, ...]) A circuit operation which repeatedly executes a subcircuit (body) parameterized by a parameter loop_parameter through the set of integer values provided in indexset. BreakLoopOp(num_qubits, num_clbits[, label]) A circuit operation which, when encountered, jumps to the end of the nearest enclosing loop. ContinueLoopOp(num_qubits, num_clbits[, label]) A circuit operation which, when encountered, moves to the next iteration of the nearest enclosing loop.

### Parametric Quantum Circuits¶

 Parameter(name) Parameter Class for variable parameters. ParameterVector(name[, length]) ParameterVector class to quickly generate lists of parameters. ParameterExpression(symbol_map, expr) ParameterExpression class to enable creating expressions of Parameters.

### Random Circuits¶

 random.random_circuit(num_qubits, depth[, ...]) Generate random circuit of arbitrary size and form.