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
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.
Returns
number of qubits
Return type
int
z2_symmetries
returns z2 symmetries
Methods
__mul__
MatrixOperator.__mul__(other)
Overload * operation. Only support two Operators have the same representation mode.
Returns
the multiplied Operator.
Return type
Raises
TypeError**, **if two Operators do not have the same representations. –
add
MatrixOperator.add(other, copy=False)
chop
MatrixOperator.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
MatrixOperator.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
MatrixOperator.copy()
Get a copy of self.
evaluate_with_result
MatrixOperator.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
MatrixOperator.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
MatrixOperator.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
MatrixOperator.is_empty()
Check Operator is empty or not.
Returns
is empty?
Return type
bool
print_details
MatrixOperator.print_details()
Returns
a formatted operator.
Return type
str
sub
MatrixOperator.sub(other, copy=False)
to_opflow
MatrixOperator.to_opflow()
to op flow