Package: qcalibrateremote
A client library for runnig a control optimization with qruise calibrate softwareNoteThe API is experimental and subject to change without a prior noticeDescriptionThe qcalibrateremote package provides interface to QCalibrate optimization service, providing algorithms helping to define optimal control for quantum system.
The actual optimization algorithm runs on the server, supplying the set of parameters and/or PWC pulses to client side. The client code evaluates the parameters
by deriving and applying control signals to a system under control, performing measurement, calcualates and returns the figure of merit (infidelity) value.
The algorithm tries different parameters in order to find optimal values to achieve minimal infidelity. Live progress of optimization can be observed in the in web UI,
given opportunity to finish the optimization, before the optimization stopping criteria are achieved.Currently two optimization modes are supported.pure parameter optimizationRandom chopped base PWC function optimization (Fourier and Sigmoid bases)InstallingInstall withpip:$pipinstallqcalibrateremotefor conda environment install grcpio explicitly$condainstallgrpcioUsagePrerequisitsPython 3.8+ (developed and tested with 3.8.5)Qruise Calibrate account (contactr.razilov@fz-juelich.defor details)Direct internet connection to server (may require VPN access)ExperimentExperiment defines is a set of meta-parameters controlling the optimization
Use use API or Web UI to create an experiment and define optimization parameters. Use online help to get learn about details.
The evaluation of figure of merit class can be supplied as classevaluate_fom_class=..or objectevaluate_fom_object=..Pure parameter optimization example# import dependenciesfromtypingimportDictfromqcalibrateremoteimport(EvaluateFigureOfMerit,FigureOfMerit,create_optimizer_client,)# setup client connection (copy form web UI: https://www.qcalibrate.staging.optimal-control.net:31603)experiment_id="0xabcd"token=("ey...")optimizer_client=create_optimizer_client(host="grpc.qcalibrate.staging.optimal-control.net",port=31603,token=token)# define infidelity evaluation classclassDistanceFom(EvaluateFigureOfMerit):def__init__(self,*args,**kwargs)->None:super().__init__()definfidelity(self,param1,param2)->float:return(param1-0.55)**2+(param2-0.33)**2defevaluate(self,parameters:Dict[str,float],**kwargs)->FigureOfMerit:"""Abstract method for figure of merit evaluation"""# print(parameters)returnFigureOfMerit(self.infidelity(**parameters),'')# run optimizationoptimization_result=optimizer_client.run(experiment_id=experiment_id,evaluate_fom_class=DistanceFom)# best fitting parametersoptimization_result.top[0].parametersRather than create a completely new configuration, one can update an existing experiment configurationwithoptimizer_client.update_experiment(experiment_id)asexperiment_builder:withexperiment_builder.configuration()asconfiguration:withconfiguration.parameter("param1")asparam1:param1.initial_value=0.7optimization_result=optimizer_client.run(experiment_id=experiment_id,evaluate_fom_class=DistanceFom)# best fitting parametersoptimization_result.top[0].parametersPulse optimization example# import dependenciesfromtypingimportDictfromqcalibrateremoteimport(EvaluateFigureOfMerit,FigureOfMerit,create_optimizer_client,Pulse,)# setup client connection (copy form web UI: https://www.qcalibrate.staging.optimal-control.net:31603)token=("ey...")optimizer_client=create_optimizer_client(host="grpc.qcalibrate.staging.optimal-control.net",port=31603,token=token)experiment_builder=optimizer_client.create_pulse_optimization_experiment("Pulse optimization","Created by "+__file__)# define configurationwithexperiment_builder.configuration()asconfiguration:withconfiguration.time("time1")astime1:time1.initial_value=1time1.optimize=Falsewithconfiguration.pulse("pulse1")aspulse1:pulse1.time_name="time1"pulse1.lower_limit=-1pulse1.upper_limit=1pulse1.bins_number=21withpulse1.fourier_basis()asfourier_basis:fourier_basis.basis_vector_number=5withfourier_basis.uniform_super_parameter_distribution()asuniform_super_parameter_distribution:uniform_super_parameter_distribution.lower_limit=0.01uniform_super_parameter_distribution.upper_limit=5withpulse1.initial_guess()asinitial_guess:initial_guess.function="lambda t: 1"withpulse1.scaling_function()asscaling_function:scaling_function.function="lambda t: np.exp(-(t - 0.5)**2/(2*0.2**2))"withconfiguration.dcrab_settings()asdcrab_settings:dcrab_settings.maximum_iterations_per_super_iteration=50dcrab_settings.super_iteration_number=6experiment_id=optimizer_client.add_experiment(experiment_builder)# define infidelity evaluation classdefexpected_pulse(t):returnnp.sin(2*np.pi*t)**4classSineFom(EvaluateFigureOfMerit):defevaluate(self,parameters:Dict[str,float],pulses:Dict[str,Pulse],**kwargs)->FigureOfMerit:pulse1=pulses["pulse1"]inf=np.sum((expected_pulse(pulse1.times)-pulse1.values)**2)returnFigureOfMerit(inf,'{}')# run optimizationoptimization_result=optimizer_client.run(experiment_id=experiment_id,evaluate_fom_object=SineFom())# plot best fitting pulsepulse1=optimization_result.top[0].pulses["pulse1"]importmatplotlib.pyplotaspltplt.plot(pulse1.times,expected_pulse(pulse1.times))plt.plot(pulse1.times,pulse1.values)