qiskit.aqua.operators.legacy.MatrixOperator
class MatrixOperator(matrix, basis=None, z2_symmetries=None, atol=1e-12, name=None)
Operators relevant for quantum applications
For grouped paulis representation, all operations will always convert it to paulis and then convert it back. (It might be a performance issue.)
Parameters
- matrix (numpy.ndarray or scipy.sparse.csr_matrix) – a 2-D sparse matrix represents operator (using CSR format internally)
- 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) – represent the Z2 symmetries
- atol (float) – atol
- name (str) – name
__init__
__init__(matrix, basis=None, z2_symmetries=None, atol=1e-12, name=None)
Parameters
- matrix (numpy.ndarray or scipy.sparse.csr_matrix) – a 2-D sparse matrix represents operator (using CSR format internally)
- 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) – represent the Z2 symmetries
- atol (float) – atol
- name (str) – name
Methods
__init__ (matrix[, basis, z2_symmetries, …]) | param matrixa 2-D sparse matrix represents operator (using CSR format internally) |
add (other[, copy]) | |
chop ([threshold, copy]) | Eliminate the real and imagine part of coeff in each pauli by threshold. |
construct_evaluation_circuit (wave_function) | Construct the circuits for evaluation. |
copy () | Get a copy of self. |
evaluate_with_result (result[, …]) | Use the executed result with operator to get the evaluated value. |
evaluate_with_statevector (quantum_state) | param quantum_statequantum state |
evolve (state_in[, evo_time, …]) | Carry out the eoh evolution for the operator under supplied specifications. |
is_empty () | Check Operator is empty or not. |
print_details () | returnsa formatted operator. |
sub (other[, copy]) | |
to_opflow () | to op flow |
Attributes
atol | return atol |
basis | returns basis |
dense_matrix | Getter of matrix in dense matrix form. |
dia_matrix | diagonal matrix |
matrix | Getter of matrix. |
name | returns name |
num_qubits | number of qubits required for the operator. |
z2_symmetries | returns z2 symmetries |
add
add(other, copy=False)
atol
return atol
basis
returns basis
chop
chop(threshold=None, copy=False)
Eliminate the real and imagine part of coeff in each pauli by threshold. If pauli’s coeff is less then threshold in both real and imagine parts, the pauli is removed. To align the internal representations, all available representations are chopped. The chopped result is stored back to original property. Note: if coeff is real-only, the imag part is skipped.
Parameters
- threshold (float) – threshold chops the paulis
- copy (bool) – copy or self
Returns
self or copy
Return type
construct_evaluation_circuit
construct_evaluation_circuit(wave_function, statevector_mode=True, use_simulator_snapshot_mode=None, circuit_name_prefix='')
Construct the circuits for evaluation.
Parameters
- wave_function (QuantumCircuit) – the quantum circuit.
- statevector_mode (bool) – mode
- use_simulator_snapshot_mode (bool) – uses simulator operator mode
- circuit_name_prefix (str, optional) – a prefix of circuit name
Returns
the circuits for computing the expectation of the operator over
the wavefunction evaluation.
Return type
list[QuantumCircuit]
copy
copy()
Get a copy of self.
dense_matrix
Getter of matrix in dense matrix form.
dia_matrix
diagonal matrix
evaluate_with_result
evaluate_with_result(result, statevector_mode=True, use_simulator_snapshot_mode=None, circuit_name_prefix='')
Use the executed result with operator to get the evaluated value.
Parameters
- result (qiskit.Result) – the result from the backend
- statevector_mode (bool) – mode
- use_simulator_snapshot_mode (bool) – uses simulator operator mode
- circuit_name_prefix (str, optional) – 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
evaluate_with_statevector(quantum_state)
Parameters
quantum_state (numpy.ndarray) – quantum state
Returns
the mean value float: the standard deviation
Return type
float
Raises
AquaError – if Operator is empty
evolve
evolve(state_in, evo_time=0, num_time_slices=0, expansion_mode='trotter', expansion_order=1)
Carry out the eoh evolution for the operator under supplied specifications.
Parameters
- state_in (Union(list,numpy.array)) – A vector representing the initial state for the evolution
- evo_time (Union(complex, float)) – 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 https://www.science.org/doi/10.1126/science.273.5278.1073, and ‘suzuki’, which corresponds to the discussion in https://arxiv.org/pdf/quant-ph/0508139.pdf
- expansion_order (int) – The order for suzuki expansion
Returns
Return the matrix vector multiplication result.
Return type
numpy.array
Raises
- ValueError – Invalid arguments
- AquaError – if Operator is empty
is_empty
is_empty()
Check Operator is empty or not.
Returns
is empty?
Return type
bool
matrix
Getter of matrix.
name
returns name
num_qubits
number of qubits required for the operator.
Returns
number of qubits
Return type
int
print_details
print_details()
Returns
a formatted operator.
Return type
str
sub
sub(other, copy=False)
to_opflow
to_opflow()
to op flow
z2_symmetries
returns z2 symmetries