# LinearAmplitudeFunction¶

class LinearAmplitudeFunction(num_state_qubits, slope, offset, domain, image, rescaling_factor=1, breakpoints=None, name='F')[source]

A circuit implementing a (piecewise) linear function on qubit amplitudes.

An amplitude function $$F$$ of a function $$f$$ is a mapping

$F|x\rangle|0\rangle = \sqrt{1 - \hat{f}(x)} |x\rangle|0\rangle + \sqrt{\hat{f}(x)} |x\rangle|1\rangle.$

for a function $$\hat{f}: \{0, ..., 2^n - 1} \rightarrow [0, 1]$$, where $$|x\rangle$$ is a $$n$$ qubit state.

This circuit implements $$F$$ for piecewise linear functions $$\hat{f}$$. In this case, the mapping $$F$$ can be approximately implemented using a Taylor expansion and linearly controlled Pauli-Y rotations, see [1, 2] for more detail. This approximation uses a rescaling_factor to determine the accuracy of the Taylor expansion.

In general, the function of interest $$f$$ is defined from some interval $$[a,b]$$, the domain to $$[c,d]$$, the image, instead of :math{1, …, N} to $$[0, 1]$$. Usng an affine transformation we can rescale $$f$$ to $$\hat{f}$$:

$\hat{f(x)} = \frac{f(\phi(x)) - c}{d - c}$

with

$\phi(x) = a + \frac{b - a}{2^n - 1} x.$

If $$f$$ is a piecewise linear function on $$m$$ intervals $$[p_{i-1}, p_i], i \in \{1, ..., m\}$$ with slopes $$\alpha_i$$ and offsets beta_i it can be written as

$f(x) = \sum_{i=1}^m 1_{[p_{i-1}, p_i}(x) (\alpha_i x + \beta_i)$

where $$1_[a, b]$$ is an indication function that is 1 if the argument is in the interval $$[a, b]$$ and otherwise 0. The breakpoints $$p_i$$ can be specified by the breakpoints argument.

Examples:

References

: Woerner, S., & Egger, D. J. (2018).

Quantum Risk Analysis. arXiv:1806.06893

: Gacon, J., Zoufal, C., & Woerner, S. (2020).

Quantum-Enhanced Simulation-Based Optimization. arXiv:2005.10780

Parameters
• num_state_qubits (int) – The number of qubits used to encode the variable $$x$$.

• slope (Union[float, List[float]]) – The slope of the linear function. Can be a list of slopes if it is a piecewise linear function.

• offset (Union[float, List[float]]) – The offset of the linear function. Can be a list of offsets if it is a piecewise linear function.

• domain (Tuple[float, float]) – The domain of the function as tuple $$(x_\min{}, x_\max{})$$.

• image (Tuple[float, float]) – The image of the function as tuple $$(f_\min{}, f_\max{})$$.

• rescaling_factor (float) – The rescaling factor to adjust the accuracy in the Taylor approximation.

• breakpoints (Optional[List[float]]) – The breakpoints if the function is piecewise linear. If None, the function is not piecewise.

• name (str) – Name of the circuit.

Attributes

 LinearAmplitudeFunction.ancillas Returns a list of ancilla bits in the order that the registers were added. LinearAmplitudeFunction.calibrations Return calibration dictionary. LinearAmplitudeFunction.clbits Returns a list of classical bits in the order that the registers were added. LinearAmplitudeFunction.data Return the circuit data (instructions and context). LinearAmplitudeFunction.extension_lib LinearAmplitudeFunction.global_phase Return the global phase of the circuit in radians. LinearAmplitudeFunction.header LinearAmplitudeFunction.instances LinearAmplitudeFunction.num_ancillas Return the number of ancilla qubits. LinearAmplitudeFunction.num_clbits Return number of classical bits. LinearAmplitudeFunction.num_parameters Convenience function to get the number of parameter objects in the circuit. LinearAmplitudeFunction.num_qubits Return number of qubits. LinearAmplitudeFunction.parameters Convenience function to get the parameters defined in the parameter table. LinearAmplitudeFunction.prefix LinearAmplitudeFunction.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. Register a low-level, custom pulse definition for the given gate. Add registers. LinearAmplitudeFunction.append(instruction) Append one or more instructions to the end of the circuit, modifying the circuit in place. Assign parameters to new parameters or values. Apply Barrier. Assign numeric parameters to values yielding a new circuit. LinearAmplitudeFunction.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. LinearAmplitudeFunction.ccx(control_qubit1, …) Apply CCXGate. LinearAmplitudeFunction.ch(control_qubit, …) Apply CHGate. Return the current number of instances of this class, useful for auto naming. Return the prefix to use for auto naming. LinearAmplitudeFunction.cnot(control_qubit, …) Apply CXGate. Append rhs to self if self contains compatible registers. LinearAmplitudeFunction.compose(other[, …]) Compose circuit with other circuit or instruction, optionally permuting wires. Control this circuit on num_ctrl_qubits qubits. Copy the circuit. Count each operation kind in the circuit. LinearAmplitudeFunction.cp(theta, …[, …]) Apply CPhaseGate. LinearAmplitudeFunction.crx(theta, …[, …]) Apply CRXGate. LinearAmplitudeFunction.cry(theta, …[, …]) Apply CRYGate. LinearAmplitudeFunction.crz(theta, …[, …]) Apply CRZGate. LinearAmplitudeFunction.cswap(control_qubit, …) Apply CSwapGate. LinearAmplitudeFunction.csx(control_qubit, …) Apply CSXGate. LinearAmplitudeFunction.cu(theta, phi, lam, …) Apply CUGate. LinearAmplitudeFunction.cu1(theta, …[, …]) Apply CU1Gate. LinearAmplitudeFunction.cu3(theta, phi, lam, …) Apply CU3Gate. LinearAmplitudeFunction.cx(control_qubit, …) Apply CXGate. LinearAmplitudeFunction.cy(control_qubit, …) Apply CYGate. LinearAmplitudeFunction.cz(control_qubit, …) Apply CZGate. LinearAmplitudeFunction.dcx(qubit1, qubit2) Apply DCXGate. Call a decomposition pass on this circuit, to decompose one level (shallow decompose). LinearAmplitudeFunction.delay(duration[, …]) Apply Delay. Return circuit depth (i.e., length of critical path). LinearAmplitudeFunction.diag_gate(diag, qubit) Deprecated version of QuantumCircuit.diagonal. LinearAmplitudeFunction.diagonal(diag, qubit) Attach a diagonal gate to a circuit. LinearAmplitudeFunction.draw([output, …]) Draw the quantum circuit. Append QuantumCircuit to the right hand side if it contains compatible registers. Apply CSwapGate. Take in a QASM file and generate a QuantumCircuit object. Take in a QASM string and generate a QuantumCircuit object. Apply HGate. LinearAmplitudeFunction.hamiltonian(…[, label]) Apply hamiltonian evolution to to qubits. Test if this circuit has the register r. Apply IGate. Apply IGate. LinearAmplitudeFunction.initialize(params, …) Apply initialize to circuit. Invert (take adjoint of) this circuit. LinearAmplitudeFunction.iso(isometry, …[, …]) Attach an arbitrary isometry from m to n qubits to a circuit. LinearAmplitudeFunction.isometry(isometry, …) Attach an arbitrary isometry from m to n qubits to a circuit. LinearAmplitudeFunction.iswap(qubit1, qubit2) Apply iSwapGate. LinearAmplitudeFunction.mcmt(gate, …[, …]) Apply a multi-control, multi-target using a generic gate. Apply MCPhaseGate. LinearAmplitudeFunction.mcrx(theta, …[, …]) Apply Multiple-Controlled X rotation gate LinearAmplitudeFunction.mcry(theta, …[, …]) Apply Multiple-Controlled Y rotation gate LinearAmplitudeFunction.mcrz(lam, …[, …]) Apply Multiple-Controlled Z rotation gate LinearAmplitudeFunction.mct(control_qubits, …) Apply MCXGate. Apply MCU1Gate. LinearAmplitudeFunction.mcx(control_qubits, …) Apply MCXGate. LinearAmplitudeFunction.measure(qubit, cbit) Measure quantum bit into classical bit (tuples). Adds measurement to all non-idle qubits. Adds measurement to all qubits. DEPRECATED: use circuit.reverse_ops(). LinearAmplitudeFunction.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. LinearAmplitudeFunction.p(theta, qubit) Apply PhaseGate. Map the function value of the approximated $$\hat{f}$$ to $$f$$. LinearAmplitudeFunction.power(power[, …]) Raise this circuit to the power of power. LinearAmplitudeFunction.qasm([formatted, …]) 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. LinearAmplitudeFunction.r(theta, phi, qubit) Apply RGate. Apply RC3XGate. LinearAmplitudeFunction.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. LinearAmplitudeFunction.rx(theta, qubit[, label]) Apply RXGate. LinearAmplitudeFunction.rxx(theta, qubit1, …) Apply RXXGate. LinearAmplitudeFunction.ry(theta, qubit[, label]) Apply RYGate. LinearAmplitudeFunction.ryy(theta, qubit1, …) Apply RYYGate. LinearAmplitudeFunction.rz(phi, qubit) Apply RZGate. LinearAmplitudeFunction.rzx(theta, qubit1, …) Apply RZXGate. LinearAmplitudeFunction.rzz(theta, qubit1, …) Apply RZZGate. Apply SGate. Apply SdgGate. Returns total number of gate operations in circuit. LinearAmplitudeFunction.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. LinearAmplitudeFunction.squ(unitary_matrix, …) Decompose an arbitrary 2*2 unitary into three rotation gates. LinearAmplitudeFunction.swap(qubit1, qubit2) Apply SwapGate. Apply SXGate. Apply SXdgGate. Apply TGate. Apply TdgGate. Create a Gate out of this circuit. Create an Instruction out of this circuit. Apply CCXGate. LinearAmplitudeFunction.u(theta, phi, lam, qubit) Apply UGate. LinearAmplitudeFunction.u1(theta, qubit) Apply U1Gate. LinearAmplitudeFunction.u2(phi, lam, qubit) Apply U2Gate. LinearAmplitudeFunction.u3(theta, phi, lam, …) Apply U3Gate. LinearAmplitudeFunction.uc(gate_list, …[, …]) Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. LinearAmplitudeFunction.ucrx(angle_list, …) Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit. LinearAmplitudeFunction.ucry(angle_list, …) Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit. LinearAmplitudeFunction.ucrz(angle_list, …) Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit. LinearAmplitudeFunction.unitary(obj, qubits) Apply unitary gate to q. Return number of qubits plus clbits in circuit. LinearAmplitudeFunction.x(qubit[, label]) Apply XGate. Apply YGate. Apply ZGate. Return indexed operation. Return number of operations in circuit.