[docs]defdumps(circuit:QuantumCircuit)->str:"""Return the cQASM representation of the circuit."""builder=CircuitBuilder(circuit.num_qubits,circuit.num_clbits)forcircuit_instructionincircuit.data:operation=circuit_instruction.operationname=operation.nameparams=[Float(param)forparaminoperation.params]qubit_operands=[Qubit(qubit._index)forqubitincircuit_instruction.qubits]clbit_operands=[Bit(clbit._index)forclbitincircuit_instruction.clbits]# Only used as circuit compilation directiveifname=="barrier":continuetry:# Get the gate's method in the CircuitBuilder class, call with operands# All of the builder's methods follow the same pattern, first the qubit operands, then parameters# Only method with classical bit operands is measure, which does not have parametersgetattr(builder,_QISKIT_TO_OPENSQUIRREL_MAPPING[name])(*qubit_operands,*clbit_operands,*params)exceptKeyError:raiseNotImplementedError(f"Unsupported instruction: {name}. Please edit your circuit or use Qiskit transpilation to support "+"your selected backend.")cqasm:str=writer.circuit_to_string(builder.to_circuit())returncqasm