qbitkit.qasm.generate module

qbitkit.qasm.generate.comment(self='')[source]

Generate a single-line QASM 2.0 comment from a string.

Parameters

self (str) – String to add as a comment in QASM 2.0 (default str(‘’))

Returns

str – Generated QASM 2.0 comment.

qbitkit.qasm.generate.headers(qasm_version=2.0, includes=['qelib1.inc'])[source]

Generate QASM 2.0 formatted headers.

Parameters
  • qasm_version (float) – a floating point value describing the version number. (default float(2.0))

  • includes (list) – a list of strings describing what to import. (default list([‘qelib1.inc’]))

Returns

str – the generated headers to be placed at the top of a QASM string

qbitkit.qasm.generate.registers(c=None, q=None)[source]

Generate a QASM String containing the specified number of classical and quantum registers.

Parameters
  • c (int) – The number of Classic registers. (default None)

  • q (int) – The number of Quantum registers, in other words the number of logical Qubits. (default None)

Returns

str – A string object containing the generated QASM.

qbitkit.qasm.generate.gate(self='h', targetA=None, targetB=None, targetC=None, angle=None, theta=None, Utheta=None, Uphi=None, Ulambda=None, custom_name=None, custom_params=None)[source]

Generate a gate from it’s name as a string passed to self, and a list of targets passed to targets.

Parameters
  • self (str) – The name used to represent the gate in QASM. For example, a Hadamard Gate is ‘h’. (default str(‘h’))

  • targetA (int) – First target qubit. (default None)

  • targetB (int) – Second target qubit. (default None)

  • targetC (int) – Third target qubit. (default None)

  • angle (float) – Angle to specify in Radians for rotation gates like RX, RY, RZ. (default None)

  • theta (float) – Theta value in to specify for rotation gates like RX, RY, RZ. Exactly the same as the angle parameter. (default None)

  • Utheta (str) – Theta value for U-gates. (default None)

  • Uphi (str) – Phi value for U-gates. (default None)

  • Ulambda (str) – Lambda value for U-gates. (default None)

  • custom_name (str) – Name for user-defined opaque gate declarations, unitary gate declarations, and user-defined unitary gates. (default None)

  • custom_params (str) – Parameters for user-defined opaque gate declarations, unitary gate declarations, and user-defined unitary gates. (default None)

Returns

str – A string object containing the specified gate as QASM.

qbitkit.qasm.generate.measurement(qreg=0, creg=0)[source]

Generate QASM that takes a measurement from a qubit and stores it in a classical register.

Parameters
  • qreg (int) – Number of the Qubit to measure. (default 0)

  • creg (int) – Number of the Classical Register to store the measurement to. (default 1)

Returns

str – Generated QASM containing measurement instruction.

qbitkit.qasm.generate.if_statement(creg_name='c', operator='==', creg_val=0, gate_name='x', targetA=None, targetB=None, targetC=None, Utheta=None, Uphi=None, Ulambda=None, custom_name=None, custom_params=None)[source]

Generate a gate controlled by a classical if statement as a QASM string from specified parameters.

Parameters
  • creg_name (str) – Classical register to run if statement against. (default ‘c’)

  • operator (str) – Operator to compare values with. (default str(‘==’))

  • creg_val (int) – Value to compare with creg_name. (default int(0))

  • gate_name (str) – The name used to represent the gate in QASM. For example, a Hadamard Gate is ‘h’. (default str(‘h’))

  • targetA (int) – First target qubit. (default None)

  • targetB (int) – Second target qubit. (default None)

  • targetC (int) – Third target qubit. (default None)

  • Utheta (float) – Theta value for U-gates. (default None)

  • Uphi (float) – Phi value for U-gates. (default None)

  • Ulambda (float) – Lambda value for U-gates. (default None)

  • custom_name (str) – Name for user-defined opaque gate declarations, unitary gate declarations, and user-defined unitary gates. (default None)

  • custom_params (str) – Parameters for user-defined opaque gate declarations, unitary gate declarations, and user-defined unitary gates. (default None)

Returns

str – A string object containing the specified gate as QASM.