NLocal¶

class NLocal(num_qubits=None, rotation_blocks=None, entanglement_blocks=None, entanglement=None, reps=1, insert_barriers=False, parameter_prefix='θ', overwrite_block_parameters=True, skip_final_rotation_layer=False, skip_unentangled_qubits=False, initial_state=None, name='nlocal')[source]

The n-local circuit class.

The structure of the n-local circuit are alternating rotation and entanglement layers. In both layers, parameterized circuit-blocks act on the circuit in a defined way. In the rotation layer, the blocks are applied stacked on top of each other, while in the entanglement layer according to the entanglement strategy. The circuit blocks can have arbitrary sizes (smaller equal to the number of qubits in the circuit). Each layer is repeated reps times, and by default a final rotation layer is appended.

For instance, a rotation block on 2 qubits and an entanglement block on 4 qubits using 'linear' entanglement yields the following circuit.

┌──────┐ ░ ┌──────┐                      ░ ┌──────┐
┤0     ├─░─┤0     ├──────────────── ... ─░─┤0     ├
│  Rot │ ░ │      │┌──────┐              ░ │  Rot │
┤1     ├─░─┤1     ├┤0     ├──────── ... ─░─┤1     ├
├──────┤ ░ │  Ent ││      │┌──────┐      ░ ├──────┤
┤0     ├─░─┤2     ├┤1     ├┤0     ├ ... ─░─┤0     ├
│  Rot │ ░ │      ││  Ent ││      │      ░ │  Rot │
┤1     ├─░─┤3     ├┤2     ├┤1     ├ ... ─░─┤1     ├
├──────┤ ░ └──────┘│      ││  Ent │      ░ ├──────┤
┤0     ├─░─────────┤3     ├┤2     ├ ... ─░─┤0     ├
│  Rot │ ░         └──────┘│      │      ░ │  Rot │
┤1     ├─░─────────────────┤3     ├ ... ─░─┤1     ├
└──────┘ ░                 └──────┘      ░ └──────┘

|                                 |
+---------------------------------+
repeated reps times


If specified, barriers can be inserted in between every block. If an initial state object of Qiskit Aqua is provided, it is added in front of the NLocal.

Create a new n-local circuit.

Parameters
• num_qubits (Optional[int]) – The number of qubits of the circuit.

• rotation_blocks (Union[QuantumCircuit, List[QuantumCircuit], Instruction, List[Instruction], None]) – The blocks used in the rotation layers. If multiple are passed, these will be applied one after another (like new sub-layers).

• entanglement_blocks (Union[QuantumCircuit, List[QuantumCircuit], Instruction, List[Instruction], None]) – The blocks used in the entanglement layers. If multiple are passed, these will be applied one after another. To use different enganglements for the sub-layers, see get_entangler_map().

• entanglement (Union[List[int], List[List[int]], None]) – The indices specifying on which qubits the input blocks act. If None, the entanglement blocks are applied at the top of the circuit.

• reps (int) – Specifies how often the rotation blocks and entanglement blocks are repeated.

• insert_barriers (bool) – If True, barriers are inserted in between each layer. If False, no barriers are inserted.

• parameter_prefix (str) – The prefix used if default parameters are generated.

• overwrite_block_parameters (Union[bool, List[List[Parameter]]]) – If the parameters in the added blocks should be overwritten. If False, the parameters in the blocks are not changed.

• skip_final_rotation_layer (bool) – Whether a final rotation layer is added to the circuit.

• skip_unentangled_qubits (bool) – If True, the rotation gates act only on qubits that are entangled. If False, the rotation gates act on all qubits.

• initial_state (Optional[Any]) – A qiskit.aqua.components.initial_states.InitialState object which can be used to describe an initial state prepended to the NLocal circuit. This is primarily for compatibility with algorithms in Qiskit Aqua, which leverage this object to prepare input states.

• name (Optional[str]) – The name of the circuit.

Examples

TODO

Raises
• ImportError – If an initial_state is specified but Qiskit Aqua is not installed.

• TypeError – If an initial_state is specified but not of the correct type, qiskit.aqua.components.initial_states.InitialState.

Attributes

 NLocal.ancillas Returns a list of ancilla bits in the order that the registers were added. NLocal.clbits Returns a list of classical bits in the order that the registers were added. NLocal.data Return the circuit data (instructions and context). NLocal.entanglement Get the entanglement strategy. NLocal.entanglement_blocks The blocks in the entanglement layers. NLocal.extension_lib NLocal.global_phase Return the global phase of the circuit in radians. NLocal.header NLocal.initial_state Return the initial state that is added in front of the n-local circuit. NLocal.insert_barriers If barriers are inserted in between the layers or not. NLocal.instances NLocal.n_qubits Deprecated, use num_qubits instead. NLocal.num_ancillas Return the number of ancilla qubits. NLocal.num_clbits Return number of classical bits. NLocal.num_layers Return the number of layers in the n-local circuit. NLocal.num_parameters Convenience function to get the number of parameter objects in the circuit. NLocal.num_parameters_settable The number of total parameters that can be set to distinct values. NLocal.num_qubits Returns the number of qubits in this circuit. NLocal.ordered_parameters The parameters used in the underlying circuit. NLocal.parameter_bounds The parameter bounds for the unbound parameters in the circuit. NLocal.parameters Get the Parameter objects in the circuit. NLocal.preferred_init_points The initial points for the parameters. NLocal.prefix NLocal.qregs A list of the quantum registers associated with the circuit. NLocal.qubits Returns a list of quantum bits in the order that the registers were added. NLocal.reps The number of times rotation and entanglement block are repeated. NLocal.rotation_blocks The blocks in the rotation layers.

Methods

 NLocal.AND(qr_variables, qb_target, qr_ancillae) Build a collective conjunction (AND) circuit in place using mct. NLocal.OR(qr_variables, qb_target, qr_ancillae) Build a collective disjunction (OR) circuit in place using mct. Return indexed operation. Return number of operations in circuit. NLocal.add_layer(other[, entanglement, front]) Append another layer to the NLocal. Add registers. NLocal.append(instruction[, qargs, cargs]) Append one or more instructions to the end of the circuit, modifying the circuit in place. NLocal.assign_parameters(param_dict[, inplace]) Assign parameters to the n-local circuit. NLocal.barrier(*qargs) Apply Barrier. NLocal.bind_parameters(value_dict) Assign numeric parameters to values yielding a new circuit. NLocal.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. NLocal.ccx(control_qubit1, control_qubit2, …) Apply CCXGate. NLocal.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. NLocal.cnot(control_qubit, target_qubit, *) Apply CXGate. Append rhs to self if self contains compatible registers. NLocal.compose(other[, qubits, clbits, …]) Compose circuit with other circuit or instruction, optionally permuting wires. NLocal.control([num_ctrl_qubits, label, …]) Control this circuit on num_ctrl_qubits qubits. NLocal.copy([name]) Copy the circuit. Count each operation kind in the circuit. NLocal.cp(theta, control_qubit, target_qubit) Apply CPhaseGate. NLocal.crx(theta, control_qubit, target_qubit, *) Apply CRXGate. NLocal.cry(theta, control_qubit, target_qubit, *) Apply CRYGate. NLocal.crz(theta, control_qubit, target_qubit, *) Apply CRZGate. NLocal.cswap(control_qubit, target_qubit1, …) Apply CSwapGate. NLocal.csx(control_qubit, target_qubit[, …]) Apply CSXGate. NLocal.cu(theta, phi, lam, gamma, …[, …]) Apply CUGate. NLocal.cu1(theta, control_qubit, target_qubit, *) Apply CU1Gate. NLocal.cu3(theta, phi, lam, control_qubit, …) Apply CU3Gate. NLocal.cx(control_qubit, target_qubit, *[, …]) Apply CXGate. NLocal.cy(control_qubit, target_qubit, *[, …]) Apply CYGate. NLocal.cz(control_qubit, target_qubit, *[, …]) Apply CZGate. NLocal.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). NLocal.diag_gate(diag, qubit) Deprecated version of QuantumCircuit.diagonal. NLocal.diagonal(diag, qubit) Attach a diagonal gate to a circuit. NLocal.draw([output, scale, filename, …]) Draw the quantum circuit. Append QuantumCircuit to the right hand side if it contains compatible registers. NLocal.fredkin(control_qubit, target_qubit1, …) Apply CSwapGate. Take in a QASM file and generate a QuantumCircuit object. NLocal.from_qasm_str(qasm_str) Take in a QASM string and generate a QuantumCircuit object. NLocal.get_entangler_map(rep_num, block_num, …) Get the entangler map for in the repetition rep_num and the block block_num. Get the indices of unentangled qubits in a set. NLocal.h(qubit, *[, q]) Apply HGate. NLocal.hamiltonian(operator, time, qubits[, …]) Apply hamiltonian evolution to to qubits. NLocal.has_register(register) Test if this circuit has the register r. NLocal.i(qubit, *[, q]) Apply IGate. NLocal.id(qubit, *[, q]) Apply IGate. NLocal.iden(qubit, *[, q]) Deprecated identity gate. NLocal.initialize(params, qubits) Apply initialize to circuit. Invert (take adjoint of) this circuit. NLocal.iso(isometry, q_input, …[, …]) Attach an arbitrary isometry from m to n qubits to a circuit. NLocal.isometry(isometry, q_input, …[, …]) Attach an arbitrary isometry from m to n qubits to a circuit. NLocal.iswap(qubit1, qubit2) Apply iSwapGate. NLocal.mcmt(gate, control_qubits, target_qubits) Apply a multi-control, multi-target using a generic gate. NLocal.mcrx(theta, q_controls, q_target[, …]) Apply Multiple-Controlled X rotation gate NLocal.mcry(theta, q_controls, q_target, …) Apply Multiple-Controlled Y rotation gate NLocal.mcrz(lam, q_controls, q_target[, …]) Apply Multiple-Controlled Z rotation gate NLocal.mct(control_qubits, target_qubit[, …]) Apply MCXGate. NLocal.mcu1(lam, control_qubits, target_qubit) Apply MCU1Gate. NLocal.mcx(control_qubits, target_qubit[, …]) Apply MCXGate. NLocal.measure(qubit, cbit) Measure quantum bit into classical bit (tuples). NLocal.measure_active([inplace]) Adds measurement to all non-idle qubits. NLocal.measure_all([inplace]) Adds measurement to all qubits. DEPRECATED: use circuit.reverse_ops(). NLocal.ms(theta, qubits) Apply MSGate. NLocal.num_connected_components([unitary_only]) 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. NLocal.p(theta, qubit) Apply PhaseGate. NLocal.power(power[, matrix_power]) Raise this circuit to the power of power. Returns information about the setting. NLocal.qasm([formatted, filename]) Return OpenQASM string. Converts several qubit representations (such as indexes, range, etc.) into a list of qubits. NLocal.r(theta, phi, qubit, *[, q]) Apply RGate. NLocal.rcccx(control_qubit1, control_qubit2, …) Apply RC3XGate. NLocal.rccx(control_qubit1, control_qubit2, …) Apply RCCXGate. NLocal.remove_final_measurements([inplace]) Removes final measurement on all qubits if they are present. NLocal.repeat(reps) Repeat this circuit reps times. NLocal.reset(qubit) Reset q. Return a circuit with the opposite order of wires. Reverse the circuit by reversing the order of instructions. NLocal.rx(theta, qubit, *[, label, q]) Apply RXGate. NLocal.rxx(theta, qubit1, qubit2) Apply RXXGate. NLocal.ry(theta, qubit, *[, label, q]) Apply RYGate. NLocal.ryy(theta, qubit1, qubit2) Apply RYYGate. NLocal.rz(phi, qubit, *[, q]) Apply RZGate. NLocal.rzx(theta, qubit1, qubit2) Apply RZXGate. NLocal.rzz(theta, qubit1, qubit2) Apply RZZGate. NLocal.s(qubit, *[, q]) Apply SGate. NLocal.sdg(qubit, *[, q]) Apply SdgGate. Returns total number of gate operations in circuit. NLocal.snapshot(label[, snapshot_type, …]) Take a statevector snapshot of the internal simulator representation. NLocal.snapshot_density_matrix(label[, qubits]) Take a density matrix snapshot of simulator state. NLocal.snapshot_expectation_value(label, op, …) Take a snapshot of expectation value of an Operator. NLocal.snapshot_probabilities(label, qubits) Take a probability snapshot of the simulator state. Take a stabilizer snapshot of the simulator state. Take a statevector snapshot of the simulator state. NLocal.squ(unitary_matrix, qubit[, mode, …]) Decompose an arbitrary 2*2 unitary into three rotation gates. NLocal.swap(qubit1, qubit2) Apply SwapGate. NLocal.sx(qubit) Apply SXGate. NLocal.sxdg(qubit) Apply SXdgGate. NLocal.t(qubit, *[, q]) Apply TGate. NLocal.tdg(qubit, *[, q]) Apply TdgGate. NLocal.to_gate([parameter_map, label]) Create a Gate out of this circuit. NLocal.to_instruction([parameter_map]) Create an Instruction out of this circuit. NLocal.toffoli(control_qubit1, …[, ctl1, …]) Apply CCXGate. NLocal.u(theta, phi, lam, qubit) Apply UGate. NLocal.u1(theta, qubit, *[, q]) Apply U1Gate. NLocal.u2(phi, lam, qubit, *[, q]) Apply U2Gate. NLocal.u3(theta, phi, lam, qubit, *[, q]) Apply U3Gate. NLocal.uc(gate_list, q_controls, q_target[, …]) Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. NLocal.ucg(angle_list, q_controls, q_target) Deprecated version of uc. NLocal.ucrx(angle_list, q_controls, q_target) Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit. NLocal.ucry(angle_list, q_controls, q_target) Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit. NLocal.ucrz(angle_list, q_controls, q_target) Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit. NLocal.ucx(angle_list, q_controls, q_target) Deprecated version of ucrx. NLocal.ucy(angle_list, q_controls, q_target) Deprecated version of ucry. NLocal.ucz(angle_list, q_controls, q_target) Deprecated version of ucrz. NLocal.unitary(obj, qubits[, label]) Apply unitary gate to q. Return number of qubits plus clbits in circuit. NLocal.x(qubit, *[, label, ctrl_state, q]) Apply XGate. NLocal.y(qubit, *[, q]) Apply YGate. NLocal.z(qubit, *[, q]) Apply ZGate. Return indexed operation. Return number of operations in circuit.