qlauncher.hampy.debug#

Module with functionalities for debugging Hamiltonians and checking their boolean properties

Summary#

Classes:

TruthTable

Generates and analyzes a full truth table for a Hamiltonian represented as either an Equation or a qiskit.quantum_info.SparsePauliOp.

Reference#

class qlauncher.hampy.debug.TruthTable(equation: Equation | SparsePauliOp, return_int: bool = True)[source]#

Bases: object

Generates and analyzes a full truth table for a Hamiltonian represented as either an Equation or a qiskit.quantum_info.SparsePauliOp.

The class evaluates the Hamiltonian on all possible bitstrings of length size and exposes utilities for debugging, visualizing value distributions, and checking boolean properties (e.g., whether the Hamiltonian is binary-valued).

Parameters#

equationEquation or SparsePauliOp

Hamiltonian to evaluate. If an Equation is provided, its simplified SparsePauliOp is used. If a SparsePauliOp is provided, the number of qubits is inferred.

return_intbool, optional

Whether to cast diagonal values to integers. Defaults to True.

Examples#

From an Equation: >>> eq = Equation(2) >>> x0, x1 = eq[0], eq[1] >>> tt = TruthTable(x0 ^ x1) >>> tt.truth_table {‘00’: 0, ‘01’: 1, ‘10’: 1, ‘11’: 0}

From a SparsePauliOp: >>> from qiskit.quantum_info import SparsePauliOp >>> H = SparsePauliOp.from_sparse_list([(‘Z’, [0], 1.0)], 1) >>> tt = TruthTable(H) >>> tt[‘0’], tt[‘1’] (1, -1)

Get solutions for a given value: >>> tt.get_solutions(tt.lowest_value) [‘1’]

Check if the Hamiltonian is binary-valued: >>> tt.check_if_binary() # Hamiltonian is binary if all energy values ar either 0 or 1 False

Plot the distribution of output energies: >>> tt.plot_distribution()

Access row by integer or bitstring: >>> tt[0] 1 >>> tt[‘1’] -1

count(value: int) int[source]#
get_solutions(value: int) list[str][source]#
count_min_value_solutions() int[source]#
get_min_value_solutions() list[str][source]#
check_if_binary() bool[source]#
plot_distribution() None[source]#