def __init__(self, operator: BaseOperator, initial_state: InitialState, evo_operator: BaseOperator, evo_time: float = 1, num_time_slices: int = 1, expansion_mode: str = 'trotter', expansion_order: int = 1) -> None: """ Args: operator: Operator to evaluate initial_state: Initial state for evolution evo_operator: Operator to evolve evo_time: Evolution time, has min value of 0 num_time_slices: Number of time slices, has minimum value of 1 expansion_mode: Either ``"trotter"`` (Lloyd's method) or ``"suzuki"`` (for Trotter-Suzuki expansion) expansion_order: The Trotter-Suzuki expansion order. """ validate_min('evo_time', evo_time, 0) validate_min('num_time_slices', num_time_slices, 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) self._initial_state = initial_state self._evo_operator = op_converter.to_weighted_pauli_operator( evo_operator) self._evo_time = evo_time self._num_time_slices = num_time_slices self._expansion_mode = expansion_mode self._expansion_order = expansion_order self._ret = {}
def __init__(self, operator: LegacyBaseOperator, initial_state: Union[InitialState, QuantumCircuit], evo_operator: LegacyBaseOperator, evo_time: float = 1, num_time_slices: int = 1, expansion_mode: str = 'trotter', expansion_order: int = 1, quantum_instance: Optional[ Union[QuantumInstance, BaseBackend, Backend]] = None) -> None: """ Args: operator: Operator to evaluate initial_state: Initial state for evolution evo_operator: Operator to evolve evo_time: Evolution time, has min value of 0 num_time_slices: Number of time slices, has minimum value of 1 expansion_mode: Either ``"trotter"`` (Lloyd's method) or ``"suzuki"`` (for Trotter-Suzuki expansion) expansion_order: The Trotter-Suzuki expansion order. quantum_instance: Quantum Instance or Backend """ validate_min('evo_time', evo_time, 0) validate_min('num_time_slices', num_time_slices, 1) validate_in_set('expansion_mode', expansion_mode, {'trotter', 'suzuki'}) validate_min('expansion_order', expansion_order, 1) super().__init__(quantum_instance) self._operator = op_converter.to_weighted_pauli_operator(operator) self._initial_state = initial_state self._evo_operator = op_converter.to_weighted_pauli_operator(evo_operator) self._evo_time = evo_time self._num_time_slices = num_time_slices self._expansion_mode = expansion_mode self._expansion_order = expansion_order self._ret = {} # type: Dict[str, Any]
def __init__(self, feature_dimension: int, depth: int = 2, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', data_map_func: Callable[[np.ndarray], float] = self_product) -> None: """ Args: feature_dimension: The number of features depth: The number of repeated circuits. Defaults to 2, has a minimum value of 1. entangler_map: Describes the connectivity of qubits, each list in the overall list describes [source, target]. Defaults to ``None`` where the map is created as per *entanglement* parameter. Note that the order in the list is the order of applying the two-qubit gate. entanglement: ('full' | 'linear'), generate the qubit connectivity by a predefined topology. Defaults to full which connects every qubit to each other. Linear connects each qubit to the next. data_map_func: A mapping function for data x which can be supplied to override the default mapping from :meth:`self_product`. """ warnings.warn('The qiskit.aqua.components.feature_maps.SecondOrderExpansion object is ' 'deprecated as of 0.7.0 and will be removed no sooner than 3 months after ' 'the release. You should use qiskit.circuit.library.ZZFeatureMap instead.', DeprecationWarning, stacklevel=2) validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) super().__init__(feature_dimension, depth, entangler_map, entanglement, z_order=2, data_map_func=data_map_func)
def __init__( self, feature_dimension: int, depth: int = 2, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', data_map_func: Callable[[np.ndarray], float] = self_product) -> None: """Constructor. Args: feature_dimension: number of features depth: the number of repeated circuits, has a min. value of 1. entangler_map: describe the connectivity of qubits, each list describes [source, target], or None for full entanglement. Note that the order is the list is the order of applying the two-qubit gate. entanglement: ['full', 'linear'], generate the qubit connectivity by predefined topology data_map_func: a mapping function for data x """ validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) super().__init__(feature_dimension, depth, entangler_map, entanglement, z_order=2, data_map_func=data_map_func)
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 __init__(self, num_qubits: int, depth: int = 3, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', initial_state: Optional[InitialState] = None, entanglement_gate: str = 'cz', skip_unentangled_qubits: bool = False) -> None: """ Args: num_qubits: Number of qubits, has a minimum value of 1. depth: Number of rotation layers, has a minimum value of 1. entangler_map: Describe the connectivity of qubits, each list pair describes [source, target], or None for as defined by `entanglement`. Note that the order is the list is the order of applying the two-qubit gate. entanglement: ('full' | 'linear') overridden by 'entangler_map` if its provided. 'full' is all-to-all entanglement, 'linear' is nearest-neighbor. initial_state: An initial state object entanglement_gate: ('cz' | 'cx') skip_unentangled_qubits: Skip the qubits not in the entangler_map """ warnings.warn( 'The qiskit.aqua.components.variational_forms.RYRZ object is deprecated as ' 'of 0.7.0 and will be removed no sooner than 3 months after the release. You ' 'should use qiskit.circuit.library.EfficientSU2 (uses CX entangling) or ' 'qiskit.circuit.library.TwoLocal instead.', DeprecationWarning, stacklevel=2) validate_min('num_qubits', num_qubits, 1) validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) validate_in_set('entanglement_gate', entanglement_gate, {'cz', 'cx'}) super().__init__() self._num_qubits = num_qubits self._depth = depth if entangler_map is None: self._entangler_map = VariationalForm.get_entangler_map( entanglement, num_qubits) else: self._entangler_map = VariationalForm.validate_entangler_map( entangler_map, num_qubits) # determine the entangled qubits all_qubits = [] for src, targ in self._entangler_map: all_qubits.extend([src, targ]) self._entangled_qubits = sorted(list(set(all_qubits))) self._initial_state = initial_state self._entanglement_gate = entanglement_gate self._skip_unentangled_qubits = skip_unentangled_qubits # for the first layer self._num_parameters = len(self._entangled_qubits) * 2 if self._skip_unentangled_qubits \ else self._num_qubits * 2 # for repeated block self._num_parameters += len(self._entangled_qubits) * depth * 2 self._bounds = [(-np.pi, np.pi)] * self._num_parameters self._support_parameterized_circuit = True
def __init__(self, num_qubits: int, state: str = 'zero', state_vector: Optional[Union[np.ndarray, StateFn]] = None, circuit: Optional[QuantumCircuit] = None) -> None: """ Args: num_qubits: Number of qubits, has a minimum value of 1. state: Use a predefined state of ('zero' | 'uniform' | 'random') state_vector: An optional vector of ``complex`` or ``float`` representing the state as a probability distribution which will be normalized to a total probability of 1 when initializing the qubits. The length of the vector must be :math:`2^q`, where :math:`q` is the *num_qubits* value. When provided takes precedence over *state*. circuit: A quantum circuit for the desired initial state. When provided takes precedence over both *state_vector* and *state*. Raises: AquaError: invalid input """ validate_min('num_qubits', num_qubits, 1) validate_in_set('state', state, {'zero', 'uniform', 'random'}) super().__init__() self._num_qubits = num_qubits self._state = state size = np.power(2, self._num_qubits) self._circuit = None if isinstance(state_vector, StateFn): state_vector = state_vector.to_matrix() # pylint: disable=comparison-with-callable if circuit is not None: if circuit.width() != num_qubits: logger.warning('The specified num_qubits and ' 'the provided custom circuit do not match.') self._circuit = convert_to_basis_gates(circuit) if state_vector is not None: self._state = None self._state_vector = None logger.warning( 'The provided state_vector is ignored in favor of ' 'the provided custom circuit.') else: if state_vector is None: if self._state == 'zero': self._state_vector = np.array([1.0] + [0.0] * (size - 1)) elif self._state == 'uniform': self._state_vector = np.array([1.0 / np.sqrt(size)] * size) elif self._state == 'random': self._state_vector = normalize_vector( aqua_globals.random.random(size)) else: raise AquaError('Unknown state {}'.format(self._state)) else: if len(state_vector) != np.power(2, self._num_qubits): raise AquaError( 'The state vector length {} is incompatible with ' 'the number of qubits {}'.format( len(state_vector), self._num_qubits)) self._state_vector = normalize_vector(state_vector) self._state = None
def _check_deprecated_args(init_state, mct_mode, rotation_counts, lam, num_iterations): """Check the deprecated args, can be removed 3 months after 0.8.0.""" # init_state has been renamed to state_preparation if init_state is not None: warnings.warn( 'The init_state argument is deprecated as of 0.8.0, and will be removed ' 'no earlier than 3 months after the release date. You should use the ' 'state_preparation argument instead and pass a QuantumCircuit or ' 'Statevector instead of an InitialState.', DeprecationWarning, stacklevel=3) if mct_mode is not None: validate_in_set( 'mct_mode', mct_mode, {'basic', 'basic-dirty-ancilla', 'advanced', 'noancilla'}) warnings.warn( 'The mct_mode argument is deprecated as of 0.8.0, and will be removed no ' 'earlier than 3 months after the release date. If you want to use a ' 'special MCX mode you should use the GroverOperator in ' 'qiskit.circuit.library directly and pass it to the grover_operator ' 'keyword argument.', DeprecationWarning, stacklevel=3) if rotation_counts is not None: warnings.warn( 'The rotation_counts argument is deprecated as of 0.8.0, and will be ' 'removed no earlier than 3 months after the release date. ' 'If you want to use the incremental mode with the rotation_counts ' 'argument or you should use the iterations argument instead and pass ' 'a list of integers', DeprecationWarning, stacklevel=3) if lam is not None: warnings.warn( 'The lam argument is deprecated as of 0.8.0, and will be ' 'removed no earlier than 3 months after the release date. ' 'If you want to use the incremental mode with the lam argument, ' 'you should use the iterations argument instead and pass ' 'a list of integers calculated with the lam argument.', DeprecationWarning, stacklevel=3) if num_iterations is not None: validate_min('num_iterations', num_iterations, 1) warnings.warn( 'The num_iterations argument is deprecated as of 0.8.0, and will be ' 'removed no earlier than 3 months after the release date. ' 'If you want to use the num_iterations argument ' 'you should use the iterations argument instead and pass an integer ' 'for the number of iterations.', DeprecationWarning, stacklevel=3)
def __init__(self, oracle: Oracle, init_state: Optional[InitialState] = None, incremental: bool = False, num_iterations: int = 1, mct_mode: str = 'basic') -> None: """ Constructor. Args: oracle: the oracle component init_state: the initial quantum state preparation incremental: boolean flag for whether to use incremental search mode or not num_iterations: the number of iterations to use for amplitude amplification, has a min. value of 1. mct_mode: mct mode Raises: AquaError: evaluate_classically() missing from the input oracle """ validate_min('num_iterations', num_iterations, 1) validate_in_set( 'mct_mode', mct_mode, {'basic', 'basic-dirty-ancilla', 'advanced', 'noancilla'}) super().__init__() if not callable(getattr(oracle, "evaluate_classically", None)): raise AquaError( 'Missing the evaluate_classically() method from the provided oracle instance.' ) self._oracle = oracle self._mct_mode = mct_mode self._init_state = \ init_state if init_state else Custom(len(oracle.variable_register), state='uniform') self._init_state_circuit = \ self._init_state.construct_circuit(mode='circuit', register=oracle.variable_register) self._init_state_circuit_inverse = self._init_state_circuit.inverse() self._diffusion_circuit = self._construct_diffusion_circuit() self._max_num_iterations = np.ceil(2**(len(oracle.variable_register) / 2)) self._incremental = incremental self._num_iterations = num_iterations if not incremental else 1 if incremental: logger.debug( 'Incremental mode specified, ignoring "num_iterations".') else: if num_iterations > self._max_num_iterations: logger.warning( 'The specified value %s for "num_iterations" ' 'might be too high.', num_iterations) self._ret = {} self._qc_aa_iteration = None self._qc_amplitude_amplification = None self._qc_measurement = None
def __init__( self, operator: Optional[Union[OperatorBase, LegacyBaseOperator]] = None, state_in: Optional[Union[InitialState, QuantumCircuit]] = None, iqft: Optional[QuantumCircuit] = None, num_time_slices: int = 1, num_ancillae: int = 1, expansion_mode: str = 'trotter', expansion_order: int = 1, shallow_circuit_concat: bool = False, quantum_instance: Optional[Union[QuantumInstance, BaseBackend, Backend]] = None ) -> 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. quantum_instance: Quantum Instance or Backend """ 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__(quantum_instance) self._state_in = state_in self._iqft = iqft self._num_time_slices = num_time_slices self._num_ancillae = num_ancillae self._expansion_mode = expansion_mode self._expansion_order = expansion_order self._shallow_circuit_concat = shallow_circuit_concat self._binary_fractions = [ 1 / 2**p for p in range(1, self._num_ancillae + 1) ] self._in_operator = operator self._operator = None # type: Optional[WeightedPauliOperator] self._ret = {} # type: Dict[str, Any] self._pauli_list = None # type: Optional[List[List[Union[complex, Pauli]]]] self._phase_estimation_circuit = None self._setup(operator)
def __init__(self, bitmaps: Union[str, List[str]], optimization: bool = False, mct_mode: str = 'basic'): """ Constructor for Truth Table-based Oracle Args: bitmaps: A single binary string or a list of binary strings representing the desired single- and multi-value truth table. optimization: Boolean flag for attempting circuit optimization. When set, the Quine-McCluskey algorithm is used to compute the prime implicants of the truth table, and then its exact cover is computed to try to reduce the circuit. mct_mode: The mode to use when constructing multiple-control Toffoli. Raises: AquaError: invalid input """ if isinstance(bitmaps, str): bitmaps = [bitmaps] validate_in_set( 'mct_mode', mct_mode, {'basic', 'basic-dirty-ancilla', 'advanced', 'noancilla'}) super().__init__() self._mct_mode = mct_mode.strip().lower() self._optimization = optimization self._bitmaps = bitmaps # check that the input bitmaps length is a power of 2 if not is_power_of_2(len(bitmaps[0])): raise AquaError('Length of any bitmap must be a power of 2.') for bitmap in bitmaps[1:]: if not len(bitmap) == len(bitmaps[0]): raise AquaError('Length of all bitmaps must be the same.') self._nbits = int(math.log(len(bitmaps[0]), 2)) self._num_outputs = len(bitmaps) self._lit_to_var = None self._var_to_lit = None esop_exprs = [] for bitmap in bitmaps: esop_expr = self._get_esop_ast(bitmap) esop_exprs.append(esop_expr) self._esops = [ ESOP(esop_expr, num_vars=self._nbits) for esop_expr in esop_exprs ] if esop_exprs else None self.construct_circuit()
def __init__(self, operator: BaseOperator, num_orbitals: int, num_particles: Union[List[int], int], qubit_mapping: str = 'parity', two_qubit_reduction: bool = True, active_occupied: Optional[List[int]] = None, active_unoccupied: Optional[List[int]] = None, is_eom_matrix_symmetric: bool = True, 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 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. qubit_mapping: qubit mapping type two_qubit_reduction: two qubit reduction is applied or not 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 is_eom_matrix_symmetric: is EoM matrix symmetric 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 to build 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, 1, aux_operators) 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)
def __init__(self, num_qubits: int, state: str = 'zero', state_vector: Optional[np.ndarray] = None, circuit: Optional[QuantumCircuit] = None) -> None: """Constructor. Args: num_qubits: number of qubits, has a min. value of 1. state: `zero`, `uniform` or `random` state_vector: customized vector circuit: the actual custom circuit for the desired initial state Raises: AquaError: invalid input """ validate_min('num_qubits', num_qubits, 1) validate_in_set('state', state, {'zero', 'uniform', 'random'}) super().__init__() self._num_qubits = num_qubits self._state = state size = np.power(2, self._num_qubits) self._circuit = None if circuit is not None: if circuit.width() != num_qubits: logger.warning('The specified num_qubits and ' 'the provided custom circuit do not match.') self._circuit = convert_to_basis_gates(circuit) if state_vector is not None: self._state = None self._state_vector = None logger.warning( 'The provided state_vector is ignored in favor of ' 'the provided custom circuit.') else: if state_vector is None: if self._state == 'zero': self._state_vector = np.array([1.0] + [0.0] * (size - 1)) elif self._state == 'uniform': self._state_vector = np.array([1.0 / np.sqrt(size)] * size) elif self._state == 'random': self._state_vector = normalize_vector( aqua_globals.random.rand(size)) else: raise AquaError('Unknown state {}'.format(self._state)) else: if len(state_vector) != np.power(2, self._num_qubits): raise AquaError( 'The state vector length {} is incompatible with ' 'the number of qubits {}'.format( len(state_vector), self._num_qubits)) self._state_vector = normalize_vector(state_vector) self._state = None
def __init__( self, feature_dimension: int, depth: int = 2, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', paulis: Optional[List[str]] = None, data_map_func: Callable[[np.ndarray], float] = self_product) -> None: """ Args: feature_dimension: The number of features depth: The number of repeated circuits. Defaults to 2, has a minimum value of 1. entangler_map: Describes the connectivity of qubits, each list in the overall list describes [source, target]. Defaults to ``None`` where the map is created as per *entanglement* parameter. Note that the order in the list is the order of applying the two-qubit gate. entanglement: ('full' | 'linear'), generate the qubit connectivity by a predefined topology. Defaults to full which connects every qubit to each other. Linear connects each qubit to the next. paulis: a list of strings for to-be-used paulis (a pauli is a any combination of I, X, Y ,Z). Note that the order of pauli label is counted from right to left as the notation used in Pauli class in Qiskit Terra. Defaults to ``None`` whereupon ['Z', 'ZZ'] will be used. data_map_func: A mapping function for data x which can be supplied to override the default mapping from :meth:`self_product`. """ warnings.warn( 'The qiskit.aqua.components.feature_maps.PauliExpansion object is ' 'deprecated as of 0.7.0 and will be removed no sooner than 3 months after ' 'the release. You should use qiskit.circuit.library.PauliFeatureMap instead.', DeprecationWarning, stacklevel=2) paulis = paulis if paulis is not None else ['Z', 'ZZ'] validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) super().__init__() self._num_qubits = self._feature_dimension = feature_dimension self._depth = depth if entangler_map is None: self._entangler_map = self.get_entangler_map( entanglement, feature_dimension) else: self._entangler_map = self.validate_entangler_map( entangler_map, feature_dimension) self._pauli_strings = self._build_subset_paulis_string(paulis) self._data_map_func = data_map_func self._support_parameterized_circuit = True
def __init__(self, num_qubits: int, depth: int = 3, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', initial_state: Optional[InitialState] = None, entanglement_gate: str = 'cz', skip_unentangled_qubits: bool = False) -> None: """ Args: num_qubits: Number of qubits, has a minimum value of 1. depth: Number of rotation layers, has a minimum value of 1. entangler_map: Describe the connectivity of qubits, each list pair describes [source, target], or None for as defined by `entanglement`. Note that the order is the list is the order of applying the two-qubit gate. entanglement: ('full' | 'linear') overridden by 'entangler_map` if its provided. 'full' is all-to-all entanglement, 'linear' is nearest-neighbor. initial_state: An initial state object entanglement_gate: ('cz' | 'cx') skip_unentangled_qubits: Skip the qubits not in the entangler_map """ validate_min('num_qubits', num_qubits, 1) validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) validate_in_set('entanglement_gate', entanglement_gate, {'cz', 'cx'}) super().__init__() self._num_qubits = num_qubits self._depth = depth if entangler_map is None: self._entangler_map = VariationalForm.get_entangler_map(entanglement, num_qubits) else: self._entangler_map = VariationalForm.validate_entangler_map(entangler_map, num_qubits) # determine the entangled qubits all_qubits = [] for src, targ in self._entangler_map: all_qubits.extend([src, targ]) self._entangled_qubits = sorted(list(set(all_qubits))) self._initial_state = initial_state self._entanglement_gate = entanglement_gate self._skip_unentangled_qubits = skip_unentangled_qubits # for the first layer self._num_parameters = len(self._entangled_qubits) * 2 if self._skip_unentangled_qubits \ else self._num_qubits * 2 # for repeated block self._num_parameters += len(self._entangled_qubits) * depth * 2 self._bounds = [(-np.pi, np.pi)] * self._num_parameters self._support_parameterized_circuit = True
def __init__(self, operator: LegacyBaseOperator, iqft: QuantumCircuit, num_time_slices: int = 1, num_ancillae: int = 1, expansion_mode: str = 'trotter', expansion_order: int = 1, evo_time: Optional[float] = None, negative_evals: bool = False, ne_qfts: Optional[List] = None) -> None: """ Args: operator: The Hamiltonian Operator object iqft: The Inverse Quantum Fourier Transform circuit 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 minimum value of 1. expansion_mode: The expansion mode ('trotter' | 'suzuki') expansion_order: The suzuki expansion order, has a minimum value of 1. evo_time: An optional evolution time which should scale the eigenvalue onto the range :math:`(0,1]` (or :math:`(-0.5,0.5]` for negative eigenvalues). Defaults to ``None`` in which case a suitably estimated evolution time is internally computed. negative_evals: Set ``True`` to indicate negative eigenvalues need to be handled ne_qfts: The QFT and IQFT circuits for handling negative eigenvalues """ super().__init__() ne_qfts = ne_qfts if ne_qfts is not None else [None, None] 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) self._operator = op_converter.to_weighted_pauli_operator(operator) self._iqft = iqft self._num_ancillae = num_ancillae self._num_time_slices = num_time_slices self._expansion_mode = expansion_mode self._expansion_order = expansion_order self._evo_time = evo_time self._negative_evals = negative_evals self._ne_qfts = ne_qfts self._circuit = None self._output_register = None self._input_register = None self._init_constants()
def __init__( self, epsilon: float, alpha: float, confint_method: str = 'beta', min_ratio: float = 2.0, a_factory: Optional[CircuitFactory] = None, q_factory: Optional[CircuitFactory] = None, i_objective: Optional[int] = None, quantum_instance: Optional[Union[QuantumInstance, BaseBackend]] = None ) -> None: """ The output of the algorithm is an estimate for the amplitude `a`, that with at least probability 1 - alpha has an error of epsilon. The number of A operator calls scales linearly in 1/epsilon (up to a logarithmic factor). Args: epsilon: Target precision for estimation target `a`, has values between 0 and 0.5 alpha: Confidence level, the target probability is 1 - alpha, has values between 0 and 1 confint_method: Statistical method used to estimate the confidence intervals in each iteration, can be 'chernoff' for the Chernoff intervals or 'beta' for the Clopper-Pearson intervals (default) min_ratio: Minimal q-ratio (K_{i+1} / K_i) for FindNextK a_factory: The A operator, specifying the QAE problem q_factory: The Q operator (Grover operator), constructed from the A operator i_objective: Index of the objective qubit, that marks the 'good/bad' states quantum_instance: Quantum Instance or Backend Raises: AquaError: if the method to compute the confidence intervals is not supported """ # validate ranges of input arguments validate_range('epsilon', epsilon, 0, 0.5) validate_range('alpha', alpha, 0, 1) validate_in_set('confint_method', confint_method, {'chernoff', 'beta'}) super().__init__(a_factory, q_factory, i_objective, quantum_instance) # store parameters self._epsilon = epsilon self._alpha = alpha self._min_ratio = min_ratio self._confint_method = confint_method # results dictionary self._ret = {} # type: Dict[str, Any]
def __init__( self, operator: Optional[Union[OperatorBase, LegacyBaseOperator]] = None, state_in: Optional[Union[QuantumCircuit, InitialState]] = None, num_time_slices: int = 1, num_iterations: int = 1, expansion_mode: str = 'suzuki', expansion_order: int = 2, shallow_circuit_concat: bool = False, quantum_instance: Optional[Union[QuantumInstance, BaseBackend, Backend]] = None ) -> None: """ Args: operator: The hamiltonian Operator state_in: An InitialState component representing an initial quantum state. num_time_slices: The number of time slices, has a minimum value of 1. num_iterations: The number of iterations, has a minimum 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. quantum_instance: Quantum Instance or Backend """ 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__(quantum_instance) 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._ancilla_phase_coef = None self._in_operator = operator self._operator = None # type: Optional[WeightedPauliOperator] self._ret = {} # type: Dict[str, Any] self._pauli_list = None # type: Optional[List[List[Union[complex, Pauli]]]] self._phase_estimation_circuit = None self._slice_pauli_list = None # type: Optional[List[List[Union[complex, Pauli]]]] self._setup(operator)
def __init__(self, num_qubits: int, depth: int = 3, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', initial_state: Optional[InitialState] = None, skip_unentangled_qubits: bool = False) -> None: """Constructor. Args: num_qubits: number of qubits, has a min. value of 1. depth: number of rotation layers, has a min. value of 1. entangler_map: describe the connectivity of qubits, each list describes [source, target], or None for full entanglement. Note that the order is the list is the order of applying the two-qubit gate. entanglement: 'full' or 'linear' initial_state: an initial state object skip_unentangled_qubits: skip the qubits not in the entangler_map """ validate_min('num_qubits', num_qubits, 1) validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) super().__init__() self._num_qubits = num_qubits self._depth = depth if entangler_map is None: self._entangler_map = VariationalForm.get_entangler_map(entanglement, num_qubits) else: self._entangler_map = VariationalForm.validate_entangler_map(entangler_map, num_qubits) # determine the entangled qubits all_qubits = [] for src, targ in self._entangler_map: all_qubits.extend([src, targ]) self._entangled_qubits = sorted(list(set(all_qubits))) self._initial_state = initial_state self._skip_unentangled_qubits = skip_unentangled_qubits # for the first layer self._num_parameters = len(self._entangled_qubits) if self._skip_unentangled_qubits \ else self._num_qubits # for repeated block self._num_parameters += (len(self._entangled_qubits) + len(self._entangler_map)) * depth self._bounds = [(-np.pi, np.pi)] * self._num_parameters self._support_parameterized_circuit = True
def __init__(self, expression: str, optimization: bool = False, mct_mode: str = 'basic') -> None: """ Constructor. Args: expression: The string of the desired logical expression. It could be either in the DIMACS CNF format, or a general boolean logical expression, such as 'a ^ b' and 'v[0] & (~v[1] | v[2])' optimization: Boolean flag for attempting logical expression optimization mct_mode: The mode to use for building Multiple-Control Toffoli. Raises: AquaError: invalid input """ validate_in_set( 'mct_mode', mct_mode, {'basic', 'basic-dirty-ancilla', 'advanced', 'noancilla'}) super().__init__() self._mct_mode = mct_mode.strip().lower() self._optimization = optimization expression = re.sub('(?i)' + re.escape(' and '), ' & ', expression) expression = re.sub('(?i)' + re.escape(' xor '), ' ^ ', expression) expression = re.sub('(?i)' + re.escape(' or '), ' | ', expression) expression = re.sub('(?i)' + re.escape('not '), '~', expression) orig_expression = expression # try parsing as normal logical expression that sympy recognizes try: raw_expr = parse_expr(expression) except Exception: # pylint: disable=broad-except # try parsing as dimacs cnf try: expression = LogicalExpressionOracle._dimacs_cnf_to_expression( expression) raw_expr = parse_expr(expression) except Exception: raise AquaError( 'Failed to parse the input expression: {}.'.format( orig_expression)) self._expr = raw_expr self._process_expr() self.construct_circuit()
def __init__( self, feature_dimension: int, depth: int = 2, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', z_order: int = 2, data_map_func: Callable[[np.ndarray], float] = self_product) -> None: """ Args: feature_dimension: The number of features depth: The number of repeated circuits. Defaults to 2, has a minimum value of 1. entangler_map: Describes the connectivity of qubits, each list in the overall list describes [source, target]. Defaults to ``None`` where the map is created as per *entanglement* parameter. Note that the order in the list is the order of applying the two-qubit gate. entanglement: ('full' | 'linear'), generate the qubit connectivity by a predefined topology. Defaults to full which connects every qubit to each other. Linear connects each qubit to the next. z_order: z order, has a min. value of 1. Creates *paulis* for superclass based on the z order value, e.g. 3 would result in ['Z', 'ZZ', 'ZZZ'] where the paulis contains strings of Z up to length of *z_order* data_map_func: A mapping function for data x which can be supplied to override the default mapping from :meth:`self_product`. """ # extra warning since this class will be removed entirely warnings.warn( 'The qiskit.aqua.components.feature_maps.PauliZExpansion class is deprecated ' 'as of 0.7.0 and will be removed no sooner than 3 months after the release. ' 'You should use qiskit.circuit.library.PauliFeatureMap instead.', DeprecationWarning, stacklevel=2) validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) validate_min('z_order', z_order, 1) pauli_string = [] for i in range(1, z_order + 1): pauli_string.append('Z' * i) super().__init__(feature_dimension, depth, entangler_map, entanglement, paulis=pauli_string, data_map_func=data_map_func)
def __init__(self, operator: BaseOperator, iqft: IQFT, num_time_slices: int = 1, num_ancillae: int = 1, expansion_mode: str = 'trotter', expansion_order: int = 1, evo_time: Optional[float] = None, negative_evals: bool = False, ne_qfts: Optional[List] = None) -> None: """Constructor. Args: operator: the hamiltonian Operator object 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. evo_time: the evolution time negative_evals: indicate if negative eigenvalues need to be handled ne_qfts: the QFT and IQFT components for handling negative eigenvalues """ super().__init__() ne_qfts = ne_qfts if ne_qfts is not None else [None, None] 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) self._operator = op_converter.to_weighted_pauli_operator(operator) self._iqft = iqft self._num_ancillae = num_ancillae self._num_time_slices = num_time_slices self._expansion_mode = expansion_mode self._expansion_order = expansion_order self._evo_time = evo_time self._negative_evals = negative_evals self._ne_qfts = ne_qfts self._circuit = None self._output_register = None self._input_register = None self._init_constants()
def __init__( self, feature_dimension: int, depth: int = 2, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', paulis: Optional[List[str]] = None, data_map_func: Callable[[np.ndarray], float] = self_product) -> None: """Constructor. Args: feature_dimension: number of features depth: the number of repeated circuits. Defaults to 2, has a min. value of 1. entangler_map: describe the connectivity of qubits, each list describes [source, target], or None for full entanglement. Note that the order is the list is the order of applying the two-qubit gate. entanglement: ['full', 'linear'], generate the qubit connectivity by predefined topology. Defaults to full paulis: a list of strings for to-be-used paulis. Defaults to None. If None, ['Z', 'ZZ'] will be used. data_map_func: a mapping function for data x """ paulis = paulis if paulis is not None else ['Z', 'ZZ'] validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) super().__init__() self._num_qubits = self._feature_dimension = feature_dimension self._depth = depth if entangler_map is None: self._entangler_map = self.get_entangler_map( entanglement, feature_dimension) else: self._entangler_map = self.validate_entangler_map( entangler_map, feature_dimension) self._pauli_strings = self._build_subset_paulis_string(paulis) self._data_map_func = data_map_func self._support_parameterized_circuit = True
def __init__(self, operator: BaseOperator, initial_state: InitialState, evo_operator: BaseOperator, evo_time: int = 1, num_time_slices: int = 1, expansion_mode: str = 'trotter', expansion_order: int = 1) -> None: validate_min('evo_time', evo_time, 0) validate_min('num_time_slices', num_time_slices, 0) 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) self._initial_state = initial_state self._evo_operator = op_converter.to_weighted_pauli_operator(evo_operator) self._evo_time = evo_time self._num_time_slices = num_time_slices self._expansion_mode = expansion_mode self._expansion_order = expansion_order self._ret = {}
def __init__(self, operator: Optional[BaseOperator] = None, state_in: Optional[InitialState] = None, 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 state_in: An InitialState component representing an initial quantum state. num_time_slices: The number of time slices, has a minimum value of 1. num_iterations: The number of iterations, has a minimum 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. """ 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._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._ancilla_phase_coef = None self._in_operator = operator self._operator = None self._ret = {} self._pauli_list = None self._phase_estimation_circuit = None self._slice_pauli_list = None self._setup(operator)
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, num_orbitals: int, num_particles: Union[List[int], int], qubit_mapping: str = 'parity', two_qubit_reduction: bool = True, sq_list: Optional[List[int]] = None) -> None: """ Args: num_orbitals: 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. qubit_mapping: mapping type for qubit operator two_qubit_reduction: flag indicating whether or not two qubit is reduced sq_list: position of the single-qubit operators that anticommute with the cliffords Raises: ValueError: wrong setting in num_particles and num_orbitals. ValueError: wrong setting for computed num_qubits and supplied num_qubits. """ # validate the input validate_min('num_orbitals', num_orbitals, 1) validate_in_set('qubit_mapping', qubit_mapping, {'jordan_wigner', 'parity', 'bravyi_kitaev'}) if qubit_mapping != 'parity' and two_qubit_reduction: warnings.warn('two_qubit_reduction only works with parity qubit mapping ' 'but you have %s. We switch two_qubit_reduction ' 'to False.' % qubit_mapping) two_qubit_reduction = False super().__init__() # get the bitstring encoding the Hartree Fock state if isinstance(num_particles, list): num_particles = tuple(num_particles) # type: ignore bitstr = hartree_fock_bitstring(num_orbitals, num_particles, qubit_mapping, two_qubit_reduction, sq_list) self._bitstr = bitstr
def __init__( self, feature_dimension: int, depth: int = 2, entangler_map: Optional[List[List[int]]] = None, entanglement: str = 'full', z_order: int = 2, data_map_func: Callable[[np.ndarray], float] = self_product) -> None: """ Args: feature_dimension: The number of features depth: The number of repeated circuits. Defaults to 2, has a minimum value of 1. entangler_map: Describes the connectivity of qubits, each list in the overall list describes [source, target]. Defaults to ``None`` where the map is created as per *entanglement* parameter. Note that the order in the list is the order of applying the two-qubit gate. entanglement: ('full' | 'linear'), generate the qubit connectivity by a predefined topology. Defaults to full which connects every qubit to each other. Linear connects each qubit to the next. z_order: z order, has a min. value of 1. Creates *paulis* for superclass based on the z order value, e.g. 3 would result in ['Z', 'ZZ', 'ZZZ'] where the paulis contains strings of Z up to length of *z_order* data_map_func: A mapping function for data x which can be supplied to override the default mapping from :meth:`self_product`. """ validate_min('depth', depth, 1) validate_in_set('entanglement', entanglement, {'full', 'linear'}) validate_min('z_order', z_order, 1) pauli_string = [] for i in range(1, z_order + 1): pauli_string.append('Z' * i) super().__init__(feature_dimension, depth, entangler_map, entanglement, paulis=pauli_string, data_map_func=data_map_func)
def __init__( self, operator: LegacyBaseOperator, var_form: Union[QuantumCircuit, 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, 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[LegacyBaseOperator] = None, aux_operators: Optional[List[LegacyBaseOperator]] = None, quantum_instance: Optional[Union[QuantumInstance, Backend, BaseBackend]] = 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. 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 quantum_instance: Quantum Instance or Backend 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, quantum_instance=quantum_instance) 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)
def __init__(self, num_qubits: int, num_orbitals: int, num_particles: Union[List[int], int], qubit_mapping: str = 'parity', two_qubit_reduction: bool = True, sq_list: Optional[List[int]] = None) -> None: """Constructor. Args: num_qubits: number of qubits num_orbitals: 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. qubit_mapping: mapping type for qubit operator two_qubit_reduction: flag indicating whether or not two qubit is reduced sq_list: position of the single-qubit operators that anticommute with the cliffords Raises: ValueError: wrong setting in num_particles and num_orbitals. ValueError: wrong setting for computed num_qubits and supplied num_qubits. """ validate_min('num_orbitals', num_orbitals, 1) if isinstance(num_particles, list) and len(num_particles) != 2: raise ValueError( 'Num particles value {}. Number of values allowed is 2'.format( num_particles)) validate_in_set('qubit_mapping', qubit_mapping, {'jordan_wigner', 'parity', 'bravyi_kitaev'}) super().__init__() self._sq_list = sq_list self._qubit_tapering = bool(self._sq_list) self._qubit_mapping = qubit_mapping.lower() self._two_qubit_reduction = two_qubit_reduction if self._qubit_mapping != 'parity': if self._two_qubit_reduction: logger.warning( "two_qubit_reduction only works with parity qubit mapping " "but you have %s. We switch two_qubit_reduction " "to False.", self._qubit_mapping) self._two_qubit_reduction = False self._num_orbitals = num_orbitals if isinstance(num_particles, list): self._num_alpha = num_particles[0] self._num_beta = num_particles[1] else: logger.info( "We assume that the number of alphas and betas are the same.") self._num_alpha = num_particles // 2 self._num_beta = num_particles // 2 self._num_particles = self._num_alpha + self._num_beta if self._num_particles > self._num_orbitals: raise ValueError( "# of particles must be less than or equal to # of orbitals.") self._num_qubits = num_orbitals - 2 if self._two_qubit_reduction else self._num_orbitals self._num_qubits = self._num_qubits \ if not self._qubit_tapering else self._num_qubits - len(sq_list) if self._num_qubits != num_qubits: raise ValueError("Computed num qubits {} does not match " "actual {}".format(self._num_qubits, num_qubits)) self._bitstr = None