Diagonal

class Diagonal(diag)[source]

Diagonal circuit.

Circuit symbol:

     ┌───────────┐
q_0: ┤0          ├
     │           │
q_1: ┤1 Diagonal ├
     │           │
q_2: ┤2          ├
     └───────────┘

Matrix form:

\[\begin{split}\text{DiagonalGate}\ q_0, q_1, .., q_{n-1} = \begin{pmatrix} D[0] & 0 & \dots & 0 \\ 0 & D[1] & \dots & 0 \\ \vdots & \vdots & \ddots & 0 \\ 0 & 0 & \dots & D[n-1] \end{pmatrix}\end{split}\]

Diagonal gates are useful as representations of Boolean functions, as they can map from {0,1}^2**n to {0,1}^2**n space. For example a phase oracle can be seen as a diagonal gate with {+1, -1} on the diagonals. Such an oracle will induce a +1 or -1 phase on the amplitude of any corresponding basis state.

Diagonal gates appear in many classically hard oracular problems such as Forrelation or Hidden Shift circuits.

Diagonal gates are represented and simulated more efficiently than a dense 2**n x 2**n unitary matrix.

The reference implementation is via the method described in Theorem 7 of [1]. The code is based on Emanuel Malvetti’s semester thesis at ETH in 2018, supervised by Raban Iten and Prof. Renato Renner.

Reference:

[1] Shende et al., Synthesis of Quantum Logic Circuits, 2009 arXiv:0406176

Create a new Diagonal circuit.

Parameters

diag (Union[List, array]) – list of the 2^k diagonal entries (for a diagonal gate on k qubits).

Raises

CircuitError – if the list of the diagonal entries or the qubit list is in bad format; if the number of diagonal entries is not 2^k, where k denotes the number of qubits

Attributes

Diagonal.clbits

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

Diagonal.data

Return the circuit data (instructions and context).

Diagonal.extension_lib

Diagonal.header

Diagonal.instances

Diagonal.n_qubits

Deprecated, use num_qubits instead.

Diagonal.num_clbits

Return number of classical bits.

Diagonal.num_parameters

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

Diagonal.num_qubits

Return number of qubits.

Diagonal.parameters

Convenience function to get the parameters defined in the parameter table.

Diagonal.prefix

Diagonal.qubits

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

Methods

Diagonal.AND(qr_variables, qb_target, …[, …])

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

Diagonal.OR(qr_variables, qb_target, qr_ancillae)

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

Diagonal.__getitem__(item)

Return indexed operation.

Diagonal.__len__()

Return number of operations in circuit.

Diagonal.add_register(*regs)

Add registers.

Diagonal.append(instruction[, qargs, cargs])

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

Diagonal.assign_parameters(param_dict[, inplace])

Assign parameters to new parameters or values.

Diagonal.barrier(*qargs)

Apply Barrier.

Diagonal.bind_parameters(value_dict)

Assign numeric parameters to values yielding a new circuit.

Diagonal.cast(value, _type)

Best effort to cast value to type.

Diagonal.cbit_argument_conversion(…)

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

Diagonal.ccx(control_qubit1, control_qubit2, …)

Apply CCXGate.

Diagonal.ch(control_qubit, target_qubit, *)

Apply CHGate.

Diagonal.cls_instances()

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

Diagonal.cls_prefix()

Return the prefix to use for auto naming.

Diagonal.cnot(control_qubit, target_qubit, *)

Apply CXGate.

Diagonal.combine(rhs)

Append rhs to self if self contains compatible registers.

Diagonal.compose(other[, qubits, clbits, …])

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

Diagonal.copy([name])

Copy the circuit.

Diagonal.count_ops()

Count each operation kind in the circuit.

Diagonal.crx(theta, control_qubit, …[, …])

Apply CRXGate.

Diagonal.cry(theta, control_qubit, …[, …])

Apply CRYGate.

Diagonal.crz(theta, control_qubit, …[, …])

Apply CRZGate.

Diagonal.cswap(control_qubit, target_qubit1, …)

Apply CSwapGate.

Diagonal.cu1(theta, control_qubit, …[, …])

Apply CU1Gate.

Diagonal.cu3(theta, phi, lam, control_qubit, …)

Apply CU3Gate.

Diagonal.cx(control_qubit, target_qubit, *)

Apply CXGate.

Diagonal.cy(control_qubit, target_qubit, *)

Apply CYGate.

Diagonal.cz(control_qubit, target_qubit, *)

Apply CZGate.

Diagonal.dcx(qubit1, qubit2)

Apply DCXGate.

Diagonal.decompose()

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

Diagonal.depth()

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

Diagonal.diag_gate(diag, qubit)

Deprecated version of QuantumCircuit.diagonal.

Diagonal.diagonal(diag, qubit)

Attach a diagonal gate to a circuit.

Diagonal.draw([output, scale, filename, …])

Draw the quantum circuit.

Diagonal.extend(rhs)

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

Diagonal.fredkin(control_qubit, …[, ctl, …])

Apply CSwapGate.

Diagonal.from_qasm_file(path)

Take in a QASM file and generate a QuantumCircuit object.

Diagonal.from_qasm_str(qasm_str)

Take in a QASM string and generate a QuantumCircuit object.

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

Apply HGate.

Diagonal.hamiltonian(operator, time, qubits)

Apply hamiltonian evolution to to qubits.

Diagonal.has_register(register)

Test if this circuit has the register r.

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

Apply IGate.

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

Apply IGate.

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

Deprecated identity gate.

Diagonal.initialize(params, qubits)

Apply initialize to circuit.

Diagonal.inverse()

Invert this circuit.

Diagonal.iso(isometry, q_input, …[, …])

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

Diagonal.isometry(isometry, q_input, …[, …])

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

Diagonal.iswap(qubit1, qubit2)

Apply iSwapGate.

Diagonal.mcmt(gate, control_qubits, …[, …])

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

Diagonal.mcrx(theta, q_controls, q_target[, …])

Apply Multiple-Controlled X rotation gate

Diagonal.mcry(theta, q_controls, q_target, …)

Apply Multiple-Controlled Y rotation gate

Diagonal.mcrz(lam, q_controls, q_target[, …])

Apply Multiple-Controlled Z rotation gate

Diagonal.mct(control_qubits, target_qubit[, …])

Apply MCXGate.

Diagonal.mcu1(lam, control_qubits, target_qubit)

Apply MCU1Gate.

Diagonal.mcx(control_qubits, target_qubit[, …])

Apply MCXGate.

Diagonal.measure(qubit, cbit)

Measure quantum bit into classical bit (tuples).

Diagonal.measure_active([inplace])

Adds measurement to all non-idle qubits.

Diagonal.measure_all([inplace])

Adds measurement to all qubits.

Diagonal.mirror()

Mirror the circuit by reversing the instructions.

Diagonal.ms(theta, qubits)

Apply MSGate.

Diagonal.num_connected_components([unitary_only])

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

Diagonal.num_nonlocal_gates()

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

Diagonal.num_tensor_factors()

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

Diagonal.num_unitary_factors()

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

Diagonal.qasm([formatted, filename])

Return OpenQASM string.

Diagonal.qbit_argument_conversion(…)

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

Diagonal.r(theta, phi, qubit, *[, q])

Apply RGate.

Diagonal.rcccx(control_qubit1, …)

Apply RC3XGate.

Diagonal.rccx(control_qubit1, …)

Apply RCCXGate.

Diagonal.remove_final_measurements([inplace])

Removes final measurement on all qubits if they are present.

Diagonal.reset(qubit)

Reset q.

Diagonal.rx(theta, qubit, *[, label, q])

Apply RXGate.

Diagonal.rxx(theta, qubit1, qubit2)

Apply RXXGate.

Diagonal.ry(theta, qubit, *[, label, q])

Apply RYGate.

Diagonal.ryy(theta, qubit1, qubit2)

Apply RYYGate.

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

Apply RZGate.

Diagonal.rzx(theta, qubit1, qubit2)

Apply RZXGate.

Diagonal.rzz(theta, qubit1, qubit2)

Apply RZZGate.

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

Apply SGate.

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

Apply SdgGate.

Diagonal.size()

Returns total number of gate operations in circuit.

Diagonal.snapshot(label[, snapshot_type, …])

Take a statevector snapshot of the internal simulator representation.

Diagonal.snapshot_density_matrix(label[, qubits])

Take a density matrix snapshot of simulator state.

Diagonal.snapshot_expectation_value(label, …)

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

Diagonal.snapshot_probabilities(label, qubits)

Take a probability snapshot of the simulator state.

Diagonal.snapshot_stabilizer(label)

Take a stabilizer snapshot of the simulator state.

Diagonal.snapshot_statevector(label)

Take a statevector snapshot of the simulator state.

Diagonal.squ(unitary_matrix, qubit[, mode, …])

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

Diagonal.swap(qubit1, qubit2)

Apply SwapGate.

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

Apply TGate.

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

Apply TdgGate.

Diagonal.to_gate([parameter_map])

Create a Gate out of this circuit.

Diagonal.to_instruction([parameter_map])

Create an Instruction out of this circuit.

Diagonal.toffoli(control_qubit1, …[, …])

Apply CCXGate.

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

Apply U1Gate.

Diagonal.u2(phi, lam, qubit, *[, q])

Apply U2Gate.

Diagonal.u3(theta, phi, lam, qubit, *[, q])

Apply U3Gate.

Diagonal.uc(gate_list, q_controls, q_target)

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

Diagonal.ucg(angle_list, q_controls, q_target)

Deprecated version of uc.

Diagonal.ucrx(angle_list, q_controls, q_target)

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

Diagonal.ucry(angle_list, q_controls, q_target)

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

Diagonal.ucrz(angle_list, q_controls, q_target)

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

Diagonal.ucx(angle_list, q_controls, q_target)

Deprecated version of ucrx.

Diagonal.ucy(angle_list, q_controls, q_target)

Deprecated version of ucry.

Diagonal.ucz(angle_list, q_controls, q_target)

Deprecated version of ucrz.

Diagonal.unitary(obj, qubits[, label])

Apply unitary gate to q.

Diagonal.width()

Return number of qubits plus clbits in circuit.

Diagonal.x(qubit, *[, label, ctrl_state, q])

Apply XGate.

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

Apply YGate.

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

Apply ZGate.

Diagonal.__getitem__(item)

Return indexed operation.

Diagonal.__len__()

Return number of operations in circuit.