def serialize_many_circuits(
        self,
        circuits: list[cirq.AbstractCircuit],
        job_settings: dict | None = None,
        error_mitigation: dict | None = None,
    ) -> SerializedProgram:
        """Serialize the given array of circuits.

        Raises:
            ValueError: if the circuit has gates that are not supported or is otherwise invalid.
            IonQSerializerMixedGatesetsException: if not all input circuits have the same type
            of gates: either 'qis' or 'native' gates.
        """
        for circuit in circuits:
            self._validate_circuit(circuit)
            self._validate_qubits(circuit.all_qubits())

        num_qubits = max([self._num_qubits(circuit) for circuit in circuits])

        gateset = None
        for circuit in circuits:
            current_gateset = "qis" if not _NATIVE_GATES.validate(circuit) else "native"
            if gateset is None:
                gateset = current_gateset
            if current_gateset != gateset:
                raise IonQSerializerMixedGatesetsException(
                    "For batch circuit submission, all circuits in a batch must contain "
                    "the same type of gates: either 'qis' or 'native' gates."
                )

        # IonQ API does not support measurements, so we pass the measurement keys through
        # the metadata field.  Here we split these out of the serialized ops.
        body: dict[str, Any] = {'gateset': gateset, 'qubits': num_qubits, 'circuits': []}

        measurements = []
        qubit_numbers = []
        for circuit in circuits:
            serialized_ops = self._serialize_circuit(circuit)
            body['circuits'].append(
                {'circuit': [op for op in serialized_ops if op['gate'] != 'meas']}
            )
            measurements.append(
                (self._serialize_measurements(op for op in serialized_ops if op['gate'] == 'meas'))
            )
            qubit_numbers.append(self._num_qubits(circuit))

        return SerializedProgram(
            body=body,
            metadata={
                "measurements": json.dumps(measurements),
                "qubit_numbers": json.dumps(qubit_numbers),
            },
            settings=(job_settings or {}),
            error_mitigation=error_mitigation,
        )
Serialize the given array of circuits.

        Raises:
            ValueError: if the circuit has gates that are not supported or is otherwise invalid.
            IonQSerializerMixedGatesetsException: if not all input circuits have the same type
            of gates: either 'qis' or 'native' gates.
        
cirq-ionq/cirq_ionq/serializer.py