Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.
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.

TPBGroupedWeightedPauliOperator

class TPBGroupedWeightedPauliOperator(paulis, basis, z2_symmetries=None, atol=1e-12, name=None, grouping_func=None, kwargs=None)

GitHub

TPB Grouped Weighted Pauli Operator

Parameters

  • paulis (list[[complex, Pauli]]) – the list of weighted Paulis, where a weighted pauli is composed of a length-2 list and the first item is the weight and the second item is the Pauli object.
  • basis (list[tuple(object, [int])], optional) – the grouping basis, each element is a tuple composed of the basis and the indices to paulis which are belonged to that group. e.g., if tpb basis is used, the object will be a pauli. By default, the group is equal to non-grouping, each pauli is its own basis.
  • z2_symmetries (Z2Symmetries) – recording the z2 symmetries info
  • atol (float, optional) – the threshold used in truncating paulis
  • name (str, optional) – the name of operator.
  • grouping_func (Callable, optional) – Function to group paulis
  • kwargs (dict) – Optional parameters for grouping function call

Attributes

atol

get atol

basis

returns basis

grouping_func

returns grouping function

kwargs

returns kwargs

name

returns name

num_groups

returns number of groups

num_qubits

Number of qubits required for the operator.

Returns

number of qubits

Return type

int

paulis

get paulis

z2_symmetries

returns z2 symmetries


Methods

__mul__

TPBGroupedWeightedPauliOperator.__mul__(other)

Overload self * other

add

TPBGroupedWeightedPauliOperator.add(other, copy=False)

Perform self + other.

Parameters

  • other (WeightedPauliOperator) – to-be-combined operator
  • copy (bool) – working on a copy or self, if False, the results are written back to self.

Returns

operator

Return type

WeightedPauliOperator

anticommute_with

TPBGroupedWeightedPauliOperator.anticommute_with(other)

Anti commutes with

chop

TPBGroupedWeightedPauliOperator.chop(threshold=None, copy=False)

Eliminate the real and imagine part of weight in each pauli by threshold. If pauli’s weight is less then threshold in both real and imaginary parts, the pauli is removed.

Note

If weight is real-only, the imaginary part is skipped.

Parameters

  • threshold (float) – the threshold is used to remove the paulis
  • copy (bool) – chop on a copy or self

Returns

if copy is True, the original operator is unchanged; otherwise,

the operator is mutated.

Return type

WeightedPauliOperator

commute_with

TPBGroupedWeightedPauliOperator.commute_with(other)

Commutes with

construct_evaluation_circuit

TPBGroupedWeightedPauliOperator.construct_evaluation_circuit(wave_function, statevector_mode, qr=None, cr=None, use_simulator_snapshot_mode=False, circuit_name_prefix='')

Construct the circuits for evaluation, which calculating the expectation <psi|H|psi>.

At statevector mode: to simplify the computation, we do not build the whole circuit for <psi|H|psi>, instead of that we construct an individual circuit <psi|, and a bundle circuit for H|psi>

Parameters

  • wave_function (QuantumCircuit) – the quantum circuit.
  • statevector_mode (bool) – indicate which type of simulator are going to use.
  • qr (QuantumRegister, optional) – the quantum register associated with the input_circuit
  • cr (ClassicalRegister, optional) – the classical register associated with the input_circuit
  • use_simulator_snapshot_mode (bool, optional) – if aer_provider is used, we can do faster evaluation for pauli mode on statevector simulation
  • circuit_name_prefix (str, optional) – a prefix of circuit name

Returns

a list of quantum circuits and each circuit with a unique name:

circuit_name_prefix + Pauli string

Return type

list[QuantumCircuit]

Raises

  • AquaError – if Operator is empty
  • AquaError – if quantum register is not provided explicitly and cannot find quantum register with q as the name
  • AquaError – The provided qr is not in the wave_function

copy

TPBGroupedWeightedPauliOperator.copy()

Get a copy of self

evaluate_with_result

TPBGroupedWeightedPauliOperator.evaluate_with_result(result, statevector_mode, use_simulator_snapshot_mode=False, circuit_name_prefix='')

This method can be only used with the circuits generated by the construct_evaluation_circuit() method with the same circuit_name_prefix name since the circuit names are tied to some meanings.

Calculate the evaluated value with the measurement results.

Parameters

  • result (qiskit.Result) – the result from the backend.
  • statevector_mode (bool) – indicate which type of simulator are used.
  • use_simulator_snapshot_mode (bool) – if aer_provider is used, we can do faster evaluation for pauli mode on statevector simulation
  • circuit_name_prefix (str) – a prefix of circuit name

Returns

the mean value float: the standard deviation

Return type

float

Raises

AquaError – if Operator is empty

evaluate_with_statevector

TPBGroupedWeightedPauliOperator.evaluate_with_statevector(quantum_state)

Parameters

quantum_state (numpy.ndarray) – a quantum state.

Returns

the mean value float: the standard deviation

Return type

float

Raises

AquaError – if Operator is empty

evaluation_instruction

TPBGroupedWeightedPauliOperator.evaluation_instruction(statevector_mode, use_simulator_snapshot_mode=False)

Parameters

  • statevector_mode (bool) – will it be run on statevector simulator or not
  • use_simulator_snapshot_mode (bool) – will it use qiskit aer simulator operator mode

Returns

Pauli-instruction pair.

Return type

dict

Raises

AquaError – if Operator is empty

evolve

TPBGroupedWeightedPauliOperator.evolve(state_in=None, evo_time=0, num_time_slices=1, quantum_registers=None, expansion_mode='trotter', expansion_order=1)

Carry out the eoh evolution for the operator under supplied specifications.

Parameters

Returns

The constructed circuit.

Return type

QuantumCircuit

Raises

  • AquaError – quantum_registers must be in the provided state_in circuit
  • AquaError – if operator is empty

evolve_instruction

TPBGroupedWeightedPauliOperator.evolve_instruction(evo_time=0, num_time_slices=1, expansion_mode='trotter', expansion_order=1)

Carry out the eoh evolution for the operator under supplied specifications.

Parameters

Returns

The constructed QuantumCircuit.

Return type

QuantumCircuit

Raises

  • ValueError – Number of time slices should be a non-negative integer
  • NotImplementedError – expansion mode not supported
  • AquaError – if operator is empty

from_dict

classmethod TPBGroupedWeightedPauliOperator.from_dict(dictionary, before_04=False)

Load paulis from a dictionary to construct an Operator. The dictionary must comprise the key ‘paulis’ having a value which is an array of pauli dicts. Each dict in this array must be represented by label and coeff (real and imag) such as in the following example:

{'paulis':
    [
        {'label': 'IIII',
         'coeff': {'real': -0.33562957575267038, 'imag': 0.0}},
        {'label': 'ZIII',
         'coeff': {'real': 0.28220597164664896, 'imag': 0.0}},
         ...
    ]
 }

Parameters

  • dictionary (dict) – dictionary, which contains a list of Paulis and coefficients.
  • before_04 (bool) – support the format before Aqua 0.4.

Returns

the operator created from the input dictionary.

Return type

WeightedPauliOperator

Raises

AquaError – Invalid dictionary

from_file

classmethod TPBGroupedWeightedPauliOperator.from_file(file_name, before_04=False)

Load paulis in a file to construct an Operator.

Parameters

  • file_name (str) – path to the file, which contains a list of Paulis and coefficients.
  • before_04 (bool) – support the format before Aqua 0.4.

Returns

the loaded operator.

Return type

WeightedPauliOperator

from_list

classmethod TPBGroupedWeightedPauliOperator.from_list(paulis, weights=None, name=None)

Create a WeightedPauliOperator via a pair of list.

Parameters

  • paulis (list[Pauli]) – the list of Paulis
  • weights (list[complex], optional) – the list of weights, if it is None, all weights are 1.
  • name (str, optional) – name of the operator.

Returns

operator

Return type

WeightedPauliOperator

Raises

ValueError – The length of weights and paulis must be the same

is_empty

TPBGroupedWeightedPauliOperator.is_empty()

Check Operator is empty or not.

Returns

True if empty, False otherwise

Return type

bool

multiply

TPBGroupedWeightedPauliOperator.multiply(other)

Perform self * other.

Note: Grouping of the new operator, will be as per self’s grouping.

Parameters

other (TPBGroupedWeightedPauliOperator) – an operator

Returns

the multiplied operator

Return type

TPBGroupedWeightedPauliOperator

TPBGroupedWeightedPauliOperator.print_details()

Print out the operator in details.

Returns

a formatted string describes the operator.

Return type

str

reorder_paulis

TPBGroupedWeightedPauliOperator.reorder_paulis()

Reorder the paulis based on the basis and return the reordered paulis.

Returns

the ordered paulis based on the basis.

Return type

list[list[complex, paulis]]

rounding

TPBGroupedWeightedPauliOperator.rounding(decimals, copy=False)

Rounding the weight.

Parameters

  • decimals (int) – rounding the weight to the decimals.
  • copy (bool) – chop on a copy or self

Returns

operator

Return type

WeightedPauliOperator

simplify

TPBGroupedWeightedPauliOperator.simplify(copy=False)

Merge the paulis whose bases are identical and the pauli with zero coefficient would be removed.

Note

This behavior of this method is slightly changed, it will remove the paulis whose weights are zero.

Parameters

copy (bool) – simplify on a copy or self

Returns

the simplified operator

Return type

WeightedPauliOperator

sorted_grouping

classmethod TPBGroupedWeightedPauliOperator.sorted_grouping(weighted_pauli_operator, method='largest-degree')

Largest-Degree First Coloring for grouping paulis.

Parameters

  • weighted_pauli_operator (WeightedPauliOperator) – the to-be-grouped weighted pauli operator.
  • method (str) – only largest-degree is available now.

Returns

operator

Return type

TPBGroupedWeightedPauliOperator

sub

TPBGroupedWeightedPauliOperator.sub(other, copy=False)

Perform self - other.

Parameters

  • other (WeightedPauliOperator) – to-be-combined operator
  • copy (bool) – working on a copy or self, if False, the results are written back to self.

Returns

operator

Return type

WeightedPauliOperator

to_dict

TPBGroupedWeightedPauliOperator.to_dict()

Save operator to a dict in pauli representation.

Returns

a dictionary contains an operator with pauli representation.

Return type

dict

to_file

TPBGroupedWeightedPauliOperator.to_file(file_name)

Save operator to a file in pauli representation.

Parameters

file_name (str) – path to the file

to_opflow

TPBGroupedWeightedPauliOperator.to_opflow(reverse_endianness=False)

to op flow

unsorted_grouping

classmethod TPBGroupedWeightedPauliOperator.unsorted_grouping(weighted_pauli_operator)

Greedy and unsorted grouping paulis.

Parameters

weighted_pauli_operator (WeightedPauliOperator) – the to-be-grouped weighted pauli operator.

Returns

operator

Return type

TPBGroupedWeightedPauliOperator

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