ExcitationPreserving

class ExcitationPreserving(num_qubits=None, mode='iswap', entanglement='full', reps=3, skip_unentangled_qubits=False, skip_final_rotation_layer=False, parameter_prefix='θ', insert_barriers=False, initial_state=None)[source]

The heurisitic excitation-preserving wave function ansatz.

The ExcitationPreserving circuit preserves the ratio of \(|00\rangle\), \(|01\rangle + |10\rangle\) and \(|11\rangle\) states. The matrix representing the operation is

\[ \begin{align}\begin{aligned}\newcommand{\th}{\theta/2}\\\begin{split}\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos(\th) & -\sin(\th) & 0 \\ 0 & \sin(\th) & \cos(\th) & 0 \\ 0 & 0 & 0 & e^{-i\phi} \end{pmatrix}\end{split}\end{aligned}\end{align} \]

for the mode 'fsim' or with \(e^{-i\phi} = 1\) for the mode 'iswap'.

Note that other wave functions, such as UCC-ansatzes, are also excitation preserving. However these can become complex quickly, while this heuristically motivated circuit follows a simpler pattern.

This trial wave function consists of layers of \(Z\) rotations with 2-qubit entanglements. The entangling is creating using \(XX+YY\) rotations and optionally a controlled-phase gate for the mode 'fsim'.

See RealAmplitudes for more detail on the possible arguments and options such as skipping unentanglement qubits, which apply here too.

The rotations of the ExcitationPreserving ansatz can be written as

Examples

>>> ansatz = ExcitationPreserving(3, reps=1, insert_barriers=True, entanglement='linear')
>>> print(ansatz)  # show the circuit
     ┌──────────┐ ░ ┌────────────┐┌────────────┐                             ░ ┌──────────┐
q_0: ┤ RZ(θ[0]) ├─░─┤0           ├┤0           ├─────────────────────────────░─┤ RZ(θ[5]) ├
     ├──────────┤ ░ │  RXX(θ[3]) ││  RYY(θ[3]) │┌────────────┐┌────────────┐ ░ ├──────────┤
q_1: ┤ RZ(θ[1]) ├─░─┤1           ├┤1           ├┤0           ├┤0           ├─░─┤ RZ(θ[6]) ├
     ├──────────┤ ░ └────────────┘└────────────┘│  RXX(θ[4]) ││  RYY(θ[4]) │ ░ ├──────────┤
q_2: ┤ RZ(θ[2]) ├─░─────────────────────────────┤1           ├┤1           ├─░─┤ RZ(θ[7]) ├
     └──────────┘ ░                             └────────────┘└────────────┘ ░ └──────────┘
>>> ansatz = ExcitationPreserving(2, reps=1)
>>> qc = QuantumCircuit(2)  # create a circuit and append the RY variational form
>>> qc.cry(0.2, 0, 1)  # do some previous operation
>>> qc.compose(ansatz, inplace=True)  # add the swaprz
>>> qc.draw()
                ┌──────────┐┌────────────┐┌────────────┐┌──────────┐
q_0: ─────■─────┤ RZ(θ[0]) ├┤0           ├┤0           ├┤ RZ(θ[3]) ├
     ┌────┴────┐├──────────┤│  RXX(θ[2]) ││  RYY(θ[2]) │├──────────┤
q_1: ┤ RY(0.2) ├┤ RZ(θ[1]) ├┤1           ├┤1           ├┤ RZ(θ[4]) ├
     └─────────┘└──────────┘└────────────┘└────────────┘└──────────┘
>>> ansatz = ExcitationPreserving(3, reps=1, mode='fsim', entanglement=[[0,2]],
... insert_barriers=True)
>>> print(ansatz)
     ┌──────────┐ ░ ┌────────────┐┌────────────┐        ░ ┌──────────┐
q_0: ┤ RZ(θ[0]) ├─░─┤0           ├┤0           ├─■──────░─┤ RZ(θ[5]) ├
     ├──────────┤ ░ │            ││            │ │      ░ ├──────────┤
q_1: ┤ RZ(θ[1]) ├─░─┤  RXX(θ[3]) ├┤  RYY(θ[3]) ├─┼──────░─┤ RZ(θ[6]) ├
     ├──────────┤ ░ │            ││            │ │θ[4]  ░ ├──────────┤
q_2: ┤ RZ(θ[2]) ├─░─┤1           ├┤1           ├─■──────░─┤ RZ(θ[7]) ├
     └──────────┘ ░ └────────────┘└────────────┘        ░ └──────────┘

Create a new ExcitationPreserving 2-local circuit.

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

  • mode (str) – Choose the entangler mode, can be ‘iswap’ or ‘fsim’.

  • reps (int) – Specifies how often the structure of a rotation layer followed by an entanglement layer is repeated.

  • entanglement (Union[str, List[List[int]], Callable[[int], List[int]]]) – Specifies the entanglement structure. Can be a string (‘full’, ‘linear’ or ‘sca’), a list of integer-pairs specifying the indices of qubits entangled with one another, or a callable returning such a list provided with the index of the entanglement layer. See the Examples section of TwoLocal for more detail.

  • initial_state (Optional[Any]) – An InitialState object to prepend to the circuit.

  • skip_unentangled_qubits (bool) – If True, the single qubit gates are only applied to qubits that are entangled with another qubit. If False, the single qubit gates are applied to each qubit in the Ansatz. Defaults to False.

  • skip_unentangled_qubits – If True, the single qubit gates are only applied to qubits that are entangled with another qubit. If False, the single qubit gates are applied to each qubit in the Ansatz. Defaults to False.

  • skip_final_rotation_layer (bool) – If True, a rotation layer is added at the end of the ansatz. If False, no rotation layer is added. Defaults to True.

  • parameter_prefix (str) – The parameterized gates require a parameter to be defined, for which we use ParameterVector.

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

Raises

ValueError – If the selected mode is not supported.

Attributes

ExcitationPreserving.ancillas

Returns a list of ancilla bits in the order that the registers were added.

ExcitationPreserving.clbits

Returns a list of classical bits in the order that the registers were added.

ExcitationPreserving.data

Return the circuit data (instructions and context).

ExcitationPreserving.entanglement

Get the entanglement strategy.

ExcitationPreserving.entanglement_blocks

The blocks in the entanglement layers.

ExcitationPreserving.extension_lib

ExcitationPreserving.global_phase

Return the global phase of the circuit in radians.

ExcitationPreserving.header

ExcitationPreserving.initial_state

Return the initial state that is added in front of the n-local circuit.

ExcitationPreserving.insert_barriers

If barriers are inserted in between the layers or not.

ExcitationPreserving.instances

ExcitationPreserving.n_qubits

Deprecated, use num_qubits instead.

ExcitationPreserving.num_ancillas

Return the number of ancilla qubits.

ExcitationPreserving.num_clbits

Return number of classical bits.

ExcitationPreserving.num_layers

Return the number of layers in the n-local circuit.

ExcitationPreserving.num_parameters

Convenience function to get the number of parameter objects in the circuit.

ExcitationPreserving.num_parameters_settable

The number of total parameters that can be set to distinct values.

ExcitationPreserving.num_qubits

Returns the number of qubits in this circuit.

ExcitationPreserving.ordered_parameters

The parameters used in the underlying circuit.

ExcitationPreserving.parameter_bounds

Return the parameter bounds.

ExcitationPreserving.parameters

Get the Parameter objects in the circuit.

ExcitationPreserving.preferred_init_points

The initial points for the parameters.

ExcitationPreserving.prefix

ExcitationPreserving.qregs

A list of the quantum registers associated with the circuit.

ExcitationPreserving.qubits

Returns a list of quantum bits in the order that the registers were added.

ExcitationPreserving.reps

The number of times rotation and entanglement block are repeated.

ExcitationPreserving.rotation_blocks

The blocks in the rotation layers.

Methods

ExcitationPreserving.AND(qr_variables, …)

Build a collective conjunction (AND) circuit in place using mct.

ExcitationPreserving.OR(qr_variables, …[, …])

Build a collective disjunction (OR) circuit in place using mct.

ExcitationPreserving.__getitem__(item)

Return indexed operation.

ExcitationPreserving.__len__()

Return number of operations in circuit.

ExcitationPreserving.add_layer(other[, …])

Append another layer to the NLocal.

ExcitationPreserving.add_register(*regs)

Add registers.

ExcitationPreserving.append(instruction[, …])

Append one or more instructions to the end of the circuit, modifying the circuit in place.

ExcitationPreserving.assign_parameters(…)

Assign parameters to the n-local circuit.

ExcitationPreserving.barrier(*qargs)

Apply Barrier.

ExcitationPreserving.bind_parameters(value_dict)

Assign numeric parameters to values yielding a new circuit.

ExcitationPreserving.cast(value, _type)

Best effort to cast value to type.

ExcitationPreserving.cbit_argument_conversion(…)

Converts several classical bit representations (such as indexes, range, etc.) into a list of classical bits.

ExcitationPreserving.ccx(control_qubit1, …)

Apply CCXGate.

ExcitationPreserving.ch(control_qubit, …)

Apply CHGate.

ExcitationPreserving.cls_instances()

Return the current number of instances of this class, useful for auto naming.

ExcitationPreserving.cls_prefix()

Return the prefix to use for auto naming.

ExcitationPreserving.cnot(control_qubit, …)

Apply CXGate.

ExcitationPreserving.combine(rhs)

Append rhs to self if self contains compatible registers.

ExcitationPreserving.compose(other[, …])

Compose circuit with other circuit or instruction, optionally permuting wires.

ExcitationPreserving.control([…])

Control this circuit on num_ctrl_qubits qubits.

ExcitationPreserving.copy([name])

Copy the circuit.

ExcitationPreserving.count_ops()

Count each operation kind in the circuit.

ExcitationPreserving.cp(theta, …[, label, …])

Apply CPhaseGate.

ExcitationPreserving.crx(theta, …[, …])

Apply CRXGate.

ExcitationPreserving.cry(theta, …[, …])

Apply CRYGate.

ExcitationPreserving.crz(theta, …[, …])

Apply CRZGate.

ExcitationPreserving.cswap(control_qubit, …)

Apply CSwapGate.

ExcitationPreserving.csx(control_qubit, …)

Apply CSXGate.

ExcitationPreserving.cu(theta, phi, lam, …)

Apply CUGate.

ExcitationPreserving.cu1(theta, …[, …])

Apply CU1Gate.

ExcitationPreserving.cu3(theta, phi, lam, …)

Apply CU3Gate.

ExcitationPreserving.cx(control_qubit, …)

Apply CXGate.

ExcitationPreserving.cy(control_qubit, …)

Apply CYGate.

ExcitationPreserving.cz(control_qubit, …)

Apply CZGate.

ExcitationPreserving.dcx(qubit1, qubit2)

Apply DCXGate.

ExcitationPreserving.decompose()

Call a decomposition pass on this circuit, to decompose one level (shallow decompose).

ExcitationPreserving.depth()

Return circuit depth (i.e., length of critical path).

ExcitationPreserving.diag_gate(diag, qubit)

Deprecated version of QuantumCircuit.diagonal.

ExcitationPreserving.diagonal(diag, qubit)

Attach a diagonal gate to a circuit.

ExcitationPreserving.draw([output, scale, …])

Draw the quantum circuit.

ExcitationPreserving.extend(rhs)

Append QuantumCircuit to the right hand side if it contains compatible registers.

ExcitationPreserving.fredkin(control_qubit, …)

Apply CSwapGate.

ExcitationPreserving.from_qasm_file(path)

Take in a QASM file and generate a QuantumCircuit object.

ExcitationPreserving.from_qasm_str(qasm_str)

Take in a QASM string and generate a QuantumCircuit object.

ExcitationPreserving.get_entangler_map(…)

Overloading to handle the special case of 1 qubit where the entanglement are ignored.

ExcitationPreserving.get_unentangled_qubits()

Get the indices of unentangled qubits in a set.

ExcitationPreserving.h(qubit, *[, q])

Apply HGate.

ExcitationPreserving.hamiltonian(operator, …)

Apply hamiltonian evolution to to qubits.

ExcitationPreserving.has_register(register)

Test if this circuit has the register r.

ExcitationPreserving.i(qubit, *[, q])

Apply IGate.

ExcitationPreserving.id(qubit, *[, q])

Apply IGate.

ExcitationPreserving.iden(qubit, *[, q])

Deprecated identity gate.

ExcitationPreserving.initialize(params, qubits)

Apply initialize to circuit.

ExcitationPreserving.inverse()

Invert (take adjoint of) this circuit.

ExcitationPreserving.iso(isometry, q_input, …)

Attach an arbitrary isometry from m to n qubits to a circuit.

ExcitationPreserving.isometry(isometry, …)

Attach an arbitrary isometry from m to n qubits to a circuit.

ExcitationPreserving.iswap(qubit1, qubit2)

Apply iSwapGate.

ExcitationPreserving.mcmt(gate, …[, …])

Apply a multi-control, multi-target using a generic gate.

ExcitationPreserving.mcrx(theta, q_controls, …)

Apply Multiple-Controlled X rotation gate

ExcitationPreserving.mcry(theta, q_controls, …)

Apply Multiple-Controlled Y rotation gate

ExcitationPreserving.mcrz(lam, q_controls, …)

Apply Multiple-Controlled Z rotation gate

ExcitationPreserving.mct(control_qubits, …)

Apply MCXGate.

ExcitationPreserving.mcu1(lam, …)

Apply MCU1Gate.

ExcitationPreserving.mcx(control_qubits, …)

Apply MCXGate.

ExcitationPreserving.measure(qubit, cbit)

Measure quantum bit into classical bit (tuples).

ExcitationPreserving.measure_active([inplace])

Adds measurement to all non-idle qubits.

ExcitationPreserving.measure_all([inplace])

Adds measurement to all qubits.

ExcitationPreserving.mirror()

DEPRECATED: use circuit.reverse_ops().

ExcitationPreserving.ms(theta, qubits)

Apply MSGate.

ExcitationPreserving.num_connected_components([…])

How many non-entangled subcircuits can the circuit be factored to.

ExcitationPreserving.num_nonlocal_gates()

Return number of non-local gates (i.e.

ExcitationPreserving.num_tensor_factors()

Computes the number of tensor factors in the unitary (quantum) part of the circuit only.

ExcitationPreserving.num_unitary_factors()

Computes the number of tensor factors in the unitary (quantum) part of the circuit only.

ExcitationPreserving.p(theta, qubit)

Apply PhaseGate.

ExcitationPreserving.power(power[, matrix_power])

Raise this circuit to the power of power.

ExcitationPreserving.print_settings()

Returns information about the setting.

ExcitationPreserving.qasm([formatted, filename])

Return OpenQASM string.

ExcitationPreserving.qbit_argument_conversion(…)

Converts several qubit representations (such as indexes, range, etc.) into a list of qubits.

ExcitationPreserving.r(theta, phi, qubit, *)

Apply RGate.

ExcitationPreserving.rcccx(control_qubit1, …)

Apply RC3XGate.

ExcitationPreserving.rccx(control_qubit1, …)

Apply RCCXGate.

ExcitationPreserving.remove_final_measurements([…])

Removes final measurement on all qubits if they are present.

ExcitationPreserving.repeat(reps)

Repeat this circuit reps times.

ExcitationPreserving.reset(qubit)

Reset q.

ExcitationPreserving.reverse_bits()

Return a circuit with the opposite order of wires.

ExcitationPreserving.reverse_ops()

Reverse the circuit by reversing the order of instructions.

ExcitationPreserving.rx(theta, qubit, *[, …])

Apply RXGate.

ExcitationPreserving.rxx(theta, qubit1, qubit2)

Apply RXXGate.

ExcitationPreserving.ry(theta, qubit, *[, …])

Apply RYGate.

ExcitationPreserving.ryy(theta, qubit1, qubit2)

Apply RYYGate.

ExcitationPreserving.rz(phi, qubit, *[, q])

Apply RZGate.

ExcitationPreserving.rzx(theta, qubit1, qubit2)

Apply RZXGate.

ExcitationPreserving.rzz(theta, qubit1, qubit2)

Apply RZZGate.

ExcitationPreserving.s(qubit, *[, q])

Apply SGate.

ExcitationPreserving.sdg(qubit, *[, q])

Apply SdgGate.

ExcitationPreserving.size()

Returns total number of gate operations in circuit.

ExcitationPreserving.snapshot(label[, …])

Take a statevector snapshot of the internal simulator representation.

ExcitationPreserving.snapshot_density_matrix(label)

Take a density matrix snapshot of simulator state.

ExcitationPreserving.snapshot_expectation_value(…)

Take a snapshot of expectation value <O> of an Operator.

ExcitationPreserving.snapshot_probabilities(…)

Take a probability snapshot of the simulator state.

ExcitationPreserving.snapshot_stabilizer(label)

Take a stabilizer snapshot of the simulator state.

ExcitationPreserving.snapshot_statevector(label)

Take a statevector snapshot of the simulator state.

ExcitationPreserving.squ(unitary_matrix, qubit)

Decompose an arbitrary 2*2 unitary into three rotation gates.

ExcitationPreserving.swap(qubit1, qubit2)

Apply SwapGate.

ExcitationPreserving.sx(qubit)

Apply SXGate.

ExcitationPreserving.sxdg(qubit)

Apply SXdgGate.

ExcitationPreserving.t(qubit, *[, q])

Apply TGate.

ExcitationPreserving.tdg(qubit, *[, q])

Apply TdgGate.

ExcitationPreserving.to_gate([…])

Create a Gate out of this circuit.

ExcitationPreserving.to_instruction([…])

Create an Instruction out of this circuit.

ExcitationPreserving.toffoli(control_qubit1, …)

Apply CCXGate.

ExcitationPreserving.u(theta, phi, lam, qubit)

Apply UGate.

ExcitationPreserving.u1(theta, qubit, *[, q])

Apply U1Gate.

ExcitationPreserving.u2(phi, lam, qubit, *)

Apply U2Gate.

ExcitationPreserving.u3(theta, phi, lam, …)

Apply U3Gate.

ExcitationPreserving.uc(gate_list, …[, …])

Attach a uniformly controlled gates (also called multiplexed gates) to a circuit.

ExcitationPreserving.ucg(angle_list, …[, …])

Deprecated version of uc.

ExcitationPreserving.ucrx(angle_list, …)

Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit.

ExcitationPreserving.ucry(angle_list, …)

Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit.

ExcitationPreserving.ucrz(angle_list, …)

Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit.

ExcitationPreserving.ucx(angle_list, …)

Deprecated version of ucrx.

ExcitationPreserving.ucy(angle_list, …)

Deprecated version of ucry.

ExcitationPreserving.ucz(angle_list, …)

Deprecated version of ucrz.

ExcitationPreserving.unitary(obj, qubits[, …])

Apply unitary gate to q.

ExcitationPreserving.width()

Return number of qubits plus clbits in circuit.

ExcitationPreserving.x(qubit, *[, label, …])

Apply XGate.

ExcitationPreserving.y(qubit, *[, q])

Apply YGate.

ExcitationPreserving.z(qubit, *[, q])

Apply ZGate.

ExcitationPreserving.__getitem__(item)

Return indexed operation.

ExcitationPreserving.__len__()

Return number of operations in circuit.