# Thinking Outside the Box on State Preparations - Using Classiq to Generate Log-Normal Distribution Circuits of Depth 1

This note illustrates how to utilize the Classiq platform to solve the Log-Normal State preparation problem from our recent coding competition. We examine two methods for generating this state preparation as well as the trick necessary for generating a state preparation with a circuit depth of 1.

## Step-1 for All Quantum Algorithms

State preparations are an integral part to quantum computation, with almost all quantum applications beginning with the preparation of a state in a quantum register. In finance, for example, the state may represent the price distribution of certain assets as part of a portfolio optimization algorithm. In chemistry, it may be an initial estimate for the ground state of a molecule, and in quantum machine learning, it is the feature vector to be analyzed.

State preparation is the initialization of qubits with quantum gates so that their measured output corresponds to a desired probability distribution. This initialized state can then be utilized by subsequent quantum circuits to perform calculations. The Log-Normal State preparation we'll discuss is a commonly used initialized state in many finance calculations.

## The Log-Normal State Preparation Problem

In our recent coding competition, competitors were asked to design a circuit that generates a log-normal distribution with a mean (µ) of 0 and standard deviation (σ) of 0.1 using no more than 10 qubits. The circuit must approximate a log-normal distribution with an error of no more than 0.01 and can only contain 'u' and 'CX' gates. The winning entry would be the circuit with the shallowest depth while meeting all of the aforementioned criteria.

This problem was both the most difficult to solve and the simplest quantum circuit to compute of the four competition problems we designed. To provide our competitors with a hint on how to approach this problem, we required them to submit both the quantum circuit and the discretization method they employed.

## Solving State Preparations with Classiq

To generate a state preparation with Classiq, we invoke the "StatePreparation" function and specify the circuit's probabilities, qubit count, and upper error bound. We know that the maximum number of qubits is 10, that we need to input a log-normal distribution, and that the total error of the circuit (the mathematical error in approximating a log-normal distribution plus the error in translating it to a quantum circuit) should not exceed 0.01. Once these few parameters are defined, the Classiq platform will implement the quantum circuit. It's as simple as that; below is the code to generate this circuit using Classiq's Python SDK, though an equivalent circuit can be generated with the Classiq extension in Visual Studio Code.

The key to solving this problem lies in one's approach to implementing this distribution. The straightforward and simple solution to this problem is to select a subset of the domain centered on the mean of the distribution, evenly space our discretization across the available bins within this area (with 10 qubits, we have 2^{10} bins), and disregard the remainder of the domain. The probabilities within these 2^{10} bins of our domain subset can then be modified to match a log-normal distribution. Defining our circuit requires only loading this probability mass function into the Classiq platform and selecting our error threshold. Following this method, the Classiq platform (using version 0.15) implemented a **242-depth circuit** for us. The interactive circuit below can be found here.

## The Trick

However, there is another approach to this. Two parameters can be set when performing a state preparation: the probabilities to be loaded and the discretization method used to calculate the results. The previous method's discretization utilized a standard, linear-spacing, for its discretization. Doing so necessitated that we load in probabilities to match the desired log-normal distribution.

So, what would occur if a non-linear discretization spacing was chosen? By selecting the spacing for our 2^{10} bins intelligently, we can set up a circuit where all of the loaded probabilities are identical. This may make subsequent calculations for this quantum circuit difficult, but it would make setting up the state preparation trivial. We can now freely select the measurement basis for our qubits and prepare them all with the same probability in this basis. If we select the $|+\rangle$ basis, for instance, we can prepare all of our qubits with Hadamard gates, resulting in a circuit with a depth of 1, seen below and available here.

We were pleased to see that the winners of this competition problem were able to identify this trick, each employing their own discretization selection method. This problem exists to demonstrate that it takes more than technical knowledge to generate efficient quantum circuits; creativity is also required when generating efficient quantum circuits. To generate our discretization, we define two functions: one to calculate the L2 error and the other to generate the discretization in consideration of the L2 error. Our code has been added below.

To see how this compares to the solutions provided by competitors, see here.

## Beyond Log-Normal Distributions

Classiq makes creating a state preparation simple. Define the probabilities in which you want your circuit to be initiated, and the platform will take care of the rest. Classiq enables the flexible definition of probabilities as either a probability mass function or a gaussian mixture and provides multiple methods for defining the allowed error for the circuit, such as KL, L1, L2, Maximum Probability, and Loss of Fidelity. Here is an example of Classiq used to implement a state preparation using Gaussian moments, and here is an example of a Credit Risk Analysis algorithm using a Gaussian moment for its state preparation.

Classiq's state preparation is flexible, easy to program, and generates your desired circuit automatically, whether you're replicating the findings of an academic paper or creating novel quantum algorithms. As we say at Classiq, "defining what you want is easy, but implementing it is difficult." So, let the Classiq platform implement your defined circuits. Classiq customers work at a higher level. Specify the desired functionality of the circuit as well as the applicable constraints, and the Classiq platform automatically finds the right implementation from billions of design space options.

Schedule a live demonstration of the Classiq platform to see it in action, or contact us to learn how you can create industry-leading quantum circuits in minutes.

This note illustrates how to utilize the Classiq platform to solve the Log-Normal State preparation problem from our recent coding competition. We examine two methods for generating this state preparation as well as the trick necessary for generating a state preparation with a circuit depth of 1.

## Step-1 for All Quantum Algorithms

State preparations are an integral part to quantum computation, with almost all quantum applications beginning with the preparation of a state in a quantum register. In finance, for example, the state may represent the price distribution of certain assets as part of a portfolio optimization algorithm. In chemistry, it may be an initial estimate for the ground state of a molecule, and in quantum machine learning, it is the feature vector to be analyzed.

State preparation is the initialization of qubits with quantum gates so that their measured output corresponds to a desired probability distribution. This initialized state can then be utilized by subsequent quantum circuits to perform calculations. The Log-Normal State preparation we'll discuss is a commonly used initialized state in many finance calculations.

## The Log-Normal State Preparation Problem

In our recent coding competition, competitors were asked to design a circuit that generates a log-normal distribution with a mean (µ) of 0 and standard deviation (σ) of 0.1 using no more than 10 qubits. The circuit must approximate a log-normal distribution with an error of no more than 0.01 and can only contain 'u' and 'CX' gates. The winning entry would be the circuit with the shallowest depth while meeting all of the aforementioned criteria.

This problem was both the most difficult to solve and the simplest quantum circuit to compute of the four competition problems we designed. To provide our competitors with a hint on how to approach this problem, we required them to submit both the quantum circuit and the discretization method they employed.

## Solving State Preparations with Classiq

To generate a state preparation with Classiq, we invoke the "StatePreparation" function and specify the circuit's probabilities, qubit count, and upper error bound. We know that the maximum number of qubits is 10, that we need to input a log-normal distribution, and that the total error of the circuit (the mathematical error in approximating a log-normal distribution plus the error in translating it to a quantum circuit) should not exceed 0.01. Once these few parameters are defined, the Classiq platform will implement the quantum circuit. It's as simple as that; below is the code to generate this circuit using Classiq's Python SDK, though an equivalent circuit can be generated with the Classiq extension in Visual Studio Code.

The key to solving this problem lies in one's approach to implementing this distribution. The straightforward and simple solution to this problem is to select a subset of the domain centered on the mean of the distribution, evenly space our discretization across the available bins within this area (with 10 qubits, we have 2^{10} bins), and disregard the remainder of the domain. The probabilities within these 2^{10} bins of our domain subset can then be modified to match a log-normal distribution. Defining our circuit requires only loading this probability mass function into the Classiq platform and selecting our error threshold. Following this method, the Classiq platform (using version 0.15) implemented a **242-depth circuit** for us. The interactive circuit below can be found here.

## The Trick

However, there is another approach to this. Two parameters can be set when performing a state preparation: the probabilities to be loaded and the discretization method used to calculate the results. The previous method's discretization utilized a standard, linear-spacing, for its discretization. Doing so necessitated that we load in probabilities to match the desired log-normal distribution.

So, what would occur if a non-linear discretization spacing was chosen? By selecting the spacing for our 2^{10} bins intelligently, we can set up a circuit where all of the loaded probabilities are identical. This may make subsequent calculations for this quantum circuit difficult, but it would make setting up the state preparation trivial. We can now freely select the measurement basis for our qubits and prepare them all with the same probability in this basis. If we select the $|+\rangle$ basis, for instance, we can prepare all of our qubits with Hadamard gates, resulting in a circuit with a depth of 1, seen below and available here.

We were pleased to see that the winners of this competition problem were able to identify this trick, each employing their own discretization selection method. This problem exists to demonstrate that it takes more than technical knowledge to generate efficient quantum circuits; creativity is also required when generating efficient quantum circuits. To generate our discretization, we define two functions: one to calculate the L2 error and the other to generate the discretization in consideration of the L2 error. Our code has been added below.

To see how this compares to the solutions provided by competitors, see here.

## Beyond Log-Normal Distributions

Classiq makes creating a state preparation simple. Define the probabilities in which you want your circuit to be initiated, and the platform will take care of the rest. Classiq enables the flexible definition of probabilities as either a probability mass function or a gaussian mixture and provides multiple methods for defining the allowed error for the circuit, such as KL, L1, L2, Maximum Probability, and Loss of Fidelity. Here is an example of Classiq used to implement a state preparation using Gaussian moments, and here is an example of a Credit Risk Analysis algorithm using a Gaussian moment for its state preparation.

Classiq's state preparation is flexible, easy to program, and generates your desired circuit automatically, whether you're replicating the findings of an academic paper or creating novel quantum algorithms. As we say at Classiq, "defining what you want is easy, but implementing it is difficult." So, let the Classiq platform implement your defined circuits. Classiq customers work at a higher level. Specify the desired functionality of the circuit as well as the applicable constraints, and the Classiq platform automatically finds the right implementation from billions of design space options.

Schedule a live demonstration of the Classiq platform to see it in action, or contact us to learn how you can create industry-leading quantum circuits in minutes.

## About "The Qubit Guy's Podcast"

Hosted by The Qubit Guy (Yuval Boger, our Chief Marketing Officer), the podcast hosts thought leaders in quantum computing to discuss business and technical questions that impact the quantum computing ecosystem. Our guests provide interesting insights about quantum computer software and algorithm, quantum computer hardware, key applications for quantum computing, market studies of the quantum industry and more.

If you would like to suggest a guest for the podcast, please contact us.