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.ancillas Returns a list of ancilla bits in the order that the registers were added. Diagonal.calibrations Return calibration dictionary. 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.global_phase Return the global phase of the circuit in radians. Diagonal.header Diagonal.instances Diagonal.num_ancillas Return the number of ancilla qubits. 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

 Return indexed operation. Return number of operations in circuit. Diagonal.add_calibration(gate, qubits, schedule) Register a low-level, custom pulse definition for the given gate. 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. 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. Return the current number of instances of this class, useful for auto naming. Return the prefix to use for auto naming. Diagonal.cnot(control_qubit, target_qubit[, …]) Apply CXGate. 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.control([num_ctrl_qubits, label, …]) Control this circuit on num_ctrl_qubits qubits. Diagonal.copy([name]) Copy the circuit. Count each operation kind in the circuit. Diagonal.cp(theta, control_qubit, target_qubit) Apply CPhaseGate. Diagonal.crx(theta, control_qubit, target_qubit) Apply CRXGate. Diagonal.cry(theta, control_qubit, target_qubit) Apply CRYGate. Diagonal.crz(theta, control_qubit, target_qubit) Apply CRZGate. Diagonal.cswap(control_qubit, target_qubit1, …) Apply CSwapGate. Diagonal.csx(control_qubit, target_qubit[, …]) Apply CSXGate. Diagonal.cu(theta, phi, lam, gamma, …[, …]) Apply CUGate. Diagonal.cu1(theta, control_qubit, target_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. Call a decomposition pass on this circuit, to decompose one level (shallow decompose). Diagonal.delay(duration[, qarg, unit]) Apply Delay. 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. Append QuantumCircuit to the right hand side if it contains compatible registers. Diagonal.fredkin(control_qubit, …) Apply CSwapGate. 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) 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) Apply IGate. Diagonal.id(qubit) Apply IGate. Diagonal.initialize(params, qubits) Apply initialize to circuit. Invert (take adjoint of) 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.mcp(lam, control_qubits, target_qubit) Apply MCPhaseGate. 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. DEPRECATED: use circuit.reverse_ops(). Diagonal.ms(theta, qubits) Apply MSGate. Diagonal.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. Diagonal.p(theta, qubit) Apply PhaseGate. Diagonal.power(power[, matrix_power]) Raise this circuit to the power of power. Diagonal.qasm([formatted, filename]) Return OpenQASM string. Converts several qubit representations (such as indexes, range, etc.) into a list of qubits. Diagonal.qubit_duration(*qubits) Return the duration between the start and stop time of the first and last instructions, excluding delays, over the supplied qubits. Diagonal.qubit_start_time(*qubits) Return the start time of the first instruction, excluding delays, over the supplied qubits. Diagonal.qubit_stop_time(*qubits) Return the stop time of the last instruction, excluding delays, over the supplied qubits. Diagonal.r(theta, phi, qubit) 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. Repeat this circuit reps times. Diagonal.reset(qubit) Reset q. Return a circuit with the opposite order of wires. Reverse the circuit by reversing the order of instructions. Diagonal.rx(theta, qubit[, label]) Apply RXGate. Diagonal.rxx(theta, qubit1, qubit2) Apply RXXGate. Diagonal.ry(theta, qubit[, label]) Apply RYGate. Diagonal.ryy(theta, qubit1, qubit2) Apply RYYGate. Diagonal.rz(phi, qubit) Apply RZGate. Diagonal.rzx(theta, qubit1, qubit2) Apply RZXGate. Diagonal.rzz(theta, qubit1, qubit2) Apply RZZGate. Diagonal.s(qubit) Apply SGate. Diagonal.sdg(qubit) Apply SdgGate. 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. Take a snapshot of expectation value of an Operator. Diagonal.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. Diagonal.squ(unitary_matrix, qubit[, mode, …]) Decompose an arbitrary 2*2 unitary into three rotation gates. Diagonal.swap(qubit1, qubit2) Apply SwapGate. Diagonal.sx(qubit) Apply SXGate. Diagonal.sxdg(qubit) Apply SXdgGate. Diagonal.t(qubit) Apply TGate. Diagonal.tdg(qubit) Apply TdgGate. Diagonal.to_gate([parameter_map, label]) 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.u(theta, phi, lam, qubit) Apply UGate. Diagonal.u1(theta, qubit) Apply U1Gate. Diagonal.u2(phi, lam, qubit) Apply U2Gate. Diagonal.u3(theta, phi, lam, qubit) Apply U3Gate. Diagonal.uc(gate_list, q_controls, q_target) Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. 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.unitary(obj, qubits[, label]) Apply unitary gate to q. Return number of qubits plus clbits in circuit. Diagonal.x(qubit[, label]) Apply XGate. Diagonal.y(qubit) Apply YGate. Diagonal.z(qubit) Apply ZGate. Return indexed operation. Return number of operations in circuit.