openfermioncirq.VariationalStudy¶
-
class
openfermioncirq.
VariationalStudy
(name: str, ansatz: openfermioncirq.variational.ansatz.VariationalAnsatz, objective: openfermioncirq.variational.objective.VariationalObjective, preparation_circuit: Optional[cirq.circuits.circuit.Circuit] = None, initial_state: Union[int, numpy.ndarray] = 0, target: Optional[float] = None, black_box_type: Type[openfermioncirq.variational.variational_black_box.VariationalBlackBox] = <class 'openfermioncirq.variational.variational_black_box.UnitarySimulateVariationalBlackBox'>, datadir: Optional[str] = None)[source]¶ The results from optimizing a variational ansatz.
A VariationalStudy is used to facilitate optimizing the parameters of a variational ansatz. It contains methods for performing optimizations and saving and loading the results.
- Example::
ansatz = SomeVariationalAnsatz() objective = SomeVariationalObjective() study = SomeVariationalStudy(‘my_study’, ansatz, objective) optimization_params = OptimizationParams(
algorithm=openfermioncirq.optimization.COBYLA, initial_guess=numpy.zeros(5))result = study.optimize(optimization_params, identifier=’run0’) print(result.optimal_value) # prints a number print(result.params.initial_guess) # prints the initial guess used study.save() # saves the study with all results obtained so far
-
name
¶ The name of the study.
-
circuit
¶ The circuit of the study, which is the preparation circuit, if any, followed by the ansatz circuit.
-
ansatz
¶ The ansatz being studied.
-
objective
¶ The objective function of interest.
-
target
¶ An optional target value one wants to achieve during optimization.
-
trial_results
¶ A dictionary of OptimizationTrialResults from optimization runs of the study. Key is the identifier used to label the run.
-
num_params
¶ The number of parameters in the circuit.
-
__init__
(name: str, ansatz: openfermioncirq.variational.ansatz.VariationalAnsatz, objective: openfermioncirq.variational.objective.VariationalObjective, preparation_circuit: Optional[cirq.circuits.circuit.Circuit] = None, initial_state: Union[int, numpy.ndarray] = 0, target: Optional[float] = None, black_box_type: Type[openfermioncirq.variational.variational_black_box.VariationalBlackBox] = <class 'openfermioncirq.variational.variational_black_box.UnitarySimulateVariationalBlackBox'>, datadir: Optional[str] = None) → None[source]¶ Parameters: - name – The name of the study.
- ansatz – The ansatz to study.
- objective – The objective function.
- preparation_circuit – A circuit to apply prior to the ansatz circuit. It should use the qubits belonging to the ansatz.
- initial_state – An initial state to use if the study circuit is run on a simulator.
- target – The target value one wants to achieve during optimization.
- black_box_type – The type of VariationalBlackBox to use for optimization.
- datadir – The directory to use when saving the study. The default behavior is to use the current working directory.
Methods
__init__
(name, ansatz, objective, …)param name: The name of the study. extend_result
(identifier, …)Extend a result by repeating the run with the same parameters. load
(name, datadir)Load a study from disk. optimize
(optimization_params, identifier, …)Perform an optimization run and save the results. optimize_sweep
(param_sweep, identifiers, …)Perform multiple optimization runs and save the results. save
()Save the study to disk. value_of
(params)Determine the value of some parameters. Attributes
ansatz
The ansatz associated with the study. circuit
The preparation circuit followed by the ansatz circuit. num_params
The number of parameters of the ansatz. objective
The objective associated with the study.