uniqc.circuit_builder.opcode module#
This file is used to convert the opcode to various quantum code formats.
- uniqc.circuit_builder.opcode.make_header_originir(qubit_num, cbit_num)[source]#
Generate the header of OriginIR code for the given qubit and cbit number.
- uniqc.circuit_builder.opcode.make_header_qasm(qubit_num, cbit_num)[source]#
Generate the header of QASM code for the given qubit and cbit number.
- uniqc.circuit_builder.opcode.make_measure_originir(measure_list)[source]#
Generate the measure statement of OriginIR code for the given measure list.
- uniqc.circuit_builder.opcode.make_measure_qasm(measure_list)[source]#
Generate the measure statement of QASM code for the given measure list.
- uniqc.circuit_builder.opcode.opcode_to_line_originir(opcode)[source]#
Convert the given opcode to OriginIR line format.
opcodeis a tuple with layout(operation, qubit, cbit, parameter, dagger_flag, control_qubits_set):operation(str): name of the operation.qubit(QubitType): qubit(s) the operation is applied to.cbit(CbitType): classical bit(s) the result is stored in.parameter(ParameterType): parameter(s) of the operation.dagger_flag(bool): whether the operation is daggered.control_qubits_set(set): set of control qubits.
Type aliases used above:
QubitType = Union[List[int], int] CbitType = Union[List[int], int] ParameterType = Optional[Union[List[float], float]] OpcodeType = Tuple[str, QubitType, CbitType, ParameterType, set, bool]
- Parameters:
opcode (OpcodeType) – The given opcode to be converted.
- Returns:
The converted OriginIR line format.
- Return type:
- uniqc.circuit_builder.opcode.opcode_to_line_qasm(opcode, qubit_num=None)[source]#
Convert the given opcode to QASM line format.
For gates with ≥ 4 control qubits, a multi-line decomposition is returned (Toffoli-ladder for MCX; conjugation or ABC decomposition for other gates). The qubit_num argument must be supplied in that case so workspace qubits can be located; otherwise a NotImplementedError is raised.
- Parameters:
opcode (OpcodeType) – The given opcode to be converted.
qubit_num (Optional[int]) – Total number of qubits in the circuit (needed for multi-controlled gate decomposition with ≥ 4 controls).
- Returns:
The converted QASM line format (potentially multi-line for multi-controlled gate decompositions).
- Return type: