ValueError: if the circuit has gates that are not supported or
is otherwise invalid.
if len(circuit) == 0:
raise ValueError("Cannot serialize empty circuit.")
all_qubits = circuit.all_qubits()
if any(not isinstance(q, line_qubit.LineQubit) for q in all_qubits):
raise ValueError(
f"All qubits must be cirq.LineQubits but were {set(type(q) for q in all_qubits)}"
)
num_qubits = cast(line_qubit.LineQubit, max(all_qubits)).x + 1
return {"qubits": num_qubits, "circuit": self._serialize_circuit(circuit, num_qubits)}
def _serialize_circuit(self, circuit: "cirq.Circuit", num_qubits: int) -> list:
return [self._serialize_op(op) for moment in circuit for op in moment]