# cirq.Circuit¶

class cirq.Circuit(*contents: Union[cirq.ops.raw_types.Operation, cirq.ops.op_tree.OpTree], strategy: cirq.circuits.insert_strategy.InsertStrategy = cirq.InsertStrategy.EARLIEST, device: cirq.devices.device.Device = cirq.UNCONSTRAINED_DEVICE)[source]

A mutable list of groups of operations to apply to some qubits.

Methods returning information about the circuit:
next_moment_operating_on
prev_moment_operating_on
next_moments_operating_on
operation_at
all_qubits
all_operations
findall_operations
findall_operations_between
findall_operations_until_blocked
findall_operations_with_gate_type
reachable_frontier_from
has_measurements
are_all_matches_terminal
are_all_measurements_terminal
unitary
final_wavefunction
to_text_diagram
to_text_diagram_drawer
Methods for mutation:
insert
append
insert_into_range
clear_operations_touching
batch_insert
batch_remove
batch_insert_into
insert_at_frontier
Circuits can also be iterated over,
for moment in circuit:
and sliced,
circuit[1:3] is a new Circuit made up of two moments, the first being
circuit[1] and the second being circuit[2];
circuit[:, qubit] is a new Circuit with the same moments, but with only
those operations which act on the given Qubit;
circuit[:, qubits], where ‘qubits’ is list of Qubits, is a new Circuit
with the same moments, but only with those operations which touch
any of the given qubits;
circuit[1:3, qubit] is equivalent to circuit[1:3][:, qubit];
circuit[1:3, qubits] is equivalent to circuit[1:3][:, qubits];
and concatenated,
circuit1 + circuit2 is a new Circuit made up of the moments in circuit1
followed by the moments in circuit2;
and multiplied by an integer,
circuit * k is a new Circuit made up of the moments in circuit repeated
k times.
and mutated,
circuit[1:7] = [Moment(…)]
__init__(*contents: Union[cirq.ops.raw_types.Operation, cirq.ops.op_tree.OpTree], strategy: cirq.circuits.insert_strategy.InsertStrategy = cirq.InsertStrategy.EARLIEST, device: cirq.devices.device.Device = cirq.UNCONSTRAINED_DEVICE) → None[source]

Initializes a circuit.

Parameters
• contents – The initial list of moments and operations defining the circuit. You can also pass in operations, lists of operations, or generally anything meeting the cirq.OP_TREE contract. Non-moment entries will be inserted according to the specified insertion strategy.

• strategy – When initializing the circuit with operations and moments from contents, this determines how the operations are packed together. This option does not affect later insertions into the circuit.

• device – Hardware that the circuit should be able to run on.