def __init__( self, operator: BaseOperator, state_in: Optional[InitialState], iqft: IQFT, num_time_slices: int = 1, num_ancillae: int = 1, expansion_mode: str = 'trotter', expansion_order: int = 1, shallow_circuit_concat: bool = False) -> None: """ Args: operator: The Hamiltonian Operator state_in: An optional InitialState component representing an initial quantum state. ``None`` may be supplied. iqft: A Inverse Quantum Fourier Transform component num_time_slices: The number of time slices, has a minimum value of 1. num_ancillae: The number of ancillary qubits to use for the measurement, has a min. value of 1. expansion_mode: The expansion mode ('trotter'|'suzuki') expansion_order: The suzuki expansion order, has a min. value of 1. shallow_circuit_concat: Set True to use shallow (cheap) mode for circuit concatenation of evolution slices. By default this is False. See :meth:`qiskit.aqua.operators.common.evolution_instruction` for more information. """ validate_min('num_time_slices', num_time_slices, 1) validate_min('num_ancillae', num_ancillae, 1) validate_in_set('expansion_mode', expansion_mode, {'trotter', 'suzuki'}) validate_min('expansion_order', expansion_order, 1) super().__init__() self._operator = op_converter.to_weighted_pauli_operator(operator.copy()) self._num_ancillae = num_ancillae self._ret = {} self._ret['translation'] = sum([abs(p[0]) for p in self._operator.reorder_paulis()]) self._ret['stretch'] = 0.5 / self._ret['translation'] # translate the operator self._operator.simplify() translation_op = WeightedPauliOperator([ [ self._ret['translation'], Pauli( np.zeros(self._operator.num_qubits), np.zeros(self._operator.num_qubits) ) ] ]) translation_op.simplify() self._operator += translation_op self._pauli_list = self._operator.reorder_paulis() # stretch the operator for p in self._pauli_list: p[0] = p[0] * self._ret['stretch'] self._phase_estimation_circuit = PhaseEstimationCircuit( operator=self._operator, state_in=state_in, iqft=iqft, num_time_slices=num_time_slices, num_ancillae=num_ancillae, expansion_mode=expansion_mode, expansion_order=expansion_order, shallow_circuit_concat=shallow_circuit_concat, pauli_list=self._pauli_list ) self._binary_fractions = [1 / 2 ** p for p in range(1, num_ancillae + 1)]
def operator(self, operator: BaseOperator) -> None: """ Sets operator """ if operator is not None: self._in_operator = operator self.var_form = QAOAVarForm(operator.copy(), self._p, initial_state=self._initial_state, mixer_operator=self._mixer_operator)
def __init__(self, operator: BaseOperator, optimizer: Optimizer, p: int = 1, initial_state: Optional[InitialState] = None, mixer: Optional[BaseOperator] = None, initial_point: Optional[np.ndarray] = None, max_evals_grouped: int = 1, aux_operators: Optional[List[BaseOperator]] = None, callback: Optional[Callable[[int, np.ndarray, float, float], None]] = None, auto_conversion: bool = True) -> None: """ Args: operator: Qubit operator optimizer: The classical optimizer to use. p: the integer parameter p as specified in https://arxiv.org/abs/1411.4028, has a min. value of 1. initial_state: the initial state to prepend the QAOA circuit with mixer: the mixer Hamiltonian to evolve with. Allows support of optimizations in constrained subspaces as per https://arxiv.org/abs/1709.03489 optimizer: the classical optimization algorithm. initial_point: optimizer initial point. max_evals_grouped: max number of evaluations to be performed simultaneously. aux_operators: aux operators callback: a callback that can access the intermediate data during the optimization. Internally, four arguments are provided as follows the index of evaluation, parameters of variational form, evaluated mean, evaluated standard deviation. auto_conversion: an automatic conversion for operator and aux_operators into the type which is most suitable for the backend. - for *non-Aer statevector simulator:* :class:`~qiskit.aqua.operators.MatrixOperator` - for *Aer statevector simulator:* :class:`~qiskit.aqua.operators.WeightedPauliOperator` - for *qasm simulator or real backend:* :class:`~qiskit.aqua.operators.TPBGroupedWeightedPauliOperator` """ validate_min('p', p, 1) var_form = QAOAVarForm(operator.copy(), p, initial_state=initial_state, mixer_operator=mixer) super().__init__(operator, var_form, optimizer, initial_point=initial_point, max_evals_grouped=max_evals_grouped, aux_operators=aux_operators, callback=callback, auto_conversion=auto_conversion)
def __init__(self, operator: BaseOperator, state_in: InitialState, num_time_slices: int = 1, num_iterations: int = 1, expansion_mode: str = 'suzuki', expansion_order: int = 2, shallow_circuit_concat: bool = False) -> None: """ Args: operator: the hamiltonian Operator object state_in: the InitialState component representing the initial quantum state num_time_slices: the number of time slices, has a min. value of 1. num_iterations: the number of iterations, has a min. value of 1. expansion_mode: the expansion mode (trotter|suzuki) expansion_order: the suzuki expansion order, has a min. value of 1. shallow_circuit_concat: indicate whether to use shallow (cheap) mode for circuit concatenation """ validate_min('num_time_slices', num_time_slices, 1) validate_min('num_iterations', num_iterations, 1) validate_in_set('expansion_mode', expansion_mode, {'trotter', 'suzuki'}) validate_min('expansion_order', expansion_order, 1) super().__init__() self._operator = op_converter.to_weighted_pauli_operator( operator.copy()) self._state_in = state_in self._num_time_slices = num_time_slices self._num_iterations = num_iterations self._expansion_mode = expansion_mode self._expansion_order = expansion_order self._shallow_circuit_concat = shallow_circuit_concat self._state_register = None self._ancillary_register = None self._pauli_list = None self._ret = {} self._ancilla_phase_coef = None self._setup()
def __init__(self, operator: BaseOperator, state_in: InitialState, iqft: IQFT, num_time_slices: int = 1, num_ancillae: int = 1, expansion_mode: str = 'trotter', expansion_order: int = 1, shallow_circuit_concat: bool = False) -> None: """ Args: operator: the hamiltonian Operator object state_in: the InitialState component representing the initial quantum state iqft: the Inverse Quantum Fourier Transform component num_time_slices: the number of time slices, has a min. value of 1. num_ancillae: the number of ancillary qubits to use for the measurement, has a min. value of 1. expansion_mode: the expansion mode (trotter|suzuki) expansion_order: the suzuki expansion order, has a min. value of 1. shallow_circuit_concat: indicate whether to use shallow (cheap) mode for circuit concatenation """ validate_min('num_time_slices', num_time_slices, 1) validate_min('num_ancillae', num_ancillae, 1) validate_in_set('expansion_mode', expansion_mode, {'trotter', 'suzuki'}) validate_min('expansion_order', expansion_order, 1) super().__init__() self._operator = op_converter.to_weighted_pauli_operator( operator.copy()) self._num_ancillae = num_ancillae self._ret = {} self._ret['translation'] = sum( [abs(p[0]) for p in self._operator.reorder_paulis()]) self._ret['stretch'] = 0.5 / self._ret['translation'] # translate the operator self._operator.simplify() translation_op = WeightedPauliOperator([[ self._ret['translation'], Pauli(np.zeros(self._operator.num_qubits), np.zeros(self._operator.num_qubits)) ]]) translation_op.simplify() self._operator += translation_op self._pauli_list = self._operator.reorder_paulis() # stretch the operator for p in self._pauli_list: p[0] = p[0] * self._ret['stretch'] self._phase_estimation_circuit = PhaseEstimationCircuit( operator=self._operator, state_in=state_in, iqft=iqft, num_time_slices=num_time_slices, num_ancillae=num_ancillae, expansion_mode=expansion_mode, expansion_order=expansion_order, shallow_circuit_concat=shallow_circuit_concat, pauli_list=self._pauli_list) self._binary_fractions = [1 / 2**p for p in range(1, num_ancillae + 1)]
def __init__(self, operator: BaseOperator, optimizer: Optimizer, p: int = 1, initial_state: Optional[InitialState] = None, mixer: Optional[BaseOperator] = None, initial_point: Optional[np.ndarray] = None, max_evals_grouped: int = 1, aux_operators: Optional[List[BaseOperator]] = None, callback: Optional[Callable[[int, np.ndarray, float, float], None]] = None, auto_conversion: bool = True) -> None: """ Args: operator: Qubit operator optimizer: A classical optimizer. p: the integer parameter p as specified in https://arxiv.org/abs/1411.4028, Has a minimum valid value of 1. initial_state: An optional initial state to prepend the QAOA circuit with mixer: the mixer Hamiltonian to evolve with. Allows support of optimizations in constrained subspaces as per https://arxiv.org/abs/1709.03489 initial_point: An optional initial point (i.e. initial parameter values) for the optimizer. If ``None`` then it will simply compute a random one. max_evals_grouped: Max number of evaluations performed simultaneously. Signals the given optimizer that more than one set of parameters can be supplied so that potentially the expectation values can be computed in parallel. Typically this is possible when a finite difference gradient is used by the optimizer such that multiple points to compute the gradient can be passed and if computed in parallel improve overall execution time. aux_operators: Optional list of auxiliary operators to be evaluated with the eigenstate of the minimum eigenvalue main result and their expectation values returned. For instance in chemistry these can be dipole operators, total particle count operators so we can get values for these at the ground state. callback: a callback that can access the intermediate data during the optimization. Four parameter values are passed to the callback as follows during each evaluation by the optimizer for its current set of parameters as it works towards the minimum. These are: the evaluation count, the optimizer parameters for the variational form, the evaluated mean and the evaluated standard deviation. auto_conversion: When ``True`` allows an automatic conversion for operator and aux_operators into the type which is most suitable for the backend on which the algorithm is run. - for *non-Aer statevector simulator:* :class:`~qiskit.aqua.operators.MatrixOperator` - for *Aer statevector simulator:* :class:`~qiskit.aqua.operators.WeightedPauliOperator` - for *qasm simulator or real backend:* :class:`~qiskit.aqua.operators.TPBGroupedWeightedPauliOperator` """ validate_min('p', p, 1) var_form = QAOAVarForm(operator.copy(), p, initial_state=initial_state, mixer_operator=mixer) super().__init__(operator, var_form, optimizer, initial_point=initial_point, max_evals_grouped=max_evals_grouped, aux_operators=aux_operators, callback=callback, auto_conversion=auto_conversion)
def __init__(self, operator: BaseOperator, var_form: VariationalForm, optimizer: Optimizer, num_orbitals: int, num_particles: Union[List[int], int], initial_point: Optional[np.ndarray] = None, max_evals_grouped: int = 1, callback: Optional[Callable[[int, np.ndarray, float, float], None]] = None, auto_conversion: bool = True, qubit_mapping: str = 'parity', two_qubit_reduction: bool = True, is_eom_matrix_symmetric: bool = True, active_occupied: Optional[List[int]] = None, active_unoccupied: Optional[List[int]] = None, se_list: Optional[List[List[int]]] = None, de_list: Optional[List[List[int]]] = None, z2_symmetries: Optional[Z2Symmetries] = None, untapered_op: Optional[BaseOperator] = None, aux_operators: Optional[List[BaseOperator]] = None) -> None: """ Args: operator: qubit operator var_form: parameterized variational form. optimizer: the classical optimization algorithm. num_orbitals: total number of spin orbitals, has a min. value of 1. num_particles: number of particles, if it is a list, the first number is alpha and the second number if beta. initial_point: optimizer initial point, 1-D vector max_evals_grouped: max number of evaluations performed simultaneously callback: a callback that can access the intermediate data during the optimization. Internally, four arguments are provided as follows the index of evaluation, parameters of variational form, evaluated mean, evaluated standard deviation. auto_conversion: an automatic conversion for operator and aux_operators into the type which is most suitable for the backend. - non-aer statevector_simulator: MatrixOperator - aer statevector_simulator: WeightedPauliOperator - qasm simulator or real backend: TPBGroupedWeightedPauliOperator qubit_mapping: qubit mapping type two_qubit_reduction: two qubit reduction is applied or not is_eom_matrix_symmetric: is EoM matrix symmetric active_occupied: list of occupied orbitals to include, indices are 0 to n where n is num particles // 2 active_unoccupied: list of unoccupied orbitals to include, indices are 0 to m where m is (num_orbitals - num particles) // 2 se_list: single excitation list, overwrite the setting in active space de_list: double excitation list, overwrite the setting in active space z2_symmetries: represent the Z2 symmetries untapered_op: if the operator is tapered, we need untapered operator during building element of EoM matrix aux_operators: Auxiliary operators to be evaluated at each eigenvalue Raises: ValueError: invalid parameter """ validate_min('num_orbitals', num_orbitals, 1) validate_in_set('qubit_mapping', qubit_mapping, {'jordan_wigner', 'parity', 'bravyi_kitaev'}) if isinstance(num_particles, list) and len(num_particles) != 2: raise ValueError('Num particles value {}. Number of values allowed is 2'.format( num_particles)) super().__init__(operator.copy(), var_form, optimizer, initial_point=initial_point, max_evals_grouped=max_evals_grouped, aux_operators=aux_operators, callback=callback, auto_conversion=auto_conversion) self.qeom = QEquationOfMotion(operator, num_orbitals, num_particles, qubit_mapping, two_qubit_reduction, active_occupied, active_unoccupied, is_eom_matrix_symmetric, se_list, de_list, z2_symmetries, untapered_op)