Skip to main contentIBM Quantum Documentation
Important

IBM Quantum Platform is moving and this version will be sunset on July 1. To get started on the new platform, read the migration guide.

QkObsTerm

This is a group of functions for interacting with an opaque (Rust-space) SparseTerm instance.


Data types

QkObsTerm

struct QkObsTerm

A term in a QkObs.

This contains the coefficient (coeff), the number of qubits of the observable (num_qubits) and pointers to the bit_terms and indices arrays, which have length len. It’s the responsibility of the user that the data is coherent, see also the below section on safety.

Safety

  • bit_terms must be a non-null, aligned pointer to len elements of type QkBitTerm.
  • indices must be a non-null, aligned pointer to len elements of type uint32_t.

QkComplex64 coeff

The coefficient of the observable term.

uintptr_t len

Length of the bit_terms and indices arrays.

QkBitTerm *bit_terms

A non-null, aligned pointer to len elements of type QkBitTerm.

uint32_t *indices

A non-null, aligned pointer to len elements of type uint32_t.

uint32_t num_qubits

The number of qubits the observable term is defined on.


Functions

qk_obsterm_str

char *qk_obsterm_str(const QkObsTerm *term)

Return a string representation of the sparse term.

Example

QkObs *obs = qk_obs_identity(100);
QkObsTerm term;
qk_obs_term(obs, 0, &term);
char *string = qk_obsterm_str(&term);
qk_str_free(string);

Safety

Behavior is undefined term is not a valid, non-null pointer to a QkObsTerm.

The string must not be freed with the normal C free, you must use qk_str_free to free the memory consumed by the String. Not calling qk_str_free will lead to a memory leak.

Do not change the length of the string after it’s returned, although values can be mutated.

Parameters

term – A pointer to the term.

Returns

The function exit code. This is >0 if reading the term failed.

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