peropq.bch_optimized

Classes

NormTerm

Class representing a term to be taken into account in the norm.

VariationalNorm

Class representing the perturbative norm with some variational parameters. It is used in the optimization process.

Functions

_get_non_zero_trace_indices(bitstrings)

Get all the the term indices which have non zero trace, i.e Tr(term[i]*term[j])!=0.

_loop_over_trace(trace_list, indices, theta, ...)

Just in timed compiled function which computes the norm once all the traces are calculated.

_is_pauli_string(to_test)

_is_norm_term(to_test)

commutator(aterm, other)

Take the commutator between two NormTerm instances.

Module Contents

peropq.bch_optimized._get_non_zero_trace_indices(bitstrings)

Get all the the term indices which have non zero trace, i.e Tr(term[i]*term[j])!=0.

Works directly at the bitstring level. :param bitstring: array containing bitstrings one which to compute the trace over. :returns: an array containing the qubit indices on which the Pauli string does not have identity.

Parameters:

bitstrings (numpy.typing.NDArray)

Return type:

numpy.typing.NDArray

peropq.bch_optimized._loop_over_trace(trace_list, indices, theta, min_order, all_the_orders, all_the_indices, begin_list, end_list, all_the_coefficients)

Just in timed compiled function which computes the norm once all the traces are calculated.

Parameters:
  • trace_list (numpy.typing.NDArray) – array containing all the non zero traces

  • indices (numpy.typing.NDArray) – array containing the indices corresponding to every trace

  • theta (numpy.typing.NDArray) – variational parameters

  • min_order (int) – minimum order to be taken into the calculation (i.e. 0 for uncontrained and 1 for contrained)

  • all_the_orders (numpy.typing.NDArray) – array containaing the order of every term included in the terms

  • all_the_indices (numpy.typing.NDArray) – indices of the theta parameters for all the terms in the trace

  • begin_list (numpy.typing.NDArray) – array containing the first index to take into account in the trace for the variational parameters

  • end_list (numpy.typing.NDArray) – array containing the last index to take into account in the trace for the variational parameters

  • all_the_coefficients (numpy.typing.NDArray) – coefficient of the NormTerms which need to be taken into account in the trace

Returns:

the perturbative norm

Return type:

float

class peropq.bch_optimized.NormTerm

Class representing a term to be taken into account in the norm.

Parameters:
  • pauli_string – of the term

  • order – at which the term is relevant

  • coefficient – in front of the Pauli string

  • theta_indices – represents the indices of the variational parameter to be multiplied in front

pauli_string: peropq.pauli_bitstring.PauliString
order: int
coefficient: complex
theta_indices: list[tuple[int, int]]
peropq.bch_optimized._is_pauli_string(to_test)
Parameters:

to_test (peropq.pauli_bitstring.PauliString | Literal[0])

Return type:

TypeGuard[peropq.pauli_bitstring.PauliString]

peropq.bch_optimized._is_norm_term(to_test)
Parameters:

to_test (NormTerm | Literal[0])

Return type:

TypeGuard[NormTerm]

peropq.bch_optimized.commutator(aterm, other)

Take the commutator between two NormTerm instances.

Parameters:
Return type:

NormTerm | Literal[0]

class peropq.bch_optimized.VariationalNorm(variational_unitary, order, *, unconstrained=False)

Class representing the perturbative norm with some variational parameters. It is used in the optimization process.

Parameters:
variational_unitary
order
terms: dict[int, list[NormTerm]]
unconstrained
calculated_trace = False
compute_commutator_sum(term_list1, term_list2)

Compute the commutator of two sums of Pauli strings: [term_list1[0]+term_list1[1]+term_list1[2]+…,term_list2[0]+term_list2[1]+term_list2[2]+…].

Returns:

a list of instances of NormTerm corresponding to the commutator.

Parameters:
Return type:

list[NormTerm]

add_term(new_term)

Take into account a new term in the variational norm. This is currently implemented up to order 4.

Parameters:

new_term (NormTerm)

Return type:

None

get_commutators()

Get the commutators required to calculate the perturbative variational norm.

Return type:

None

get_traces()

Calculate all the traces of commutator needed for the perturbative variational norm.

Return type:

None

calculate_norm(theta)

Calculate the norm for a given variational parameter theta.

Parameters:

theta (numpy.typing.NDArray) – variational parameter

Returns:

the norm

Return type:

float