fulqrum.core.QubitOperator

class QubitOperator

Operator class for qubit terms consisting of Pauli operators,projection operators, and ladder operators

Parameters:
  • width (int) – Number of qubits

  • operators (list) – List of tuples for terms in Hamiltonian

Example:

import fulqrum as fq
fq.QubitOperator(5, [("X1", [0, 3], -2), ("XZY", [2, 0, 4], 3)])
<QubitOperator[('X:0 1:3', (-2+0j)), ('Z:0 X:2 Y:4', (3+0j))], width=5>

Methods

add_operator(self, unsigned int qubit, ...)

append(self, QubitOperator other)

coefficients(self)

Return the coefficients for each term in the operator

combine_repeated_terms(self, double atol=1e-12)

Combine repeated terms that represent same operators, dropping terms smaller than requested tolerance.

constant_energy(self)

Value of the constant energy term(s) in the operator

copy(self)

Copy QubitOperator

extended(self)

Extended element flag for each term

from_constant(self, unsigned int width, ...)

Generate a constant Hamiltonian term

from_dict(self, dict dic)

QubitOperator from dictionary

from_json(self, filename)

Load operator from a JSON or XZ file.

from_label(self, string label, ...)

group_ladder_bin_starts(self)

group_offdiag_indices(self)

Off-diagonal indices for each group in operator

group_ptrs(self)

Get pointers to start and stop indices for off-diagonal grouping

group_rowint_length(self)

The length (number of bits) in the row int per group

group_term_sort_by_ladder_int(self, ...)

Sort groups by ladder integer if operator is type=2

groups(self)

Off-diagonal group structure of terms in operator

is_diagonal(self)

Check if operator is diagonal in computational basis

is_real(self)

Can operator be described via a symmetric matrix

ladder_ints(self)

Compute the ladder operator integer for each term

matrix_element(self, row, col)

Compute matrix element value at given row and column

max_offdiag_ptr_size(self)

Maximum number of elements in an off-diagonal pointer term

offdiag_ptrs(self)

Pointers for off-diagonal term sorting

offdiag_term_grouping(self)

Inplace sorting of operator terms according to off-diagonal structure.

offdiag_weight_ptrs(self)

Off-diagonal weight pointers for the operator

offdiag_weight_sort(self)

In-place sort terms by their off-diagonal weight

offdiag_weights(self)

Off-diagonal weight of each term in the operator

projector_oper_validation(self, Bitset bits)

Return array indicating which terms pass projector validation for a given bit-string

real_phases(self)

The real 'phase' of each term in operator

remove_constant_terms(self, ...)

Remove constant (identity) terms from operator, optionally returning the sum of the coefficients

set_type(self, unsigned int value)

Manually set the type of the operator

split_diagonal(self)

Spit an operator into diagonal and non-diagonal components

terms_by_group(self, int number)

Return terms in operator that correspond to input group number

to_dict(self)

Dictionary representation of QubitOperator

to_json(self, filename[, overwrite])

Save operator to a JSON or XZ file.

weight_sort(self)

In-place sort terms by their standard weight

weights(self)

Weight of each term in the operator

worst_case_offdiag_group_amplitudes(self)

Compute the worst case amplitude of off-diagonal groups.

Attributes

coeff

Return the coefficient of a Hamiltonian comprised from a single term

dtype

The data type of the operator

ladder_width

Ladder with

num_groups

Number of off-diagonal groupings

num_terms

Return the number of terms in the operator

off_weight_sorted

Is the operator sorted by off-diagonal weight

operators

Return the operators for a single term or empty operator

proj_indices

Return the projector indices for a single term or empty operator

sorted

Is the operator sorted by off-diagonal structure

type

Type of QubitOperator

weight_sorted

Is the operator sorted by full operator weight

width

Width (number of qubits) of the operator

add_operator(self, unsigned int qubit, str operator, bool overwrite=False)
append(self, QubitOperator other) void
coeff

Return the coefficient of a Hamiltonian comprised from a single term

Returns:

complex

coefficients(self)

Return the coefficients for each term in the operator

Returns:

complex-valued array of coefficients

Return type:

ndarray

combine_repeated_terms(self, double atol=1e-12)

Combine repeated terms that represent same operators, dropping terms smaller than requested tolerance.

Parameters:

atol (double) – Tolerance for dropping terms, default=1e-12

Returns:

Operator with repeat terms combined

Return type:

QubitOperator

constant_energy(self)

Value of the constant energy term(s) in the operator

Returns:

float

copy(self)

Copy QubitOperator

Returns:

QubitOperator

dtype

The data type of the operator

Returns:

Data type of operator

Return type:

type

extended(self)

Extended element flag for each term

Returns:

Array of ints indicating if terms are extended or not

Return type:

ndarray

classmethod from_constant(self, unsigned int width, double complex coeff)

Generate a constant Hamiltonian term

Parameters:
  • width (unsigned int) – Width of operator

  • coeff (complex) – Operator coefficient

Returns:

Constant operator

Return type:

QubitOperator

classmethod from_dict(self, dict dic)

QubitOperator from dictionary

Parameters:

dic (dict) – Dictionary representation of operator

Returns:

QubitOperator

classmethod from_json(self, filename)

Load operator from a JSON or XZ file.

Parameters:

filename (str) – File to load from

Returns:

QubitOperator

classmethod from_label(self, string label, double complex coeff=1.0)
group_ladder_bin_starts(self)
group_offdiag_indices(self)

Off-diagonal indices for each group in operator

group_ptrs(self)

Get pointers to start and stop indices for off-diagonal grouping

Returns:

Array of ints giving pointers to group starts and stops

Return type:

ndarray

group_rowint_length(self)

The length (number of bits) in the row int per group

group_term_sort_by_ladder_int(self, unsigned int ladder_width=4)

Sort groups by ladder integer if operator is type=2

Raises:

FulqrumError – Operator is NOT type=2

groups(self)

Off-diagonal group structure of terms in operator

Returns:

Array of ints indicating group of each term

Return type:

ndarray

is_diagonal(self) int

Check if operator is diagonal in computational basis

Returns:

True if diagonal, False otherwise

Return type:

int

is_real(self)

Can operator be described via a symmetric matrix

Returns:

Is operator real-valued

Return type:

int

ladder_ints(self)

Compute the ladder operator integer for each term

If no ladder ops present then default int is max(uint32)

Parameters:

ladder_width (int) – Number of ladder terms to consider, default = 4

Returns:

Array of uint32 integers

Return type:

ndarray

ladder_width

Ladder with

Returns:

Ladder width

Return type:

int

matrix_element(self, row, col)

Compute matrix element value at given row and column

Parameters:
  • row (str or int) – Row index

  • col (str or int) – Column index

Returns:

Element value at H[row, col]

Return type:

complex

max_offdiag_ptr_size(self)

Maximum number of elements in an off-diagonal pointer term

Returns:

Number of terms

Return type:

int

num_groups

Number of off-diagonal groupings

Returns:

Number of groups in operator

Return type:

int

num_terms

Return the number of terms in the operator

Returns:

Number of terms in operator

Return type:

int

off_weight_sorted

Is the operator sorted by off-diagonal weight

Returns:

Operator is sorted by off-diagonal weight

Return type:

bool

offdiag_ptrs(self)

Pointers for off-diagonal term sorting

Returns:

Array of type size_t

Return type:

ndarray

offdiag_term_grouping(self)

Inplace sorting of operator terms according to off-diagonal structure.

offdiag_weight_ptrs(self)

Off-diagonal weight pointers for the operator

Returns:

Array of off-diagonal weight pointers

Return type:

ndarray

offdiag_weight_sort(self)

In-place sort terms by their off-diagonal weight

offdiag_weights(self)

Off-diagonal weight of each term in the operator

Returns:

Array of operator off-diagonal weights

Return type:

ndarray

operators

Return the operators for a single term or empty operator

Returns:

List of operator index tuples, if any, else None

Return type:

list or None

Notes

This returns a list of tuples to allow for multiple indices in Fermionic operators

proj_indices

Return the projector indices for a single term or empty operator

projector_oper_validation(self, Bitset bits)

Return array indicating which terms pass projector validation for a given bit-string

Parameters:

bits (Bitset) – bit-string of interest

Returns:

ndarray

real_phases(self)

The real ‘phase’ of each term in operator

Returns:

real phase of each term in operator

Return type:

ndarray

remove_constant_terms(self, bool return_value=True)

Remove constant (identity) terms from operator, optionally returning the sum of the coefficients

Parameters:

return_value (bool) – Return the sum of constant term coefficients, default=True

Returns:

Operator with no identity terms complex: Sum of identity coefficients, if return_value=True

Return type:

QubitOperator

set_type(self, unsigned int value)

Manually set the type of the operator

Parameters:

value (int) – Set 1 for a standard qubit Hamiltonian, and 2 for fermionic

Note

This is usually automatically set for you, with type=2 being set during the conversion from FermionicOperator to QubitOperator

sorted

Is the operator sorted by off-diagonal structure

Returns:

Operator is sorted

Return type:

bool

split_diagonal(self)

Spit an operator into diagonal and non-diagonal components

Returns:

QubitOperators for diagonal and non-diagonal parts

Return type:

tuple

terms_by_group(self, int number)

Return terms in operator that correspond to input group number

Parameters:

number (int) – Group number

Returns:

QubitOperator

to_dict(self)

Dictionary representation of QubitOperator

Returns:

Dictionary representation of QubitOperator

Return type:

dict

to_json(self, filename, overwrite=False)

Save operator to a JSON or XZ file. File extension can be ‘json’ or ‘xz’, the latter or which does LZMA compression which is recommended for large operators.

Parameters:
  • filename (str) – File to store to

  • overwrite (bool) – Overwrite file if it exits, default=False

type

Type of QubitOperator

Type 1 is standard Qubit systems, e.g. Paulis and projectors Type 2 is for systems derived from Fermionic systems via extended JW

Returns:

Type of operator

Return type:

int

weight_sort(self)

In-place sort terms by their standard weight

weight_sorted

Is the operator sorted by full operator weight

Returns:

Operator is sorted by full weight

Return type:

bool

weights(self)

Weight of each term in the operator

Returns:

Array of operator weights

Return type:

ndarray

width

Width (number of qubits) of the operator

Returns:

Width of operator

Return type:

int

worst_case_offdiag_group_amplitudes(self)

Compute the worst case amplitude of off-diagonal groups.

Requires input operator to be purely off-diagonal

Parameters:

off (QubitOperator) – Off-diagonal qubit operator

Returns:

Worse case amplitudes of groups

Return type:

ndarray