A circuit to compute the weighted sum of qubit registers.

Given $$n$$ qubit basis states $$q_0, \ldots, q_{n-1} \in \{0, 1\}$$ and non-negative integer weights $$\lambda_0, \ldots, \lambda_{n-1}$$, this circuit performs the operation

$|q_0 \ldots q_{n-1}\rangle |0\rangle_s \mapsto |q_0 \ldots q_{n-1}\rangle |\sum_{j=0}^{n-1} \lambda_j q_j\rangle_s$

where $$s$$ is the number of sum qubits required. This can be computed as

$s = 1 + \left\lfloor \log_2\left( \sum_{j=0}^{n-1} \lambda_j \right) \right\rfloor$

or $$s = 1$$ if the sum of the weights is 0 (then the expression in the logarithm is invalid).

For qubits in a circuit diagram, the first weight applies to the upper-most qubit. For an example where the state of 4 qubits is added into a sum register, the circuit can be schematically drawn as

           ┌────────┐
state_0: ┤0       ├ | state_0 * weights[0]
│        │ |
state_1: ┤1       ├ | + state_1 * weights[1]
│        │ |
state_2: ┤2       ├ | + state_2 * weights[2]
│        │ |
state_3: ┤3       ├ | + state_3 * weights[3]
│        │
sum_0: ┤4       ├ |
sum_1: ┤5       ├ | = sum_0 * 2^0 + sum_1 * 2^1 + sum_2 * 2^2
│        │ |
sum_2: ┤6       ├ |
│        │
carry_0: ┤7       ├
│        │
carry_1: ┤8       ├
│        │
control_0: ┤9       ├
└────────┘


Computes the weighted sum controlled by state qubits.

Parameters
• num_state_qubits (Optional[int]) – The number of state qubits.

• weights (Optional[List[int]]) – List of weights, one for each state qubit. If none are provided they default to 1 for every qubit.

• name (str) – The name of the circuit.

Attributes

 WeightedAdder.clbits Returns a list of classical bits in the order that the registers were added. WeightedAdder.data Return the circuit data (instructions and context). WeightedAdder.extension_lib WeightedAdder.header WeightedAdder.instances WeightedAdder.n_qubits Deprecated, use num_qubits instead. WeightedAdder.num_ancilla_qubits The number of ancilla qubits required to implement the weighted sum. WeightedAdder.num_carry_qubits The number of carry qubits required to compute the sum. WeightedAdder.num_clbits Return number of classical bits. WeightedAdder.num_control_qubits The number of additional control qubits required. WeightedAdder.num_parameters Convenience function to get the number of parameter objects in the circuit. WeightedAdder.num_qubits Return number of qubits. WeightedAdder.num_state_qubits The number of qubits to be summed. WeightedAdder.num_sum_qubits The number of sum qubits in the circuit. WeightedAdder.parameters Convenience function to get the parameters defined in the parameter table. WeightedAdder.prefix WeightedAdder.qregs A list of the quantum registers associated with the circuit. WeightedAdder.qubits Returns a list of quantum bits in the order that the registers were added. WeightedAdder.weights The weights for the qubit states.

Methods

 WeightedAdder.AND(qr_variables, qb_target, …) Build a collective conjunction (AND) circuit in place using mct. WeightedAdder.OR(qr_variables, qb_target, …) Build a collective disjunction (OR) circuit in place using mct. Return indexed operation. Return number of operations in circuit. Add registers. WeightedAdder.append(instruction[, qargs, cargs]) Append one or more instructions to the end of the circuit, modifying the circuit in place. WeightedAdder.assign_parameters(param_dict) Assign parameters to new parameters or values. WeightedAdder.barrier(*qargs) Apply Barrier. WeightedAdder.bind_parameters(value_dict) Assign numeric parameters to values yielding a new circuit. WeightedAdder.cast(value, _type) Best effort to cast value to type. Converts several classical bit representations (such as indexes, range, etc.) into a list of classical bits. WeightedAdder.ccx(control_qubit1, …[, …]) Apply CCXGate. WeightedAdder.ch(control_qubit, target_qubit, *) Apply CHGate. Return the current number of instances of this class, useful for auto naming. Return the prefix to use for auto naming. WeightedAdder.cnot(control_qubit, …[, …]) Apply CXGate. Append rhs to self if self contains compatible registers. WeightedAdder.compose(other[, qubits, …]) Compose circuit with other circuit or instruction, optionally permuting wires. WeightedAdder.copy([name]) Copy the circuit. Count each operation kind in the circuit. WeightedAdder.crx(theta, control_qubit, …) Apply CRXGate. WeightedAdder.cry(theta, control_qubit, …) Apply CRYGate. WeightedAdder.crz(theta, control_qubit, …) Apply CRZGate. WeightedAdder.cswap(control_qubit, …[, …]) Apply CSwapGate. WeightedAdder.cu1(theta, control_qubit, …) Apply CU1Gate. WeightedAdder.cu3(theta, phi, lam, …[, …]) Apply CU3Gate. WeightedAdder.cx(control_qubit, target_qubit, *) Apply CXGate. WeightedAdder.cy(control_qubit, target_qubit, *) Apply CYGate. WeightedAdder.cz(control_qubit, target_qubit, *) Apply CZGate. WeightedAdder.dcx(qubit1, qubit2) Apply DCXGate. Call a decomposition pass on this circuit, to decompose one level (shallow decompose). Return circuit depth (i.e., length of critical path). WeightedAdder.diag_gate(diag, qubit) Deprecated version of QuantumCircuit.diagonal. WeightedAdder.diagonal(diag, qubit) Attach a diagonal gate to a circuit. WeightedAdder.draw([output, scale, …]) Draw the quantum circuit. Append QuantumCircuit to the right hand side if it contains compatible registers. WeightedAdder.fredkin(control_qubit, …[, …]) Apply CSwapGate. Take in a QASM file and generate a QuantumCircuit object. WeightedAdder.from_qasm_str(qasm_str) Take in a QASM string and generate a QuantumCircuit object. WeightedAdder.h(qubit, *[, q]) Apply HGate. WeightedAdder.hamiltonian(operator, time, qubits) Apply hamiltonian evolution to to qubits. WeightedAdder.has_register(register) Test if this circuit has the register r. WeightedAdder.i(qubit, *[, q]) Apply IGate. WeightedAdder.id(qubit, *[, q]) Apply IGate. WeightedAdder.iden(qubit, *[, q]) Deprecated identity gate. WeightedAdder.initialize(params, qubits) Apply initialize to circuit. Invert this circuit. WeightedAdder.iso(isometry, q_input, …[, …]) Attach an arbitrary isometry from m to n qubits to a circuit. WeightedAdder.isometry(isometry, q_input, …) Attach an arbitrary isometry from m to n qubits to a circuit. WeightedAdder.iswap(qubit1, qubit2) Apply iSwapGate. WeightedAdder.mcmt(gate, control_qubits, …) Apply a multi-control, multi-target using a generic gate. WeightedAdder.mcrx(theta, q_controls, q_target) Apply Multiple-Controlled X rotation gate WeightedAdder.mcry(theta, q_controls, …[, …]) Apply Multiple-Controlled Y rotation gate WeightedAdder.mcrz(lam, q_controls, q_target) Apply Multiple-Controlled Z rotation gate WeightedAdder.mct(control_qubits, target_qubit) Apply MCXGate. WeightedAdder.mcu1(lam, control_qubits, …) Apply MCU1Gate. WeightedAdder.mcx(control_qubits, target_qubit) Apply MCXGate. WeightedAdder.measure(qubit, cbit) Measure quantum bit into classical bit (tuples). WeightedAdder.measure_active([inplace]) Adds measurement to all non-idle qubits. WeightedAdder.measure_all([inplace]) Adds measurement to all qubits. Mirror the circuit by reversing the instructions. WeightedAdder.ms(theta, qubits) Apply MSGate. How many non-entangled subcircuits can the circuit be factored to. Return number of non-local gates (i.e. Computes the number of tensor factors in the unitary (quantum) part of the circuit only. Computes the number of tensor factors in the unitary (quantum) part of the circuit only. WeightedAdder.qasm([formatted, filename]) Return OpenQASM string. Converts several qubit representations (such as indexes, range, etc.) into a list of qubits. WeightedAdder.r(theta, phi, qubit, *[, q]) Apply RGate. WeightedAdder.rcccx(control_qubit1, …) Apply RC3XGate. WeightedAdder.rccx(control_qubit1, …) Apply RCCXGate. Removes final measurement on all qubits if they are present. Reset q. WeightedAdder.rx(theta, qubit, *[, label, q]) Apply RXGate. WeightedAdder.rxx(theta, qubit1, qubit2) Apply RXXGate. WeightedAdder.ry(theta, qubit, *[, label, q]) Apply RYGate. WeightedAdder.ryy(theta, qubit1, qubit2) Apply RYYGate. WeightedAdder.rz(phi, qubit, *[, q]) Apply RZGate. WeightedAdder.rzx(theta, qubit1, qubit2) Apply RZXGate. WeightedAdder.rzz(theta, qubit1, qubit2) Apply RZZGate. WeightedAdder.s(qubit, *[, q]) Apply SGate. WeightedAdder.sdg(qubit, *[, q]) Apply SdgGate. Returns total number of gate operations in circuit. WeightedAdder.snapshot(label[, …]) Take a statevector snapshot of the internal simulator representation. Take a density matrix snapshot of simulator state. Take a snapshot of expectation value of an Operator. Take a probability snapshot of the simulator state. Take a stabilizer snapshot of the simulator state. Take a statevector snapshot of the simulator state. WeightedAdder.squ(unitary_matrix, qubit[, …]) Decompose an arbitrary 2*2 unitary into three rotation gates. WeightedAdder.swap(qubit1, qubit2) Apply SwapGate. WeightedAdder.t(qubit, *[, q]) Apply TGate. WeightedAdder.tdg(qubit, *[, q]) Apply TdgGate. WeightedAdder.to_gate([parameter_map]) Create a Gate out of this circuit. WeightedAdder.to_instruction([parameter_map]) Create an Instruction out of this circuit. WeightedAdder.toffoli(control_qubit1, …[, …]) Apply CCXGate. WeightedAdder.u1(theta, qubit, *[, q]) Apply U1Gate. WeightedAdder.u2(phi, lam, qubit, *[, q]) Apply U2Gate. WeightedAdder.u3(theta, phi, lam, qubit, *) Apply U3Gate. WeightedAdder.uc(gate_list, q_controls, q_target) Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. WeightedAdder.ucg(angle_list, q_controls, …) Deprecated version of uc. WeightedAdder.ucrx(angle_list, q_controls, …) Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit. WeightedAdder.ucry(angle_list, q_controls, …) Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit. WeightedAdder.ucrz(angle_list, q_controls, …) Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit. WeightedAdder.ucx(angle_list, q_controls, …) Deprecated version of ucrx. WeightedAdder.ucy(angle_list, q_controls, …) Deprecated version of ucry. WeightedAdder.ucz(angle_list, q_controls, …) Deprecated version of ucrz. WeightedAdder.unitary(obj, qubits[, label]) Apply unitary gate to q. Return number of qubits plus clbits in circuit. WeightedAdder.x(qubit, *[, label, ctrl_state, q]) Apply XGate. WeightedAdder.y(qubit, *[, q]) Apply YGate. WeightedAdder.z(qubit, *[, q]) Apply ZGate. Return indexed operation. Return number of operations in circuit.