def get_costs(control_eval_count, evolution_time): control_norm_weights = 1 - gauss( np.linspace(0, evolution_time, control_eval_count)) control_norm_weights = np.repeat(control_norm_weights[:, np.newaxis], CONTROL_COUNT, axis=1) # Don't penalize controls in the middle. control_offset = int(control_eval_count / 5) control_norm_weights[control_offset:-control_offset] = 0 return [ TargetStateInfidelity(TARGET_STATES, cost_multiplier=FIDELITY_MULTIPLIER), ControlVariation(CONTROL_COUNT, control_eval_count, cost_multiplier=CONTROL_VAR_01_MULTIPLIER, max_control_norms=MAX_CONTROL_NORMS, order=1), ControlVariation(CONTROL_COUNT, control_eval_count, cost_multiplier=CONTROL_VAR_02_MULTIPLIER, max_control_norms=MAX_CONTROL_NORMS, order=2), ControlNorm( CONTROL_COUNT, control_eval_count, control_weights=control_norm_weights, cost_multiplier=CONTROL_NORM_MULTIPLIER, max_control_norms=MAX_CONTROL_NORMS, ), ]
# Let's try to put a photon in the cavity. # That is, we desire the fock state transition |0, g> -> |1, g>. INITIAL_STATE_0 = krons(CAVITY_ZERO, TRANSMON_ZERO) # Notice that when we specify states (or probability density matrices!) # to qoc, we always give qoc an array of states that we would like it to track, # even if we only give qoc a single state. The `,` in anp.stack((INITIAL_STATE_0`,`)) # makes a difference. INITIAL_STATES = anp.stack((INITIAL_STATE_0,)) assert(INITIAL_STATES.ndim == 3) TARGET_STATE_0 = krons(CAVITY_ONE, TRANSMON_ZERO) TARGET_STATES = anp.stack((TARGET_STATE_0,)) # Costs are functions that we want qoc to minimize the output of. # In this example, we want to minimize the infidelity (maximize the fidelity) of # the initial state and the target state. # Note that `COSTS` is a list of cost function objects. COSTS = [TargetStateInfidelity(TARGET_STATES)] # We want to tell qoc how often to store information about the optimization # and how often to log output. Both `log_iteration_step` and `save_iteration_step` # are specified in units of optimization iterations. LOG_ITERATION_STEP = 1 SAVE_INTERMEDIATE_STATES = True SAVE_ITERATION_STEP = 1 # For this problem, the LBFGSB optimizer reaches a reasonable # answer very quickly. OPTIMIZER = LBFGSB() ITERATION_COUNT = 30 # In practice, we find that using a second-order optimizer, such as LBFGSB, # gives a good initial answer. Then, this answer may be used with a first- # order optimizer, such as Adam, to achieve the desired error.
CONTROL_COUNT, axis=1) # COSTS = [ # ControlNorm(CONTROL_COUNT, CONTROL_EVAL_COUNT, # control_weights=CONTROL_NORM_WEIGHTS, # cost_multiplier=1, # max_control_norms=MAX_CONTROL_NORMS,), # ] # psi_f1 = tensor(basis(qnum,0),basis(mnum,11)).full() # psi_f2 = tensor(basis(qnum,1),basis(mnum,11)).full() # forbidden_states = np.stack([[psi_f1, psi_f2] for _ in range(STATE_COUNT)]) # For multiple states # forbidden_states = np.stack([[psi_f1, psi_f2]],) COSTS = [ TargetStateInfidelity(TARGET_STATES), # ControlVariation(CONTROL_COUNT, CONTROL_EVAL_COUNT, # cost_multiplier=1, max_control_norms=MAX_CONTROL_NORMS, order=1), # ControlVariation(CONTROL_COUNT, CONTROL_EVAL_COUNT, # cost_multiplier=1, max_control_norms=MAX_CONTROL_NORMS, order=2), ] # ForbidStates(forbidden_states, SYSTEM_EVAL_COUNT, cost_multiplier=10), # ControlArea(CONTROL_COUNT, CONTROL_EVAL_COUNT, cost_multiplier=1, max_control_norms=MAX_CONTROL_NORMS), WDIR = os.environ["MULTIMODE_QOC_PATH"] SAVE_PATH = os.path.join(WDIR, "out", EXPERIMENT_META) GRAB_CONTROLS = True if GRAB_CONTROLS: controls_path = os.path.join(SAVE_PATH, "00002_swap_g10_g01.h5") controls_path_lock = "{}.lock".format(controls_path)
def gauss(x): b = anp.mean(x) c = anp.std(x) return anp.exp(-((x - b) ** 2) / (c ** 2)) CONTROL_NORM_WEIGHTS = 1 - gauss(anp.linspace(0, EVOLUTION_TIME, CONTROL_EVAL_COUNT)) CONTROL_NORM_WEIGHTS = anp.repeat(CONTROL_NORM_WEIGHTS[:, anp.newaxis], CONTROL_COUNT, axis=1) # Don't penalize controls in the middle. # CONTROL_OFFSET = int(CONTROL_COUNT / 5) # CONTROL_NORM_WEIGHTS[CONTROL_OFFSET:-CONTROL_OFFSET] = 0 CONTROL_BANDWIDTH_MULTIPLIER = 1. CONTROL_NORM_MULTIPLIER = 0.5 CONTROL_VAR_01_MULTIPLIER = 1. CONTROL_VAR_02_MULTIPLIER = 1. FIDELITY_MULTIPLIER = 1. COSTS = [ TargetStateInfidelity(TARGET_STATES, cost_multiplier=FIDELITY_MULTIPLIER), ControlVariation(CONTROL_COUNT, CONTROL_EVAL_COUNT, cost_multiplier=CONTROL_VAR_01_MULTIPLIER, max_control_norms=MAX_CONTROL_NORMS, order=1), ControlVariation(CONTROL_COUNT, CONTROL_EVAL_COUNT, cost_multiplier=CONTROL_VAR_02_MULTIPLIER, max_control_norms=MAX_CONTROL_NORMS, order=2), # ControlNorm(CONTROL_COUNT, CONTROL_EVAL_COUNT, # control_weights=CONTROL_NORM_WEIGHTS, # cost_multiplier=CONTROL_NORM_MULTIPLIER, # max_control_norms=MAX_CONTROL_NORMS,), # ControlBandwidthMax(CONTROL_COUNT, CONTROL_EVAL_COUNT, EVOLUTION_TIME,