qiskit.aqua.operators.legacy.WeightedPauliOperator¶

class
WeightedPauliOperator
(paulis, basis=None, z2_symmetries=None, atol=1e12, name=None)[소스]¶ Weighted Pauli Operator
 매개변수
paulis (
List
[List
[Union
[complex
,Pauli
]]]) – the list of weighted Paulis, where a weighted pauli is composed of a length2 list and the first item is the weight and the second item is the Pauli object.basis (
Optional
[List
[Tuple
[object
,List
[int
]]]]) – the grouping basis, each element is a tuple composed of the basis and the indices to paulis which belong to that group. e.g., if tpb basis is used, the object will be a pauli. By default, the group is equal to nongrouping, each pauli is its own basis.z2_symmetries (
Optional
[Z2Symmetries
]) – recording the z2 symmetries infoatol (
float
) – the threshold used in truncating paulisname (
Optional
[str
]) – the name of operator.

__init__
(paulis, basis=None, z2_symmetries=None, atol=1e12, name=None)[소스]¶  매개변수
paulis (
List
[List
[Union
[complex
,Pauli
]]]) – the list of weighted Paulis, where a weighted pauli is composed of a length2 list and the first item is the weight and the second item is the Pauli object.basis (
Optional
[List
[Tuple
[object
,List
[int
]]]]) – the grouping basis, each element is a tuple composed of the basis and the indices to paulis which belong to that group. e.g., if tpb basis is used, the object will be a pauli. By default, the group is equal to nongrouping, each pauli is its own basis.z2_symmetries (
Optional
[Z2Symmetries
]) – recording the z2 symmetries infoatol (
float
) – the threshold used in truncating paulisname (
Optional
[str
]) – the name of operator.
Methods
__init__
(paulis[, basis, z2_symmetries, …]) type paulis
List
[List
[Union
[complex
,Pauli
]]]
add
(other[, copy])Perform self + other.
anticommute_with
(other)Anti commutes with
chop
([threshold, copy])Eliminate the real and imagine part of weight in each pauli by threshold.
commute_with
(other)Commutes with
construct_evaluation_circuit
(wave_function, …)Construct the circuits for evaluation, which calculating the expectation <psiHpsi>.
copy
()Get a copy of self
evaluate_with_result
(result, statevector_mode)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.evaluate_with_statevector
(quantum_state) param quantum_state
a quantum state.
evaluation_instruction
(statevector_mode[, …]) param statevector_mode
will it be run on statevector simulator or not
evolve
([state_in, evo_time, …])Carry out the eoh evolution for the operator under supplied specifications.
evolve_instruction
([evo_time, …])Carry out the eoh evolution for the operator under supplied specifications.
from_dict
(dictionary[, before_04])Load paulis from a dictionary to construct an Operator.
from_file
(file_name[, before_04])Load paulis in a file to construct an Operator.
from_list
(paulis[, weights, name])Create a WeightedPauliOperator via a pair of list.
is_empty
()Check Operator is empty or not.
multiply
(other)Perform self * other, and the phases are tracked.
Print out the operator in details.
Reorder the paulis based on the basis and return the reordered paulis.
rounding
(decimals[, copy])Rounding the weight.
simplify
([copy])Merge the paulis whose bases are identical and the pauli with zero coefficient would be removed.
sub
(other[, copy])Perform self  other.
to_dict
()Save operator to a dict in pauli representation.
to_file
(file_name)Save operator to a file in pauli representation.
to_opflow
([reverse_endianness])to op flow
Attributes
get atol
returns basis
returns name
Number of qubits required for the operator.
get paulis
returns z2 symmetries

add
(other, copy=False)[소스]¶ Perform self + other.
 매개변수
other (WeightedPauliOperator) – tobecombined operator
copy (bool) – working on a copy or self, if False, the results are written back to self.
 반환값
operator
 반환 형식

property
atol
¶ get atol

property
basis
¶ returns basis

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.
참고
If weight is realonly, the imaginary part is skipped.
 매개변수
threshold (float) – the threshold is used to remove the paulis
copy (bool) – chop on a copy or self
 반환값
 if copy is True, the original operator is unchanged; otherwise,
the operator is mutated.
 반환 형식

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 <psiHpsi>.
At statevector mode: to simplify the computation, we do not build the whole circuit for <psiHpsi>, instead of that we construct an individual circuit <psi, and a bundle circuit for Hpsi>
 매개변수
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
 반환값
 a list of quantum circuits and each circuit with a unique name:
circuit_name_prefix + Pauli string
 반환 형식
list[QuantumCircuit]
 예외

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.
 매개변수
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
 반환값
the mean value float: the standard deviation
 반환 형식
float
 예외
AquaError – if Operator is empty

evaluate_with_statevector
(quantum_state)[소스]¶  매개변수
quantum_state (numpy.ndarray) – a quantum state.
 반환값
the mean value float: the standard deviation
 반환 형식
float
 예외
AquaError – if Operator is empty

evaluation_instruction
(statevector_mode, use_simulator_snapshot_mode=False)[소스]¶  매개변수
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
 반환값
Pauliinstruction pair.
 반환 형식
dict
 예외
AquaError – if Operator is empty
MissingOptionalLibraryError – qiskitaer not installed

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.
 매개변수
state_in (QuantumCircuit) – a circuit describes the input state
evo_time (Union(complex, float, Parameter, ParameterExpression)) – The evolution time
num_time_slices (int) – The number of time slices for the expansion
quantum_registers (QuantumRegister) – The QuantumRegister to build the QuantumCircuit off of
expansion_mode (str) – The mode under which the expansion is to be done. Currently support ‘trotter’, which follows the expansion as discussed in http://science.sciencemag.org/content/273/5278/1073, and ‘suzuki’, which corresponds to the discussion in https://arxiv.org/pdf/quantph/0508139.pdf
expansion_order (int) – The order for suzuki expansion
 반환값
The constructed circuit.
 반환 형식
 예외

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.
 매개변수
evo_time (Union(complex, float, Parameter, ParameterExpression)) – The evolution time
num_time_slices (int) – The number of time slices for the expansion
expansion_mode (str) – The mode under which the expansion is to be done. Currently support ‘trotter’, which follows the expansion as discussed in http://science.sciencemag.org/content/273/5278/1073, and ‘suzuki’, which corresponds to the discussion in https://arxiv.org/pdf/quantph/0508139.pdf
expansion_order (int) – The order for suzuki expansion
 반환값
The constructed QuantumCircuit.
 반환 형식
 예외
ValueError – Number of time slices should be a nonnegative integer
NotImplementedError – expansion mode not supported
AquaError – if operator is empty

classmethod
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}}, ... ] }
 매개변수
dictionary (dict) – dictionary, which contains a list of Paulis and coefficients.
before_04 (bool) – support the format before Aqua 0.4.
 반환값
the operator created from the input dictionary.
 반환 형식
 예외
AquaError – Invalid dictionary

classmethod
from_file
(file_name, before_04=False)[소스]¶ Load paulis in a file to construct an Operator.
 매개변수
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.
 반환값
the loaded operator.
 반환 형식

classmethod
from_list
(paulis, weights=None, name=None)[소스]¶ Create a WeightedPauliOperator via a pair of list.
 매개변수
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.
 반환값
operator
 반환 형식
 예외
ValueError – The length of weights and paulis must be the same

multiply
(other)[소스]¶ Perform self * other, and the phases are tracked.
 매개변수
other (WeightedPauliOperator) – an operator
 반환값
the multiplied operator
 반환 형식

property
name
¶ returns name

property
num_qubits
¶ Number of qubits required for the operator.
 반환값
number of qubits
 반환 형식
int

property
paulis
¶ get paulis

print_details
()[소스]¶ Print out the operator in details.
 반환값
a formatted string describes the operator.
 반환 형식
str

reorder_paulis
()[소스]¶ Reorder the paulis based on the basis and return the reordered paulis.
 반환 형식
List
[List
[Union
[complex
,Pauli
]]] 반환값
the ordered paulis based on the basis.

rounding
(decimals, copy=False)[소스]¶ Rounding the weight.
 매개변수
decimals (int) – rounding the weight to the decimals.
copy (bool) – chop on a copy or self
 반환값
operator
 반환 형식

simplify
(copy=False)[소스]¶ Merge the paulis whose bases are identical and the pauli with zero coefficient would be removed.
참고
This behavior of this method is slightly changed, it will remove the paulis whose weights are zero.
 매개변수
copy (bool) – simplify on a copy or self
 반환값
the simplified operator
 반환 형식

sub
(other, copy=False)[소스]¶ Perform self  other.
 매개변수
other (WeightedPauliOperator) – tobecombined operator
copy (bool) – working on a copy or self, if False, the results are written back to self.
 반환값
operator
 반환 형식

to_dict
()[소스]¶ Save operator to a dict in pauli representation.
 반환값
a dictionary contains an operator with pauli representation.
 반환 형식
dict

to_file
(file_name)[소스]¶ Save operator to a file in pauli representation.
 매개변수
file_name (str) – path to the file

property
z2_symmetries
¶ returns z2 symmetries