uniqc.circuit_builder.random_qasm module#
Random OpenQASM 2.0 circuit generator.
This module provides functions for generating random quantum circuits in OpenQASM 2.0 format. It supports random gate selection, measurement generation, and circuit construction from opcode lists.
- Key exports:
build_qasm_gate: Build a single QASM gate string. build_full_measurements: Generate measurement instructions for all qubits. build_measurements: Generate measurement instructions for specified qubits. random_qasm: Generate a complete random QASM program. build_qasm_from_opcodes: Convert a list of opcodes to QASM code.
- uniqc.circuit_builder.random_qasm.build_full_measurements(n_qubits, qreg_name='q', creg_name='c')[source]#
Build a QASM string that measures all qubits in the given qreg to the given creg.
- uniqc.circuit_builder.random_qasm.build_measurements(measure_qbit_cbit_pairs, qreg_name='q', creg_name='c')[source]#
Build a QASM string that measures specified qubits to classical bits.
- uniqc.circuit_builder.random_qasm.build_qasm_from_opcodes(opcode_list, measure_qbit_cbit=None, qreg_name='q', creg_name='c')[source]#
Generate a QASM code from a list of opcodes.
- Parameters:
opcode_list (List[Tuple[str, List[int], List[float]]]) – a list of tuples containing the gate name, qubits, and parameters
measure_qbit_cbit (List[Tuple[int, int]]) – a list of tuples containing the qubit and cbit to measure
qreg_name (str) – name of the qreg to measure from
creg_name (str) – name of the creg to measure to
- Returns:
a QASM code
- Return type:
- uniqc.circuit_builder.random_qasm.build_qasm_gate(gate, qubits, params, qreg_name='q')[source]#
Build a QASM gate string with the given gate, qubits, and parameters.
- uniqc.circuit_builder.random_qasm.random_qasm(n_qubits, n_gates, instruction_set={'c3x': {'params': 0, 'qubit': 4}, 'ccx': {'params': 0, 'qubit': 3}, 'crx': {'params': 1, 'qubit': 2}, 'cry': {'params': 1, 'qubit': 2}, 'crz': {'params': 1, 'qubit': 2}, 'cswap': {'params': 0, 'qubit': 3}, 'cu1': {'params': 1, 'qubit': 2}, 'cx': {'params': 0, 'qubit': 2}, 'cy': {'params': 0, 'qubit': 2}, 'cz': {'params': 0, 'qubit': 2}, 'h': {'params': 0, 'qubit': 1}, 'id': {'params': 0, 'qubit': 1}, 'rx': {'params': 1, 'qubit': 1}, 'rxx': {'params': 1, 'qubit': 2}, 'ry': {'params': 1, 'qubit': 1}, 'rz': {'params': 1, 'qubit': 1}, 'rzz': {'params': 1, 'qubit': 2}, 's': {'params': 0, 'qubit': 1}, 'sdg': {'params': 0, 'qubit': 1}, 'swap': {'params': 0, 'qubit': 2}, 'sx': {'params': 0, 'qubit': 1}, 'sxdg': {'params': 0, 'qubit': 1}, 't': {'params': 0, 'qubit': 1}, 'tdg': {'params': 0, 'qubit': 1}, 'u': {'params': 3, 'qubit': 1}, 'u1': {'params': 1, 'qubit': 1}, 'u2': {'params': 2, 'qubit': 1}, 'u3': {'params': 3, 'qubit': 1}, 'x': {'params': 0, 'qubit': 1}, 'y': {'params': 0, 'qubit': 1}, 'z': {'params': 0, 'qubit': 1}}, measurements=True)[source]#
Generate a random QASM code with n_qubits and n_gates from the given instruction set.