# 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.

Methods

 Iterates over the operations applied by this circuit. Returns the qubits acted upon by Operations in this circuit. append(moment_or_operation_tree[, strategy]) Appends operations onto the end of the circuit. are_all_matches_terminal(predicate) Check whether all of the ops that satisfy a predicate are terminal. Whether all measurement gates are at the end of the circuit. batch_insert(insertions) Applies a batched insert operation to the circuit. batch_insert_into(insert_intos) Inserts operations into empty spaces in existing moments. batch_remove(removals) Removes several operations from a circuit. clear_operations_touching(qubits, moment_indices) Clears operations that are touching given qubits at given moments. final_wavefunction([initial_state, …]) Left-multiplies a state vector by the circuit’s unitary effect. findall_operations(predicate) Find the locations of all operations that satisfy a given condition. findall_operations_between(start_frontier, …) Finds operations between the two given frontiers. findall_operations_until_blocked(start_frontier) Finds all operations until a blocking operation is hit. findall_operations_with_gate_type(gate_type) Find the locations of all gate operations of a given type. insert(index, moment_or_operation_tree[, …]) Inserts operations into the circuit. insert_at_frontier(operations, start[, frontier]) Inserts operations inline at frontier. insert_into_range(operations, start, end) Writes operations inline into an area of the circuit. next_moment_operating_on(qubits[, …]) Finds the index of the next moment that touches the given qubits. next_moments_operating_on(qubits[, …]) Finds the index of the next moment that touches each qubit. operation_at(qubit, moment_index) Finds the operation on a qubit within a moment, if any. prev_moment_operating_on(qubits[, …]) Finds the index of the next moment that touches the given qubits. qid_shape([qubit_order]) reachable_frontier_from(start_frontier, *[, …]) Determines how far can be reached into a circuit under certain rules. save_qasm(file_path[, header, precision, …]) Save a QASM file equivalent to the circuit. to_qasm([header, precision, qubit_order]) Returns QASM equivalent to the circuit. to_text_diagram(*[, use_unicode_characters, …]) Returns text containing a diagram describing the circuit. to_text_diagram_drawer(*[, …]) Returns a TextDiagramDrawer with the circuit drawn into it. transform_qubits(func, *[, new_device]) Returns the same circuit, but with different qubits. unitary([qubit_order, …]) Converts the circuit into a unitary matrix, if possible. with_device(new_device[, qubit_mapping]) Maps the current circuit onto a new device, and validates. with_noise(noise) Make a noisy version of the circuit.

Attributes