openql¶
OpenQL is a C++/Python framework for high-level quantum programming. The framework provides a compiler for compiling and optimizing quantum code. The compiler produces the intermediate quantum assembly language in cQASM (Common QASM) and the compiled eQASM (executable QASM) for various target platforms. While the eQASM is platform-specific, the quantum assembly code (QASM) is hardware-agnostic and can be simulated on the QX simulator.
Functions
get_option (option_name) |
Returns value of any of the following OpenQL options: |
get_version () |
Returns OpenQL version |
print_options () |
Prints a list of available OpenQL options with their values. |
set_option (option_name, option_value) |
Sets any of the following OpenQL options: |
Classes
CReg () |
Classical register class. |
Kernel (*args) |
Kernel class which contains various quantum instructions. |
Operation (*args) |
Operation class representing classical operations. |
Platform (*args) |
Platform class specifying the target platform to be used for compilation. |
Program (*args) |
Program class which contains one or more kernels. |
Compiler (name) |
Compiler class which contains one or more compiler passes. |
-
class
openql.openql.
CReg
Classical register class.
-
class
openql.openql.
Compiler
(name) Compiler class which contains one or more compiler passes.
-
add_pass
(realPassName) - Adds a compiler pass under its real name
Parameters: arg1 (str) – name of the real pass to be added.
-
add_pass_alias
(realPassName, symbolicPassName) - Adds a compiler pass under an alias name
Parameters: - arg1 (str) – name of the real pass to be added.
- arg2 (str) – alias name of the pass to be added.
-
compile
(program) - Compiles the program
Parameters: arg1 (Program) – program object to be compiled.
-
set_pass_option
(passName, optionName, optionValue) - Sets a compiler pass option
Parameters: - arg1 (str) – name (real or alias) of the compiler pass to be added.
- arg2 (str) – option name of the option to be configured.
- arg3 (str) – value of the option.
-
-
class
openql.openql.
Kernel
(*args) Kernel class which contains various quantum instructions.
-
barrier
(*args) inserts explicit barrier on specified qubits.
wait with duration ‘0’ is also equivalent to applying barrier on specified list of qubits. If no qubits are specified, then barrier is applied on all the qubits.Parameters: arg1 ([]) – list of qubits
-
classical
(*args) - adds classical operation kernel.
Parameters:
-
clifford
(id, q0) - Applies clifford operation of the specified id on the qubit.
The ids and the corresponding operations are:
id Operations 0 [‘I’] 1 [‘Y90’, ‘X90’] 2 [‘mX90’, ‘mY90’] 3 [‘X180’] 4 [‘mY90’, ‘mX90’] 5 [‘X90’, ‘mY90’] 6 [‘Y180’] 7 [‘mY90’, ‘X90’] 8 [‘X90’, ‘Y90’] 9 [‘X180’, ‘Y180’] 10 [‘Y90’, ‘mX90’] 11 [‘mX90’, ‘Y90’] 12 [‘Y90’, ‘X180’] 13 [‘mX90’] 14 [‘X90’, ‘mY90’, ‘mX90’] 15 [‘mY90’] 16 [‘X90’] 17 [‘X90’, ‘Y90’, ‘X90’] 18 [‘mY90’, ‘X180’] 19 [‘X90’, ‘Y180’] 20 [‘X90’, ‘mY90’, ‘X90’] 21 [‘Y90’] 22 [‘mX90’, ‘Y180’] 23 [‘X90’, ‘Y90’, ‘mX90’] Parameters: - arg1 (int) – clifford operation id
- arg2 (int) – target qubit
-
cnot
(q0, q1) - Applies controlled-not operation.
Parameters: - arg1 (int) – control qubit
- arg2 (int) – target qubit
-
conjugate
(k) - generates conjugate version of the kernel from the input kernel.
Parameters: arg1 (ql::Kernel) – input kernel. Except measure, Kernel to be conjugated. Returns: Return type: None
-
controlled
(k, control_qubits, ancilla_qubits) - generates controlled version of the kernel from the input kernel.
Parameters: - arg1 (ql::Kernel) – input kernel. Except measure, Kernel to be controlled may contain any of the default gates as well custom gates which are not specialized for a specific qubits.
- arg2 ([]) – list of control qubits.
- arg3 ([]) – list of ancilla qubits. Number of ancilla qubits should be equal to number of control qubits.
Returns: Return type: None
-
cphase
(q0, q1) - Applies controlled-phase operation.
Parameters: - arg1 (int) – control qubit
- arg2 (int) – target qubit
-
display
() - inserts QX display instruction (so QX specific).
Parameters: None – Returns: Return type: None
-
gate
(*args) - adds unitary to kernel.
Parameters: - arg1 (Unitary) – unitary matrix
- arg2 ([]) – list of qubits
-
get_custom_instructions
() - Returns list of available custom instructions.
Parameters: None – Returns: List of available custom instructions Return type: []
-
hadamard
(q0) - Applies hadamard on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
identity
(q0) - Applies identity on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
measure
(q0) - measures input qubit.
Parameters: arg1 (int) – input qubit
-
mrx90
(q0) - Applies mrx90 on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
rx180
(q0) - Applies rx180 on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
rx90
(q0) - Applies rx90 on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
ry180
(q0) - Applies ry180 on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
s
(q0) - Applies x on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
sdag
(q0) - Applies sdag on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
toffoli
(q0, q1, q2) - Applies controlled-controlled-not operation.
Parameters: - arg1 (int) – control qubit
- arg2 (int) – control qubit
- arg3 (int) – target qubit
-
wait
(qubits, duration) inserts explicit wait of specified duration on specified qubits.
wait with duration ‘0’ is equivalent to barrier on specified list of qubits. If no qubits are specified, then wait/barrier is applied on all the qubits.Parameters: - arg1 ([]) – list of qubits
- arg2 (int) – duration in ns
-
y
(q0) - Applies y on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
z
(q0) - Applies z on the qubit specified in argument.
Parameters: arg1 (int) – target qubit
-
-
class
openql.openql.
Operation
(*args) Operation class representing classical operations.
-
class
openql.openql.
Platform
(*args) Platform class specifying the target platform to be used for compilation.
-
get_qubit_number
() - returns number of qubits in the platform.
Parameters: None – Returns: number of qubits Return type: int
-
-
class
openql.openql.
Program
(*args) Program class which contains one or more kernels.
-
add_do_while
(*args) - Adds specified sub-program to a program which will be repeatedly executed while specified condition is true.
Parameters:
-
add_for
(*args) - Adds specified sub-program to a program which will be executed for specified iterations.
Parameters: - arg1 (Program) – sub-program to be executed repeatedly
- arg2 (int) – iteration count
-
add_if
(*args) - Adds specified sub-program to a program which will be executed if specified condition is true. This allows nesting of operations.
Parameters:
-
add_if_else
(*args) - Adds specified sub-programs to a program. First sub-program will be executed if specified condition is true. Second sub-program will be executed if specified condition is false.
Parameters:
-
add_kernel
(k) - Adds specified kernel to program.
Parameters: arg1 (kernel) – kernel to be added
-
compile
() - Compiles the program
Parameters: None –
-
get_sweep_points
() - Returns sweep points for an experiment.
Parameters: None – Returns: list of sweep points Return type: []
-
microcode
() - Returns program microcode
Parameters: None – Returns: microcode Return type: str
-
set_sweep_points
(sweep_points) - Sets sweep points for an experiment.
Parameters: arg1 ([]) – list of sweep points
-
-
class
openql.openql.
Unitary
(name, matrix) Unitary class to hold the matrix and its decomposition
-
decompose
() - Decomposes the unitary matrix
Parameters: None – Returns: Return type: None
-
-
class
openql.openql.
cQasmReader
(q_platform, q_program) cQasmReader class specifies an interface to add cqasm programs to a program.
-
file2circuit
(cqasm_file_path) - Adds a cqasm program read from a file.
Parameters: arg1 (str) – File path to the file specifying the cqasm that is added to the program.
-
string2circuit
(cqasm_str) - Adds a cqasm program defined in a string.
Parameters: arg1 (str) – The cqasm that is added to the program.
-
-
openql.openql.
get_option
(option_name) - Returns value of any of the following OpenQL options:
Opt. Name Defaults Possible values log_level LOG_NOTHING LOG_{NOTHING/CRITICAL/ERROR/WARNING/INFO/DEBUG} output_dir test_output <output directory> optimize no yes/no use_default_gates yes yes/no decompose_toffoli no yes/no scheduler ASAP ASAP/ALAP scheduler_uniform no yes/no scheduler_commute no yes/no scheduler_post179 yes yes/no cz_mode manual auto/manual Parameters: arg1 (str) – Option name Returns: Option value Return type: str
-
openql.openql.
get_version
() - Returns OpenQL version
Parameters: None – Returns: version number as a string Return type: str
-
openql.openql.
print_options
() Prints a list of available OpenQL options with their values.
-
openql.openql.
set_option
(option_name, option_value) - Sets any of the following OpenQL options:
Opt. Name Defaults Possible values log_level LOG_NOTHING LOG_{NOTHING/CRITICAL/ERROR/WARNING/INFO/DEBUG} output_dir test_output <output directory> optimize no yes/no use_default_gates yes yes/no decompose_toffoli no yes/no scheduler ASAP ASAP/ALAP scheduler_uniform no yes/no scheduler_commute no yes/no scheduler_post179 yes yes/no cz_mode manual auto/manual Parameters: - arg1 (str) – Option name
- arg2 (str) – Option value