def __init__(self, target_states, cost_multiplier=1.):
     """
     See class fields for arguments not listed here.
     
     Arguments:
     target_states
     """
     super().__init__(cost_multiplier=cost_multiplier)
     self.state_count = target_states.shape[0]
     self.target_states_dagger = conjugate_transpose(target_states)
Exemple #2
0
 def __init__(self, step_count, target_states, cost_multiplier=1.):
     """
     See class definition for parameter specification.
     target_states :: numpy.ndarray - an array of states
         that correspond to the target state for each of the initial states
         used in optimization
     """
     super().__init__(cost_multiplier=cost_multiplier)
     self.state_count = target_states.shape[0]
     self.step_count = step_count
     self.target_states_dagger = conjugate_transpose(
         anp.stack(target_states))
    def __init__(self, system_eval_count, target_densities,
                 cost_eval_step=1, cost_multiplier=1.,):
        """
        See class fields for arguments not listed here.

        Arguments:
        target_densities
        """
        super().__init__(cost_multiplier=cost_multiplier)
        self.cost_eval_count, _ = np.divmod(system_eval_count - 1, cost_eval_step)
        self.density_count = target_densities.shape[0]
        self.hilbert_size = target_densities.shape[1]
        self.target_densities_dagger = conjugate_transpose(np.stack(target_densities))
 def __init__(self, target_states, cost_multiplier=1.):
     """
     See class definition for parameter specification.
     target_states :: numpy.ndarray - an array of states
         that correspond to the target state for each of the initial states
         used in optimization
     """
     super().__init__(cost_multiplier=cost_multiplier)
     self.target_states_dagger = conjugate_transpose(np.stack(target_states))
     self.state_normalization_constant = len(target_states)
     # This cost function does not make use of parameter penalties.
     self.dcost_dparams = (lambda params, states, step:
                           np.zeros_like(params))
    def __init__(self, target_densities, cost_multiplier=1.):
        """
        See class definition for arguments not listed here.

        Args:
        target_densities :: ndarray (density_count x hilbert_size x hilbert_size)
            - an array of densities
            that correspond to the target density for each of the initial densities
            used in optimization
        """
        super().__init__(cost_multiplier=cost_multiplier)
        self.density_count = target_densities.shape[0]
        self.hilbert_size = target_densities.shape[-1]
        self.target_densities_dagger = conjugate_transpose(
            np.stack(target_densities))
Exemple #6
0
    def __init__(
        self,
        system_eval_count,
        target_states,
        neglect_relative_pahse=False,
        cost_eval_step=1,
        cost_multiplier=1.,
    ):
        """
        See class fields for arguments not listed here.

        Arguments:
        target_states
        """
        super().__init__(cost_multiplier=cost_multiplier)
        self.cost_eval_count, _ = np.divmod(system_eval_count - 1,
                                            cost_eval_step)
        self.state_count = target_states.shape[0]
        self.target_states_dagger = conjugate_transpose(
            anp.stack(target_states))
        self.neglect_relative_pahse = neglect_relative_pahse
Exemple #7
0
    def __init__(self,
                 forbidden_states,
                 system_step_count,
                 cost_multiplier=1.):
        """
        See class definition for arguments not listed here.

        Args:
        forbidden_states :: ndarray - an array where each entry
            in the first axis is an array of states that the corresponding
            evolving state is forbidden from, that is, each evolving
            state has its own list of forbidden states
        system_step_count :: int - the number of system steps in the evolution
        """
        super().__init__(cost_multiplier=cost_multiplier)
        self.forbidden_states_dagger = conjugate_transpose(forbidden_states)
        state_count = forbidden_states.shape[0]
        self.normalization_constant = state_count * system_step_count
        self.state_normalization_constants = np.array([
            state_forbidden_states.shape[0]
            for state_forbidden_states in forbidden_states
        ])
def _tests():
    """
    Run test on the module.
    """
    system_step_count = 10
    state0 = np.array([[0], [1]])
    density0 = np.matmul(state0, conjugate_transpose(state0))
    target_state0 = np.array([[1], [0]])
    target_density0 = np.matmul(target_state0,
                                conjugate_transpose(target_state0))
    densities = np.stack((density0, ), axis=0)
    targets = np.stack((target_density0, ), axis=0)
    ti = TargetDensityInfidelityTime(system_step_count, targets)
    cost = ti.cost(None, densities, None)
    assert (np.allclose(cost, 0.1))

    ti = TargetDensityInfidelity(system_step_count, densities)
    cost = ti.cost(None, densities, None)
    assert (np.allclose(cost, 0.075))

    state0 = np.array([[1], [0]])
    state1 = (np.array([[1j], [1]]) / np.sqrt(2))
    density0 = np.matmul(state0, conjugate_transpose(state0))
    density1 = np.matmul(state1, conjugate_transpose(state1))
    target_state0 = np.array([[1j], [0]])
    target_state1 = np.array([[1], [0]])
    target_density0 = np.matmul(target_state0,
                                conjugate_transpose(target_state0))
    target_density1 = np.matmul(target_state1,
                                conjugate_transpose(target_state1))
    densities = np.stack((
        density0,
        density1,
    ), axis=0)
    targets = np.stack((
        target_density0,
        target_density1,
    ), axis=0)
    ti = TargetDensityInfidelity(system_step_count, targets)
    cost = ti.cost(None, densities, None)
    expected_cost = (1 - np.divide(5, 32)) / 10
    assert (np.allclose(cost, expected_cost))
Exemple #9
0
def _test():
    """
    Run tests on the module.
    """
    system_step_count = 10
    state0 = np.array([[1], [0]])
    density0 = np.matmul(state0, conjugate_transpose(state0))
    forbid0_0 = np.array([[1], [0]])
    density0_0 = np.matmul(forbid0_0, conjugate_transpose(forbid0_0))
    forbid0_1 = np.divide(np.array([[1], [1]]), np.sqrt(2))
    density0_1 = np.matmul(forbid0_1, conjugate_transpose(forbid0_1))
    state1 = np.array([[0], [1]])
    density1 = np.matmul(state1, conjugate_transpose(state1))
    forbid1_0 = np.divide(np.array([[1], [1]]), np.sqrt(2))
    density1_0 = np.matmul(forbid1_0, conjugate_transpose(forbid1_0))
    forbid1_1 = np.divide(np.array([[1j], [1j]]), np.sqrt(2))
    density1_1 = np.matmul(forbid1_1, conjugate_transpose(forbid1_1))
    densities = np.stack((
        density0,
        density1,
    ))
    forbidden_densities0 = np.stack((
        density0_0,
        density0_1,
    ))
    forbidden_densities1 = np.stack((
        density1_0,
        density1_1,
    ))
    forbidden_densities = np.stack((
        forbidden_densities0,
        forbidden_densities1,
    ))
    fd = ForbidDensities(forbidden_densities, system_step_count)

    cost = fd.cost(None, densities, None)
    expected_cost = np.divide(7, 640)
    assert (np.allclose(
        cost,
        expected_cost,
    ))