def test_tasks() -> None: """Task creation is tested separately in the absence of Von Neumann eqn""" model = Model() model.read_config("test/test_model_spam.cfg") pmap = ParameterMap(model=model, generator=gen) pmap.read_config("test/instructions.cfg") assert list(model.tasks.keys()) == ["init_ground", "conf_matrix", "meas_rescale"]
def from_dict(self, cfg: Dict) -> None: """ Load experiment from dictionary """ model = Model() model.fromdict(cfg["model"]) generator = Generator() generator.fromdict(cfg["generator"]) pmap = ParameterMap(model=model, generator=generator) pmap.fromdict(cfg["instructions"]) if "options" in cfg: for k, v in cfg["options"].items(): self.__dict__[k] = v self.pmap = pmap
zero_ones[0] = 0 val1 = one_zeros * m00_q1 + zero_ones * m01_q1 val2 = one_zeros * m00_q2 + zero_ones * m01_q2 min = one_zeros * 0.8 + zero_ones * 0.0 max = one_zeros * 1.0 + zero_ones * 0.2 confusion_row1 = Quantity(value=val1, min_val=min, max_val=max, unit="") confusion_row2 = Quantity(value=val2, min_val=min, max_val=max, unit="") conf_matrix = ConfusionMatrix(Q1=confusion_row1, Q2=confusion_row2) init_temp = 50e-3 init_ground = InitialiseGround(init_temp=Quantity( value=init_temp, min_val=-0.001, max_val=0.22, unit="K")) model = Model( [S], # Individual, self-contained components [drive], # Interactions between components [conf_matrix, init_ground], # SPAM processing ) model.set_dressed(False) hdrift, hks = model.get_Hamiltonians() @pytest.mark.unit def test_SNAIL_eigenfrequencies_1() -> None: "Eigenfrequency of SNAIL" assert (hdrift[1, 1] - hdrift[0, 0] == freq_S * 2 * np.pi ) # for the 0.2dev version, comment out the 2 pi
def test_name_collision() -> None: broken_model = Model() with pytest.raises(KeyError): broken_model.read_config("test/test_model_breaking.cfg")
import numpy as np import pytest from c3.c3objs import Quantity from c3.libraries.envelopes import envelopes from c3.signal.gates import Instruction from c3.signal.pulse import Envelope, Carrier from c3.model import Model from c3.generator.generator import Generator from c3.parametermap import ParameterMap from c3.experiment import Experiment as Exp model = Model() model.read_config("test/test_model.cfg") gen = Generator() gen.read_config("test/generator.cfg") pmap = ParameterMap(model=model, generator=gen) pmap.read_config("test/instructions.cfg") @pytest.mark.unit def test_name_collision() -> None: broken_model = Model() with pytest.raises(KeyError): broken_model.read_config("test/test_model_breaking.cfg") @pytest.mark.unit def test_subsystems() -> None: assert list(model.subsystems.keys()) == ["Q1", "Q2", "Q3", "Q4", "Q5", "Q6"]
# t2star=Qty(value=t2star_tc, min_val=1e-6, max_val=90e-6, unit="s"), # temp=Qty(value=init_temp, min_val=0.0, max_val=0.12, unit="K"), ) q1q2 = Coupling( name="Q1-Q2", connected=["Qubit1", "Qubit2"], strength=Qty(value=coupling_strength, min_val=0 * 1e4, max_val=200e6, unit="Hz 2pi"), hamiltonian_func=hamiltonians.int_XX, ) model = Model(subsystems=[q1, q2], couplings=[q1q2], max_excitations=cut_excitations) model.set_lindbladian(False) model.set_dressed(True) model.set_FR(True) # ### MAKE GENERATOR lo = devices.LO(name="lo", resolution=sim_res) awg = devices.AWG(name="awg", resolution=awg_res) dig_to_an = devices.DigitalToAnalog(name="dac", resolution=sim_res) resp = devices.ResponseFFT( name="resp", rise_time=Qty(value=0.3e-9, min_val=0.05e-9, max_val=0.6e-9, unit="s"), resolution=sim_res, ) mixer = devices.Mixer(name="mixer")
def run_cfg(cfg, opt_config_filename, debug=False): """Execute an optimization problem described in the cfg file. Parameters ---------- cfg : Dict[str, Union[str, int, float]] Configuration file containing optimization options and information needed to completely setup the system and optimization problem. debug : bool, optional Skip running the actual optimization, by default False """ optim_type = cfg.pop("optim_type") optim_lib = { "C1": OptimalControl, "C2": Calibration, "C3": ModelLearning, "C3_confirm": ModelLearning, "confirm": ModelLearning, "SET": Sensitivity, } if not optim_type in optim_lib: raise Exception("C3:ERROR:Unknown optimization type specified.") tf_utils.tf_setup() with tf.device("/CPU:0"): model = None gen = None exp = None prop_meth = cfg.pop("propagation_method", None) if "model" in cfg: model = Model() model.read_config(cfg.pop("model")) if "generator" in cfg: gen = Generator() gen.read_config(cfg.pop("generator")) if "instructions" in cfg: pmap = ParameterMap(model=model, generator=gen) pmap.read_config(cfg.pop("instructions")) exp = Experiment(pmap, prop_method=prop_meth) if "exp_cfg" in cfg: exp = Experiment(prop_method=prop_meth) exp.read_config(cfg.pop("exp_cfg")) if exp is None: print( "C3:STATUS: No instructions specified. Performing quick setup." ) exp = Experiment(prop_method=prop_meth) exp.quick_setup(cfg) exp.set_opt_gates(cfg.pop("opt_gates", None)) if "gateset_opt_map" in cfg: exp.pmap.set_opt_map([[tuple(par) for par in pset] for pset in cfg.pop("gateset_opt_map")]) if "exp_opt_map" in cfg: exp.pmap.set_opt_map([[tuple(par) for par in pset] for pset in cfg.pop("exp_opt_map")]) opt = optim_lib[optim_type](**cfg, pmap=exp.pmap) opt.set_exp(exp) opt.set_created_by(opt_config_filename) if "initial_point" in cfg: initial_points = cfg["initial_point"] if isinstance(initial_points, str): initial_points = [initial_points] elif isinstance(initial_points, list): pass else: raise Warning( "initial_point has to be a path or a list of paths.") for init_point in initial_points: try: opt.load_best(init_point) print("C3:STATUS:Loading initial point from : " f"{os.path.abspath(init_point)}") except FileNotFoundError as fnfe: raise Exception( f"C3:ERROR:No initial point found at " f"{os.path.abspath(init_point)}. ") from fnfe if optim_type == "C1": if "adjust_exp" in cfg: try: adjust_exp = cfg["adjust_exp"] opt.load_model_parameters(adjust_exp) print("C3:STATUS:Loading experimental values from : " f"{os.path.abspath(adjust_exp)}") except FileNotFoundError as fnfe: raise Exception( f"C3:ERROR:No experimental values found at " f"{os.path.abspath(adjust_exp)} " "Continuing with default.") from fnfe if not debug: opt.run()
def quick_setup(self, cfg) -> None: """ Load a quick setup cfg and create all necessary components. Parameters ---------- cfg : Dict Configuration options """ model = Model() model.read_config(cfg["model"]) gen = Generator() gen.read_config(cfg["generator"]) single_gate_time = cfg["single_qubit_gate_time"] v2hz = cfg["v2hz"] instructions = [] sideband = cfg.pop("sideband", None) for gate_name, props in cfg["single_qubit_gates"].items(): target_qubit = model.subsystems[props["qubits"]] instr = Instruction( name=props["name"], targets=[model.names.index(props["qubits"])], t_start=0.0, t_end=single_gate_time, channels=[target_qubit.drive_line], ) instr.quick_setup( target_qubit.drive_line, target_qubit.params["freq"].get_value() / 2 / np.pi, single_gate_time, v2hz, sideband, ) instructions.append(instr) for gate_name, props in cfg["two_qubit_gates"].items(): qubit_1 = model.subsystems[props["qubit_1"]] qubit_2 = model.subsystems[props["qubit_2"]] instr = Instruction( name=gate_name, targets=[ model.names.index(props["qubit_1"]), model.names.index(props["qubit_2"]), ], t_start=0.0, t_end=props["gate_time"], channels=[qubit_1.drive_line, qubit_2.drive_line], ) instr.quick_setup( qubit_1.drive_line, qubit_1.params["freq"].get_value() / 2 / np.pi, props["gate_time"], v2hz, sideband, ) instr.quick_setup( qubit_2.drive_line, qubit_2.params["freq"].get_value() / 2 / np.pi, props["gate_time"], v2hz, sideband, ) instructions.append(instr) self.pmap = ParameterMap(instructions, generator=gen, model=model)