# IntegerComparator¶

class IntegerComparator(num_state_qubits=None, value=None, geq=True, name='cmp')[source]

Integer Comparator.

Operator compares basis states $$|i\rangle_n$$ against a classically given integer $$L$$ of fixed value and flips a target qubit if $$i \geq L$$ (or $$<$$ depending on the parameter geq):

$|i\rangle_n |0\rangle \mapsto |i\rangle_n |i \geq L\rangle$

This operation is based on two’s complement implementation of binary subtraction but only uses carry bits and no actual result bits. If the most significant carry bit (the results bit) is 1, the $$\geq$$ condition is True otherwise it is False.

Create a new fixed value comparator circuit.

Parameters
• num_state_qubits (Optional[int]) – Number of state qubits. If this is set it will determine the number of qubits required for the circuit.

• value (Optional[int]) – The fixed value to compare with.

• geq (bool) – If True, evaluate a >= condition, else <.

• name (str) – Name of the circuit.

Attributes

 IntegerComparator.ancillas Returns a list of ancilla bits in the order that the registers were added. IntegerComparator.calibrations Return calibration dictionary. IntegerComparator.clbits Returns a list of classical bits in the order that the registers were added. IntegerComparator.data Return the circuit data (instructions and context). IntegerComparator.extension_lib IntegerComparator.geq Return whether the comparator compares greater or less equal. IntegerComparator.global_phase Return the global phase of the circuit in radians. IntegerComparator.header IntegerComparator.instances IntegerComparator.num_ancilla_qubits Deprecated. IntegerComparator.num_ancillas Return the number of ancilla qubits. IntegerComparator.num_clbits Return number of classical bits. IntegerComparator.num_parameters Convenience function to get the number of parameter objects in the circuit. IntegerComparator.num_qubits Return number of qubits. IntegerComparator.num_state_qubits The number of qubits encoding the state for the comparison. IntegerComparator.parameters Convenience function to get the parameters defined in the parameter table. IntegerComparator.prefix IntegerComparator.qregs A list of the quantum registers associated with the circuit. IntegerComparator.qubits Returns a list of quantum bits in the order that the registers were added. IntegerComparator.value The value to compare the qubit register to.

Methods

 Return indexed operation. Return number of operations in circuit. Register a low-level, custom pulse definition for the given gate. Add registers. IntegerComparator.append(instruction[, …]) Append one or more instructions to the end of the circuit, modifying the circuit in place. IntegerComparator.assign_parameters(param_dict) Assign parameters to new parameters or values. Apply Barrier. IntegerComparator.bind_parameters(value_dict) Assign numeric parameters to values yielding a new circuit. IntegerComparator.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. IntegerComparator.ccx(control_qubit1, …) Apply CCXGate. IntegerComparator.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. IntegerComparator.cnot(control_qubit, …[, …]) Apply CXGate. Append rhs to self if self contains compatible registers. IntegerComparator.compose(other[, qubits, …]) Compose circuit with other circuit or instruction, optionally permuting wires. IntegerComparator.control([num_ctrl_qubits, …]) Control this circuit on num_ctrl_qubits qubits. IntegerComparator.copy([name]) Copy the circuit. Count each operation kind in the circuit. IntegerComparator.cp(theta, control_qubit, …) Apply CPhaseGate. IntegerComparator.crx(theta, control_qubit, …) Apply CRXGate. IntegerComparator.cry(theta, control_qubit, …) Apply CRYGate. IntegerComparator.crz(theta, control_qubit, …) Apply CRZGate. IntegerComparator.cswap(control_qubit, …) Apply CSwapGate. IntegerComparator.csx(control_qubit, …[, …]) Apply CSXGate. IntegerComparator.cu(theta, phi, lam, gamma, …) Apply CUGate. IntegerComparator.cu1(theta, control_qubit, …) Apply CU1Gate. IntegerComparator.cu3(theta, phi, lam, …) Apply CU3Gate. IntegerComparator.cx(control_qubit, target_qubit) Apply CXGate. IntegerComparator.cy(control_qubit, target_qubit) Apply CYGate. IntegerComparator.cz(control_qubit, target_qubit) Apply CZGate. IntegerComparator.dcx(qubit1, qubit2) Apply DCXGate. Call a decomposition pass on this circuit, to decompose one level (shallow decompose). IntegerComparator.delay(duration[, qarg, unit]) Apply Delay. Return circuit depth (i.e., length of critical path). IntegerComparator.diag_gate(diag, qubit) Deprecated version of QuantumCircuit.diagonal. IntegerComparator.diagonal(diag, qubit) Attach a diagonal gate to a circuit. IntegerComparator.draw([output, scale, …]) Draw the quantum circuit. Append QuantumCircuit to the right hand side if it contains compatible registers. IntegerComparator.fredkin(control_qubit, …) Apply CSwapGate. Take in a QASM file and generate a QuantumCircuit object. Take in a QASM string and generate a QuantumCircuit object. Apply HGate. IntegerComparator.hamiltonian(operator, …) Apply hamiltonian evolution to to qubits. IntegerComparator.has_register(register) Test if this circuit has the register r. Apply IGate. Apply IGate. IntegerComparator.initialize(params, qubits) Apply initialize to circuit. Invert (take adjoint of) this circuit. IntegerComparator.iso(isometry, q_input, …) Attach an arbitrary isometry from m to n qubits to a circuit. IntegerComparator.isometry(isometry, …[, …]) Attach an arbitrary isometry from m to n qubits to a circuit. IntegerComparator.iswap(qubit1, qubit2) Apply iSwapGate. IntegerComparator.mcmt(gate, control_qubits, …) Apply a multi-control, multi-target using a generic gate. IntegerComparator.mcp(lam, control_qubits, …) Apply MCPhaseGate. IntegerComparator.mcrx(theta, q_controls, …) Apply Multiple-Controlled X rotation gate IntegerComparator.mcry(theta, q_controls, …) Apply Multiple-Controlled Y rotation gate IntegerComparator.mcrz(lam, q_controls, q_target) Apply Multiple-Controlled Z rotation gate IntegerComparator.mct(control_qubits, …[, …]) Apply MCXGate. IntegerComparator.mcu1(lam, control_qubits, …) Apply MCU1Gate. IntegerComparator.mcx(control_qubits, …[, …]) Apply MCXGate. IntegerComparator.measure(qubit, cbit) Measure quantum bit into classical bit (tuples). IntegerComparator.measure_active([inplace]) Adds measurement to all non-idle qubits. IntegerComparator.measure_all([inplace]) Adds measurement to all qubits. DEPRECATED: use circuit.reverse_ops(). IntegerComparator.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. IntegerComparator.p(theta, qubit) Apply PhaseGate. IntegerComparator.power(power[, matrix_power]) Raise this circuit to the power of power. IntegerComparator.qasm([formatted, filename]) Return OpenQASM string. Converts several qubit representations (such as indexes, range, etc.) into a list of qubits. Return the duration between the start and stop time of the first and last instructions, excluding delays, over the supplied qubits. Return the start time of the first instruction, excluding delays, over the supplied qubits. Return the stop time of the last instruction, excluding delays, over the supplied qubits. IntegerComparator.r(theta, phi, qubit) Apply RGate. IntegerComparator.rcccx(control_qubit1, …) Apply RC3XGate. IntegerComparator.rccx(control_qubit1, …) Apply RCCXGate. Removes final measurement on all qubits if they are present. Repeat this circuit reps times. Reset q. Return a circuit with the opposite order of wires. Reverse the circuit by reversing the order of instructions. IntegerComparator.rx(theta, qubit[, label]) Apply RXGate. IntegerComparator.rxx(theta, qubit1, qubit2) Apply RXXGate. IntegerComparator.ry(theta, qubit[, label]) Apply RYGate. IntegerComparator.ryy(theta, qubit1, qubit2) Apply RYYGate. IntegerComparator.rz(phi, qubit) Apply RZGate. IntegerComparator.rzx(theta, qubit1, qubit2) Apply RZXGate. IntegerComparator.rzz(theta, qubit1, qubit2) Apply RZZGate. Apply SGate. Apply SdgGate. Returns total number of gate operations in circuit. IntegerComparator.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. IntegerComparator.squ(unitary_matrix, qubit) Decompose an arbitrary 2*2 unitary into three rotation gates. IntegerComparator.swap(qubit1, qubit2) Apply SwapGate. Apply SXGate. Apply SXdgGate. Apply TGate. Apply TdgGate. IntegerComparator.to_gate([parameter_map, label]) Create a Gate out of this circuit. IntegerComparator.to_instruction([parameter_map]) Create an Instruction out of this circuit. IntegerComparator.toffoli(control_qubit1, …) Apply CCXGate. IntegerComparator.u(theta, phi, lam, qubit) Apply UGate. IntegerComparator.u1(theta, qubit) Apply U1Gate. IntegerComparator.u2(phi, lam, qubit) Apply U2Gate. IntegerComparator.u3(theta, phi, lam, qubit) Apply U3Gate. IntegerComparator.uc(gate_list, q_controls, …) Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. IntegerComparator.ucrx(angle_list, …) Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit. IntegerComparator.ucry(angle_list, …) Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit. IntegerComparator.ucrz(angle_list, …) Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit. IntegerComparator.unitary(obj, qubits[, label]) Apply unitary gate to q. Return number of qubits plus clbits in circuit. IntegerComparator.x(qubit[, label]) Apply XGate. Apply YGate. Apply ZGate. Return indexed operation. Return number of operations in circuit.