qubiter.adv_applications.MeanHamil module¶

class
qubiter.adv_applications.MeanHamil.
MeanHamil
(file_prefix, num_bits, hamil, all_var_nums, fun_name_to_fun, init_st_vec=None, simulator_name=None, num_samples=0)[source]¶ Bases:
object
This is an abstract class. The main purpose of this class is to evaluate the mean value of a Hamiltonian.
The Hamiltonian hamil is stored as an object of QubitOperator (a class of the opensource lib OpenFermion). terms is an attribute of QubitOperator. hamil.terms is a dictionary that maps a term to a coefficient. A term represents a tensor product of Pauli matrices (a Pauli string) as a tuple of tuples of the form (bit_pos, action). An example of a term: ( (1, ‘X’), (2, ‘Y’))
file_prefix identifies the location of an English file that specifies a quantum circuit. If init_st_vec=None, we assume that the initial state of that quantum circuit is the ground state (all qubits in state 0>). Let psi> be the final state vector that evolves from that circuit. Let hamil be a Hamiltonian suitable for that circuit and stored as an object of QubitOperator (a class of the opensource lib OpenFermion). Then the mean value evaluated by this class is <psihamilpsi>.
Subclasses of this class use different methods to evaluate this mean value. They might change the tensor lib (numpy, PyTorch, TensorFlow) or the device (native, Rigetti, etc.) or the simulator for a particular device. They might evaluate the mean value exactly or empirically.
Variables:  all_var_nums (list[int]) – This is a list of all the nonfunctional placeholder variable numbers
 file_prefix (str) – Prefix to English file to be used in evaluating the mean hamil
 fun_name_to_fun (dict[str, function]) – This is a dict that maps function names to functions. Such functions are functional placeholders, meaning that their values are only decided at a later time. These functions do not vary during the minimization process.
 hamil (QubitOperator) – Hamiltonian
 init_st_vec (StateVec) – initial state vector
 num_bits (int) – number of qubits
 num_samples (int) – number of samples (aka num_shots). If this is zero, the psi> in <psiHpsi> is calculated exactly from theory. If this is >0, the psi> is calculated empirically from a number num_samples of “oneshot” experiments.
 simulator_name (str  None) – name of the simulator.

__init__
(file_prefix, num_bits, hamil, all_var_nums, fun_name_to_fun, init_st_vec=None, simulator_name=None, num_samples=0)[source]¶ Constructor
Parameters:  file_prefix (str) –
 num_bits (int) –
 hamil (QubitOperator) –
 all_var_nums (list[int]) –
 fun_name_to_fun (dict[str, function]) –
 init_st_vec (StateVec) –
 simulator_name (str) –
 num_samples (int) –

static
check_hamil_is_herm
(hamil)[source]¶ Checks that the Hamiltonian hamil is a Hermitian operator. Emits warning and stops execution if it isn’t.
Parameters: hamil (QubitOperator) – Returns: Return type: None

static
check_hamil_is_in_range
(hamil, max_bit_pos)[source]¶ Checks that the Hamiltonian hamil operates on range(max_bit_pos+1).
Parameters: hamil (QubitOperator) – Returns: Return type: None

get_mean_val
(var_num_to_rads)[source]¶ Abstract method. The main goal of subclasses of this class is to override this method.
Parameters: var_num_to_rads (dict[int, float]) –

get_real_vec
(term)[source]¶ Internal method that returns a numpy array, of shape [2]*num_bits, that will be used as input to the method StateVec.get_mean_value_of_real_diag_mat()
The input is a term. terms is an attribute of QubitOperator (a class in OpenFermion). terms is a dictionary that maps a term to a coefficient. A term represents a tensor product of Pauli matrices (a Pauli string) as a tuple of tuples of the form (bit_pos, action). An example of a term: ((1, ‘X’), (2, ‘Y’))
Parameters: term (tuple) – Returns: shape=[2]*num_bits Return type: np.ndarray