Skip to main content
IBM Quantum Platform

QkQuantumRegister

typedef struct QkQuantumRegister QkQuantumRegister

A common way to instantiate several bits at once is to create a register. A register is a named collection of bits. Creating a register enables giving a collection of bits a name which can be use as metadata around specific bits in a circuit. This name will also typically be preseserved when exporting the circuit to interchange languages.

You can create a register by calling qk_quantum_register_new(), for example:

Which creates a new 5 qubit register named "my_qreg".

Then to add the register to a circuit you use the qk_circuit_add_quantum_register() function:

While circuits track registers, the registers themselves impart almost no behavioral differences on circuits.


Functions

qk_quantum_register_new

QkQuantumRegister *qk_quantum_register_new(uint32_t num_qubits, const char *name)

Construct a new owning quantum register with a given number of qubits and name

Example

QkQuantumRegister *qr = qk_quantum_register_new(5, "five_qubits");

Safety

The name parameter must be a pointer to memory that contains a valid nul terminator at the end of the string. It also must be valid for reads of bytes up to and including the nul terminator.

Parameters

  • num_qubits – The number of qubits to create the register for
  • name – The name string for the created register. The name must be comprised of valid UTF-8 characters.

Returns

A pointer to the created register

qk_quantum_register_free

void qk_quantum_register_free(QkQuantumRegister *reg)

Free a quantum register.

Example

QkQuantumRegister *qr = qk_quantum_register_new(1024, "qreg");
qk_quantum_register_free(qr);

Safety

Behavior is undefined if reg is not either null or a valid pointer to a QkQuantumRegister.

Parameters

reg – A pointer to the register to free.

Was this page helpful?
Report a bug or request content on GitHub.