# LogNormalDistribution¶

class LogNormalDistribution(num_qubits, mu=None, sigma=None, bounds=None, upto_diag=False, name='P(X)')[source]

A circuit to encode a discretized log-normal distribution in qubit amplitudes.

A random variable $$X$$ is log-normal distributed if

$\log(X) \sim \mathcal{N}(\mu, \sigma^2)$

for a normal distribution $$\mathcal{N}(\mu, \sigma^2)$$. The probability density function of the log-normal distribution is defined as

$\mathbb{P}(X = x) = \frac{1}{x\sqrt{2\pi\sigma^2}} e^{-\frac{(\log(x) - \mu)^2}{\sigma^2}}$

Note

The parameter sigma in this class equals the variance, $$\sigma^2$$ and not the standard deviation. This is for consistency with multivariate distributions, where the uppercase sigma, $$\Sigma$$, is associated with the covariance.

This circuit considers the discretized version of $$X$$ on 2 ** num_qubits equidistant points, $$x_i$$, truncated to bounds. The action of this circuit can be written as

$\mathcal{P}_X |0\rangle^n = \sum_{i=0}^{2^n - 1} \sqrt{\mathbb{P}(x_i)} |i\rangle$

where $$n$$ is num_qubits.

Note

The circuit loads the square root of the probabilities into the qubit amplitudes such that the sampling probability, which is the square of the amplitude, equals the probability of the distribution.

This circuit is for example used in amplitude estimation applications, such as finance [1, 2], where customer demand or the return of a portfolio could be modelled using a log-normal distribution.

Examples

This class can be used for both univariate and multivariate distributions. >>> mu = [1, 0.9, 0.2] >>> sigma = [[1, -0.2, 0.2], [-0.2, 1, 0.4], [0.2, 0.4, 1]] >>> circuit = LogNormalDistribution([2, 2, 2], mu, sigma) >>> circuit.num_qubits 6

References

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

Quantum-Enhanced Simulation-Based Optimization. arXiv:2005.10780

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

Quantum Risk Analysis. arXiv:1806.06893

Parameters
• num_qubits (Union[int, List[int]]) – The number of qubits used to discretize the random variable. For a 1d random variable, num_qubits is an integer, for multiple dimensions a list of integers indicating the number of qubits to use in each dimension.

• mu (Union[float, List[float], None]) – The parameter $$\mu$$ of the distribution. Can be either a float for a 1d random variable or a list of floats for a higher dimensional random variable.

• sigma (Union[float, List[float], None]) – The parameter $$\sigma^2$$ or $$\Sigma$$, which is the variance or covariance matrix.

• bounds (Union[Tuple[float, float], List[Tuple[float, float]], None]) – The truncation bounds of the distribution as tuples. For multiple dimensions, bounds is a list of tuples [(low0, high0), (low1, high1), ...]. If None, the bounds are set to (0, 1) for each dimension.

• upto_diag (bool) – If True, load the square root of the probabilities up to multiplication with a diagonal for a more efficient circuit.

• name (str) – The name of the circuit.

Attributes

 LogNormalDistribution.ancillas Returns a list of ancilla bits in the order that the registers were added. LogNormalDistribution.bounds Return the bounds of the probability distribution. LogNormalDistribution.calibrations Return calibration dictionary. LogNormalDistribution.clbits Returns a list of classical bits in the order that the registers were added. LogNormalDistribution.data Return the circuit data (instructions and context). LogNormalDistribution.extension_lib LogNormalDistribution.global_phase Return the global phase of the circuit in radians. LogNormalDistribution.header LogNormalDistribution.instances LogNormalDistribution.num_ancillas Return the number of ancilla qubits. LogNormalDistribution.num_clbits Return number of classical bits. LogNormalDistribution.num_parameters Convenience function to get the number of parameter objects in the circuit. LogNormalDistribution.num_qubits Return number of qubits. LogNormalDistribution.parameters Convenience function to get the parameters defined in the parameter table. LogNormalDistribution.prefix LogNormalDistribution.probabilities Return the sampling probabilities for the values. LogNormalDistribution.qubits Returns a list of quantum bits in the order that the registers were added. LogNormalDistribution.values Return the discretized points of the random variable.

Methods

 Return indexed operation. Return number of operations in circuit. Register a low-level, custom pulse definition for the given gate. Add registers. LogNormalDistribution.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. LogNormalDistribution.bind_parameters(value_dict) Assign numeric parameters to values yielding a new circuit. LogNormalDistribution.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. LogNormalDistribution.ccx(control_qubit1, …) Apply CCXGate. LogNormalDistribution.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. LogNormalDistribution.cnot(control_qubit, …) Apply CXGate. Append rhs to self if self contains compatible registers. LogNormalDistribution.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. LogNormalDistribution.cp(theta, …[, …]) Apply CPhaseGate. LogNormalDistribution.crx(theta, …[, …]) Apply CRXGate. LogNormalDistribution.cry(theta, …[, …]) Apply CRYGate. LogNormalDistribution.crz(theta, …[, …]) Apply CRZGate. LogNormalDistribution.cswap(control_qubit, …) Apply CSwapGate. LogNormalDistribution.csx(control_qubit, …) Apply CSXGate. LogNormalDistribution.cu(theta, phi, lam, …) Apply CUGate. LogNormalDistribution.cu1(theta, …[, …]) Apply CU1Gate. LogNormalDistribution.cu3(theta, phi, lam, …) Apply CU3Gate. LogNormalDistribution.cx(control_qubit, …) Apply CXGate. LogNormalDistribution.cy(control_qubit, …) Apply CYGate. LogNormalDistribution.cz(control_qubit, …) Apply CZGate. LogNormalDistribution.dcx(qubit1, qubit2) Apply DCXGate. Call a decomposition pass on this circuit, to decompose one level (shallow decompose). LogNormalDistribution.delay(duration[, …]) Apply Delay. Return circuit depth (i.e., length of critical path). LogNormalDistribution.diag_gate(diag, qubit) Deprecated version of QuantumCircuit.diagonal. LogNormalDistribution.diagonal(diag, qubit) Attach a diagonal gate to a circuit. LogNormalDistribution.draw([output, scale, …]) Draw the quantum circuit. Append QuantumCircuit to the right hand side if it contains compatible registers. LogNormalDistribution.fredkin(control_qubit, …) Apply CSwapGate. Take in a QASM file and generate a QuantumCircuit object. Take in a QASM string and generate a QuantumCircuit object. Apply HGate. LogNormalDistribution.hamiltonian(operator, …) Apply hamiltonian evolution to to qubits. Test if this circuit has the register r. Apply IGate. Apply IGate. LogNormalDistribution.initialize(params, qubits) Apply initialize to circuit. Invert (take adjoint of) this circuit. LogNormalDistribution.iso(isometry, q_input, …) Attach an arbitrary isometry from m to n qubits to a circuit. LogNormalDistribution.isometry(isometry, …) Attach an arbitrary isometry from m to n qubits to a circuit. LogNormalDistribution.iswap(qubit1, qubit2) Apply iSwapGate. LogNormalDistribution.mcmt(gate, …[, …]) Apply a multi-control, multi-target using a generic gate. Apply MCPhaseGate. LogNormalDistribution.mcrx(theta, …[, …]) Apply Multiple-Controlled X rotation gate LogNormalDistribution.mcry(theta, …[, …]) Apply Multiple-Controlled Y rotation gate LogNormalDistribution.mcrz(lam, q_controls, …) Apply Multiple-Controlled Z rotation gate LogNormalDistribution.mct(control_qubits, …) Apply MCXGate. Apply MCU1Gate. LogNormalDistribution.mcx(control_qubits, …) Apply MCXGate. LogNormalDistribution.measure(qubit, cbit) Measure quantum bit into classical bit (tuples). Adds measurement to all non-idle qubits. LogNormalDistribution.measure_all([inplace]) Adds measurement to all qubits. DEPRECATED: use circuit.reverse_ops(). LogNormalDistribution.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. LogNormalDistribution.p(theta, qubit) Apply PhaseGate. LogNormalDistribution.power(power[, …]) Raise this circuit to the power of power. LogNormalDistribution.qasm([formatted, filename]) 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. LogNormalDistribution.r(theta, phi, qubit) Apply RGate. LogNormalDistribution.rcccx(control_qubit1, …) Apply RC3XGate. LogNormalDistribution.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. LogNormalDistribution.rx(theta, qubit[, label]) Apply RXGate. LogNormalDistribution.rxx(theta, qubit1, qubit2) Apply RXXGate. LogNormalDistribution.ry(theta, qubit[, label]) Apply RYGate. LogNormalDistribution.ryy(theta, qubit1, qubit2) Apply RYYGate. LogNormalDistribution.rz(phi, qubit) Apply RZGate. LogNormalDistribution.rzx(theta, qubit1, qubit2) Apply RZXGate. LogNormalDistribution.rzz(theta, qubit1, qubit2) Apply RZZGate. Apply SGate. Apply SdgGate. Returns total number of gate operations in circuit. LogNormalDistribution.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. LogNormalDistribution.squ(unitary_matrix, qubit) Decompose an arbitrary 2*2 unitary into three rotation gates. LogNormalDistribution.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. LogNormalDistribution.u(theta, phi, lam, qubit) Apply UGate. LogNormalDistribution.u1(theta, qubit) Apply U1Gate. LogNormalDistribution.u2(phi, lam, qubit) Apply U2Gate. LogNormalDistribution.u3(theta, phi, lam, qubit) Apply U3Gate. LogNormalDistribution.uc(gate_list, …[, …]) Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. LogNormalDistribution.ucrx(angle_list, …) Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit. LogNormalDistribution.ucry(angle_list, …) Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit. LogNormalDistribution.ucrz(angle_list, …) Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit. LogNormalDistribution.unitary(obj, qubits[, …]) Apply unitary gate to q. Return number of qubits plus clbits in circuit. LogNormalDistribution.x(qubit[, label]) Apply XGate. Apply YGate. Apply ZGate. Return indexed operation. Return number of operations in circuit.