English
Languages
English
Japanese
German
Korean
Portuguese, Brazilian
French
Shortcuts

qiskit.aqua.circuits.WeightedSumOperator

class WeightedSumOperator(num_state_qubits, weights, i_state=None, i_sum=None)[source]

Adds q^T * w to separate register for non-negative integer weights w.

Computes the weighted sum controlled by state qubits

Parameters
  • num_state_qubits (int) – number of state qubits

  • weights (Union(list, numpy.ndarray)) – weights per state qubits

  • i_state (Optional(Union(list, numpy.ndarray))) – indices of state qubits, set to range(num_state_qubits) if None

  • i_sum (Optional(int)) – indices of target qubits (that represent the resulting sum), set to range(num_state_qubits, num_state_qubits + req_num_sum_qubits) if None

Raises

AquaError – invalid input

__init__(num_state_qubits, weights, i_state=None, i_sum=None)[source]

Computes the weighted sum controlled by state qubits

Parameters
  • num_state_qubits (int) – number of state qubits

  • weights (Union(list, numpy.ndarray)) – weights per state qubits

  • i_state (Optional(Union(list, numpy.ndarray))) – indices of state qubits, set to range(num_state_qubits) if None

  • i_sum (Optional(int)) – indices of target qubits (that represent the resulting sum), set to range(num_state_qubits, num_state_qubits + req_num_sum_qubits) if None

Raises

AquaError – invalid input

Methods

__init__(num_state_qubits, weights[, …])

Computes the weighted sum controlled by state qubits

build(qc, q[, q_ancillas, params])

Adds corresponding sub-circuit to given circuit

build_controlled(qc, q, q_control[, …])

Adds corresponding controlled sub-circuit to given circuit

build_controlled_inverse(qc, q, q_control[, …])

Adds controlled inverse of corresponding sub-circuit to given circuit

build_controlled_inverse_power(qc, q, …[, …])

Adds controlled, inverse, power of corresponding circuit.

build_controlled_power(qc, q, q_control, power)

Adds controlled power of corresponding circuit.

build_inverse(qc, q[, q_ancillas])

Adds inverse of corresponding sub-circuit to given circuit

build_inverse_power(qc, q, power[, q_ancillas])

Adds inverse power of corresponding circuit.

build_power(qc, q, power[, q_ancillas])

Adds power of corresponding circuit.

get_num_qubits()

returns number of qubits

get_num_qubits_controlled()

returns number of qubits controlled

get_required_sum_qubits(weights)

get required sum qubits

required_ancillas()

required ancillas

required_ancillas_controlled()

returns required ancillas controlled

Attributes

num_carry_qubits

returns num carry qubits

num_state_qubits

returns num state qubits

num_sum_qubits

returns num sum qubits

num_target_qubits

Returns the number of target qubits

weights

returns weights

build(qc, q, q_ancillas=None, params=None)[source]

Adds corresponding sub-circuit to given circuit

Parameters
  • qc (QuantumCircuit) – quantum circuit

  • q (list) – list of qubits (has to be same length as self._num_qubits)

  • q_ancillas (list) – list of ancilla qubits (or None if none needed)

  • params (list) – parameters for circuit

build_controlled(qc, q, q_control, q_ancillas=None, use_basis_gates=True)

Adds corresponding controlled sub-circuit to given circuit

Parameters
  • qc (QuantumCircuit) – quantum circuit

  • q (list) – list of qubits (has to be same length as self._num_qubits)

  • q_control (Qubit) – control qubit

  • q_ancillas (list) – list of ancilla qubits (or None if none needed)

  • use_basis_gates (bool) – use basis gates for expansion of controlled circuit

build_controlled_inverse(qc, q, q_control, q_ancillas=None, use_basis_gates=True)

Adds controlled inverse of corresponding sub-circuit to given circuit

Parameters
  • qc (QuantumCircuit) – quantum circuit

  • q (list) – list of qubits (has to be same length as self._num_qubits)

  • q_control (Qubit) – control qubit

  • q_ancillas (list) – list of ancilla qubits (or None if none needed)

  • use_basis_gates (bool) – use basis gates for expansion of controlled circuit

build_controlled_inverse_power(qc, q, q_control, power, q_ancillas=None, use_basis_gates=True)

Adds controlled, inverse, power of corresponding circuit. May be overridden if a more efficient implementation is possible

build_controlled_power(qc, q, q_control, power, q_ancillas=None, use_basis_gates=True)

Adds controlled power of corresponding circuit. May be overridden if a more efficient implementation is possible

build_inverse(qc, q, q_ancillas=None)

Adds inverse of corresponding sub-circuit to given circuit

Parameters
  • qc (QuantumCircuit) – quantum circuit

  • q (list) – list of qubits (has to be same length as self._num_qubits)

  • q_ancillas (list) – list of ancilla qubits (or None if none needed)

build_inverse_power(qc, q, power, q_ancillas=None)

Adds inverse power of corresponding circuit. May be overridden if a more efficient implementation is possible

build_power(qc, q, power, q_ancillas=None)

Adds power of corresponding circuit. May be overridden if a more efficient implementation is possible

get_num_qubits()

returns number of qubits

get_num_qubits_controlled()

returns number of qubits controlled

static get_required_sum_qubits(weights)[source]

get required sum qubits

property num_carry_qubits

returns num carry qubits

property num_state_qubits

returns num state qubits

property num_sum_qubits

returns num sum qubits

property num_target_qubits

Returns the number of target qubits

required_ancillas()[source]

required ancillas

required_ancillas_controlled()[source]

returns required ancillas controlled

property weights

returns weights