cirq.Circuit

class cirq.Circuit(moments: Iterable[cirq.ops.moment.Moment] = (), device: cirq.devices.device.Device = cirq.UnconstrainedDevice)[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_with_gate_type
are_all_measurements_terminal
to_unitary_matrix
apply_unitary_effect_to_state
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];
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__(moments: Iterable[cirq.ops.moment.Moment] = (), device: cirq.devices.device.Device = cirq.UnconstrainedDevice) → None[source]

Initializes a circuit.

Parameters:
  • moments – The initial list of moments defining the circuit.
  • device – Hardware that the circuit should be able to run on.

Methods

all_operations() Iterates over the operations applied by this circuit.
all_qubits() Returns the qubits acted upon by Operations in this circuit.
append(moment_or_operation_tree, …) Appends operations onto the end of the circuit.
apply_unitary_effect_to_state(initial_state, …) Left-multiplies a state vector by the circuit’s unitary effect.
are_all_measurements_terminal()
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.
copy()
findall_operations(predicate, bool]) 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_with_gate_type(gate_type) Find the locations of all gate operations of a given type.
from_ops(*operations, strategy, device) Creates an empty circuit and appends the given operations.
insert(index, moment_or_operation_tree, …)
Inserts operations into the circuit.
insert_at_frontier(operations, …) Inserts operations inline at frontier.
insert_into_range(operations, …) 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.
reachable_frontier_from(start_frontier, …) Determines how far can be reached into a circuit under certain rules.
save_qasm(file_path, bytes, int], header, …) 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.
to_unitary_matrix(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.

Attributes

device