qubiter.adv_applications.MeanHamil_rigetti module

class qubiter.adv_applications.MeanHamil_rigetti.MeanHamil_rigetti(qc, file_prefix, num_bits, hamil, all_var_nums, fun_name_to_fun, do_resets=True, **kwargs)[source]

Bases: qubiter.adv_applications.MeanHamil.MeanHamil

This class is a child of MeanHamil.

This class uses either Rigetti’s real hardware or virtual simulator to calculate mean values. qc returned by Rigetti’s get_qc() method is passed in as an input to the constructor of this class. If num_samples !=0, the class uses qc.run() to calculate mean values. If num_samples=0, the class ignores the qc input and uses PyQuil’s WavefunctionSimulator to calculate mean values exactly.

Variables:
  • do_resets (bool) –
  • pg (Program) – object of PyQuil class Program
  • qc (QuantumComputer) – returned by PyQuil method get_qc()
  • term_to_exec (dict[]) – maps a term to an executable. QubitOperator from OpenFermion has attribute terms which is a dict from a term to a coefficient. An executable is the output of PyQuil’s compile() method.
  • translation_line_list (list[str]) – a list of lines of PyQuil code generated by the translator. The lines all start with “pg +=”
  • translator (Qubiter_to_RigettiPyQuil) –
__init__(qc, file_prefix, num_bits, hamil, all_var_nums, fun_name_to_fun, do_resets=True, **kwargs)[source]

Constructor

Do in constructor as much hamil indep stuff as possible so don’t have to redo it with every call to cost fun. Also, when self.num_samples !=0, we store a dict called term_to_exec mapping an executable (output of Rigetti compile() function) to a term, for each term in the hamiltonian hamil. When num_samples=0, term_to_exec={}

Parameters:
  • qc (QuantumComputer) –
  • file_prefix (str) –
  • num_bits (int) –
  • hamil (QubitOperator) –
  • all_var_nums (list[int]) –
  • fun_name_to_fun (dict[str, function]) –
  • do_resets (bool) –
  • kwargs (dict) – key-words args of MeanHamilMinimizer constructor
get_mean_val(var_num_to_rads)[source]

This method returns the empirically determined Hamiltonian mean value. It takes as input the values of placeholder variables. It passes those values into the Rigetti method run() when num_samples !=0. When num_samples=0, WavefunctionSimulator is used to calculate the output mean value exactly.

Parameters:var_num_to_rads (dict[int, float]) –
Returns:
Return type:float