Git Product home page Git Product logo

classiq / classiq-library Goto Github PK

View Code? Open in Web Editor NEW
310.0 6.0 276.0 93.16 MB

The Classiq Library is the largest collection of quantum algorithms and applications. It is the best way to explore quantum computing software. We welcome community contributions to our Library ๐Ÿ™Œ

Home Page: https://platform.classiq.io

License: MIT License

Jupyter Notebook 99.99% Python 0.01%
quantum-algorithms quantum-software quantum-applications quantum-open-source quantum-optimization quantum-synthesis quantum-compiler quantum-machine-learning

classiq-library's People

Contributors

abdullahkazi500 avatar adam-godel avatar adrabi-abderrahim avatar alexandre-ricardo avatar amir-naveh avatar arielsmoler avatar aswkok avatar bathaee avatar bill-wisotsky avatar bogachana avatar classiqdor avatar clausia avatar cvanbommel avatar giacomoranieri avatar henryafangideh avatar ilie-cristi avatar infi-dos avatar joalgago avatar jyotiraj-code avatar mnshmnsh avatar nadav138 avatar philomathysicist avatar priyabratabag avatar qcmp34 avatar qubit1718 avatar samyak3690 avatar smml1996 avatar talicohn avatar tomergoldfriend avatar vivanwin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

classiq-library's Issues

Quantum Algorithm Zoo: Fast Quantum Algorithm for Numerical Gradient Estimation

In this issue, we will create an implementation of the following paper: Fast Quantum Algorithm for Numerical Gradient Estimation.
This tutorial should follow the structure of the Deutsch Jozsa algorithm implementationl.
Once finished, the implementation will be added to the Quantum Algorithm Zoo, and of course credit will be given to the implementor.

To complete this issue, follow these steps:

  1. Read the following paper: Fast Quantum Algorithm for Numerical Gradient Estimation.
  2. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  3. Use Classiq's SDK to create a simple implementation of the paper, and showcase the results. If you have any implementation questions or challenges, the Classiq team will assist you, either on Github or in our slack community. Follow the Deutsch Jozsa algorithm implementation example for the structure of the notebook.
  4. Create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX. You can view the source or the superposition notebook to see how this is done. Chat GPT is an excellent LaTeX assistant.
  5. After creating the notebook, make sure you insert the write_qmod(model, "bell_state.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  6. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  7. Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/advanced_examples/natural_gradient_estimation

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Add an Hybrid HHL notebook

In this issue, we will create an implementation of a hybrid HHL algorithm, following the ideas that appeared in Ref. [1]. The algorithm is based on the basic HHL algorithm for solving a set of linear equation, where the eigenvalue inversion part is relaxed by feeding-forward eigenvalue approximation from a QPE routine. The algorithm consists of three parts: (1) QPE, (2) classical signal post-prosseing, and (3) matrix inversion (HHL) with known eigenvalues.

This tutorial should follow the structure of the Deutsch Jozsa algorithm implementation, and take into account the technical comments outlined below.

To complete this issue, follow these steps:

  1. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  2. Use Classiq's SDK to create a simple implementation of the hybrid HHL approach, and showcase the results (see technical comments below). If you have any implementation questions or challenges, the Classiq team will assist you, either on Github or in our slack community.
  3. Create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX.
  4. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  5. Add the notebook to a new directory classiq-library/community/advanced_examples/hybrid_hhl/.
  6. Follow the contribution guidelines to open a pull request.

Technical comments:

  • The showcase should be for a generic random matrix, or an applicative use-case, and not for a matrix whose eigenvalues have an exact binary representation (as was done in Ref. [1]).
  • Consider the following (optional):
    • Demonstrating for a small matrix and use an exact Hamiltonian evolution (using the built-in unitary function) instead of an approximated one (e.g., Suzuki-Trorrer etc.) to highlight the effect of the hybrid approach.
    • Reducing the QPE accuracy in the third HHL step, with respect to the accuracy in the first QPE step (as discussed in Ref[2]).
    • Exploring different optimization scenarios for the Synthesis.
    • Comparing the results to the textbook HHL approach.

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

References

[1]: Hybrid quantum linear equation algorithm and its experimental test on IBM Quantum Experience
[2]: Hybrid HHL with Dynamic Quantum Circuits on Real Hardware

Quantum Algorithm Zoo: Quantum Counterfeit Coins

In this issue, we will create an implementation of the following paper: Quantum Counterfeit Coin Problems. The algorithm is interesting as it shows a quartic speedup in comparison to the classical case.
This tutorial should follow the structure of the Deutsch Jozsa algorithm implementationl.
Once finished, the implementation will be added to the Quantum Algorithm Zoo, and of course credit will be given to the implementor.

To complete this issue, follow these steps:

  1. Read the following paper: Quantum Counterfeit Coin Problems.
  2. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  3. Use Classiq's SDK to create a simple implementation of the paper, and showcase the results. If you have any implementation questions or challenges, the Classiq team will assist you, either on Github or in our slack community. Follow the Deutsch Jozsa algorithm implementation example for the structure of the notebook.
  4. Create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX. You can view the source or the superposition notebook to see how this is done. Chat GPT is an excellent LaTeX assistant.
  5. After creating the notebook, make sure you insert the write_qmod(model, "bell_state.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  6. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  7. Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/advanced_examples/counterfeit_coins

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Change the Latex use of `\ket{-}` to `|-\rangle` in the phase kickback tutorial

In Jupyter notebooks there is the option to write with Latex in the .md cells. This is very convenient as it allows writing mathemtical expressions in a nice format, e.g. $|\psi \rangle = |0\rangle $. These notebooks are the source for the Classiq documentation. The problem is that for some mathematical expressions written in Latex, the documentation isn't rendered properly. This is the case for the use of \ket{} that is used to represent a ket notation $\ket{}$.

The goal of this issue is to solve this problem for the phase kickback tutorial. That is, to change all the appearances of \ket{} to | followed by \rangle. When rendered in the Jupyter notebook both look the same, but within the corresponding documentation it makes a huge difference.

Please follow the contribution guidelines and adapt the phase_kickback.ipynb notebook so it will contain the correct logic of the ket notation but with the use of | and \rangle instead of \ket{}.

Add another implementation for the "increment" function in the discrete quantum walk tutorial

The tutorial on Discrete Quantum Walks demonstrates an example of a quantum walk on a circle. The quantum_step_clockwise quantum function is implemented as a QFT-adder, however, there are other implementations available for such quantum operation, e.g., by applying a cascade of multi-controlled-X gates.

The goal of this issue is to add another implementation for the quantum_step_clockwise quantum function in the aforementioned tutorial.

Detailed guidelines:

  1. Within the section "Example: Symmetric Quantum Walk on a Circle" in the notebook do the following:
    • Add a text explaining that in this example we will construct an implementation for the "clockwise_step"/"increment" function, which is different from the QFT-based implementation presented above.
    • Add a cell defining a new quantum function with the following declaration: qfunc increment(x: QArray[QBit]).
    • Use the new function in the specific example treated in the section.
    • Modify the synthesis constraints: optimize over depth with a relevant constraint over the width.
  2. Under the "Technical Notes" section, add a short explanation about the implementation.
  3. Make sure to generate a qmod (using the write_qmod function) for the modified example.
  4. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  5. Follow the contribution guidelines to open a pull request.

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Adapt figures in the grover_workshop tutorial

The Grover workshop tutorial is a practice tutorial that should be completed by a user that wants to learn Classiq through a concrete example hands-on. The schematics throughout the tutorial convey the message but are of poor quality. The goal of this issue is to replace the figures in that tutorial with more professional figures that convey the same idea.

In order to complete the issue follow the contribution guidelines and enter your adapted notebook to the directory classiq-library/community/exercises/grover.

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Classiq Basics: Quantum Addition

In this issue, we will create a simple tutorial of quantum addition using Classiq.
This tutorial should follow the structure of the quantum superpostion tutorial:

To complete this issue, follow these steps:

  1. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  2. Use Classiq's SDK to create quantum addition: $|a\rangle|b\rangle|0\rangle^{\otimes n} \rightarrow |a\rangle|b\rangle|a+b\rangle $. So, for example, if $a=\frac{1}{\sqrt{2}}(|1\rangle + |3\rangle)$ and $b = |2\rangle$ the final state should be $|\psi\rangle = \frac{1}{\sqrt{2}}(|1\rangle |2\rangle|3\rangle + |3\rangle|2\rangle|5\rangle)$.
    To do this, you can use the + operator, built in to the QMOD language. Create two registers in an initial state, and add them using the + operator. You can find examples here.
  3. Similar to the superposition notebook, create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX. You can view the source or the superposition notebook to see how this is done. Chat GPT is an excellent LaTeX assistant.
  4. After creating the notebook, make sure you insert the write_qmod(model, "bell_state.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  5. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  6. Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/basic_examples/quantum_addition

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Quantum Algorithm Zoo: Group Isomorphism

In this issue, we will create an implementation of the following paper: Decomposing Finite Abelian Groups. The algorithm can be used to solve the group isomorphism problem, for the Abelian case.
This tutorial should follow the structure of the Deutsch Jozsa algorithm implementationl.
Once finished, the implementation will be added to the Quantum Algorithm Zoo, and of course credit will be given to the implementor.

To complete this issue, follow these steps:

  1. Read the following paper: Decomposing Finite Abelian Groups.
  2. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  3. Use Classiq's SDK to create a simple implementation of the paper, and showcase the results. If you have any implementation questions or challenges, the Classiq team will assist you, either on Github or in our slack community. Follow the Deutsch Jozsa algorithm implementation example for the structure of the notebook.
  4. Create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX. You can view the source or the superposition notebook to see how this is done. Chat GPT is an excellent LaTeX assistant.
  5. After creating the notebook, make sure you insert the write_qmod(model, "bell_state.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  6. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  7. Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/advanced_examples/group_isomorphism

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Quantum algorithm: simplified QVAR algorithm

QVAR algorithm is a quantum algorithm to calculate the variance of dataset.
This algorithm is introduced in the paper https://arxiv.org/pdf/2403.14655.pdf by researchers from Universite of Pisa. This paper is also introducing about the QODA(Quantum Outlier Detection Algorithm) and HFQS(Hybrid Quantum Feature Selection) by utilizing the QVAR algorithm, which can be used in the field of AI(Artificial Interlligence).

QVAR algorithm use 3n+s+1 qubits to get the varianve of dataset length $N(=2^n)$ , where s = $O(log 1/\epsilon )$ is decided in the QAE algorithm to measure the result.

In this issue, I developed the simplified circuit of QVAR with one less set of auxiliary qubits(2n+s+1) than the form of the original QVAR algorithm introduced in the paper(3n+s+1), i.e., with a smaller width. This simplified version remain still logarithmic along with the original QVAR algorithm, so there is no asymptotic advatage, but implementing it in fewer qubits is meaningful for practical applications.

In this algorithm,

  1. The dataset will be encoded into quantum state by normalization and amplitude encoding.
  2. The variance of the encoded dataset will be given through the QVAR algorithm.
  3. Measure the auxiliary qubits.(Or Measure the variance by QAE(Quantum Amplitude Estimation) like as the paper.)
  4. Get the variance by product appropriate coefficient, decided by the length and norm of dataset.

The example will be added under the directory classiq-library/community/basic_examples/qvar.

Refactor the Option Pricing notebook to use classiq constructs

Using quantum computers for pricing financial derivatives has the promise for quadratic speedup.

In this issue we will improve the current option-pricing notebook, implementing algorithm for european call options, based on the paper Option Pricing using Quantum Computers. The goal is to use native language constructs instead of the current construct_finance_model black box function in the existing implementation.

to complete this issue, follow the following steps:

  1. Open the option pricing notebook and go over the code and explanations.
  2. Remove the usage of the construct_finance_model, function_input in the model creation. You will later on use native language functions Instead.
  3. We use a log-normal distribution for the asset. You can use the current parameters, such as num_qubits, mu, sigma, threshold. A bonus is to derive them from financial parameters. Use the prepare_state function on calculated lognormal distribution with the parameters, and some truncation value (5 sigma). This can be computed classically and passed to the prepare_state as an array of probabilities.
  4. For the payoff, use the *= syntax, see amplitude loading example. Pay attention for needed remapping of the variables and normalization, as done in the paper. Here, in difference from the article, the implementation is exact and not approximated.
  5. For the amplitude estimation, you can use the iqae execution scheme, that uses the iterative amplitude estimation, and the built-in grover_operator. See quantum_counting for example.
  6. Verify the execution results of the algorithm with a classical computation. Add assert validation to the code.
  7. Wherever needed, add Markdown cells with explanations and mathematical formulations.
  8. After finishing with the notebook, make sure you keep the write_qmod(qmod, "option_pricing.qmod") line. Run the notebook, and you will automatically update the .qmod file for this example.
  9. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  10. Follow the contribution guidelines to open a pull request.

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Quantum Algorithm Zoo: Estimating Partition Functions

In this issue, we will create an implementation of a quantum algorithm for estimating partition function. We will implement algorithm described in the paper: Quantum speedup of Monte Carlo methods.
This tutorial should follow the structure of the Deutsch Jozsa algorithm implementation.
Once finished, the implementation will be added to the Quantum Algorithm Zoo, and of course credit will be given to the implementor.

To complete this issue, follow these steps:

  1. Read the following paper: Quantum speedup of Monte Carlo methods
    ](https://arxiv.org/abs/1504.06987).
  2. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  3. Use Classiq's SDK to create a simple implementation of the paper, and showcase the results. You can estimate the partition function of a chosen ferromagnetic model, or a different problem if you desire. If you have any implementation questions or challenges, the Classiq team will assist you, either on Github or in our slack community. Follow the Deutsch Jozsa algorithm implementation example for the structure of the notebook.
  4. Create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX. You can view the source or the superposition notebook to see how this is done. Chat GPT is an excellent LaTeX assistant.
  5. After creating the notebook, make sure you insert the write_qmod(model, "partition_function.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  6. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  7. Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/advanced_examples/partition_function

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Quantum Algorithm Zoo: Adiabatic Quantum Computation

In this issue, we will create an implementation of the adiabatic quantum evolution algorithm. Specifically, we will use it for the Graph Isomorphism Problem, following the paper: Graph isomorphism and adiabatic quantum computing.
This tutorial should follow the structure of the Deutsch Jozsa algorithm implementationl.
Once finished, the implementation will be added to the Quantum Algorithm Zoo, and of course credit will be given to the implementor.

To complete this issue, follow these steps:

  1. Read the following paper: Graph isomorphism and adiabatic quantum computing.
  2. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  3. Use Classiq's SDK to create a simple implementation of the paper, and showcase the results. If you have any implementation questions or challenges, the Classiq team will assist you, either on Github or in our slack community. Follow the Deutsch Jozsa algorithm implementation example for the structure of the notebook.
  4. Create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX. You can view the source or the superposition notebook to see how this is done. Chat GPT is an excellent LaTeX assistant.
  5. After creating the notebook, make sure you insert the write_qmod(model, "adiabatic.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  6. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  7. Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/advanced_examples/adiabatic_computation

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Certain LaTeX and images failing to render on Classiq docs

Hello, I noticed that on many algorithm pages in the Classiq documentation, certain LaTeX expressions wrapped with $$ do not render properly, even if they render properly in their respective Jupyter notebook in the Classiq library. In addition, certain images are unable to render in the Classiq documentation.

A few examples of this are the first figure in the Introduction section and the matrices in the Quantum Algorithm section on the Glued Trees page, most of the LaTeX in the Technical Notes section on the Deutsch-Jozsa page, and much of section 3 of the HHL page.

I hope to see a fix to this issue soon!

Pyomo required by classiq is obsolete

Version

  • Python-3.12.1
  • classiq-0.9.3
  • Pyomo-6.0.1

How to replicate this problem

I created a conda environment (Python 3.12.1) and installed classiq (0.9.3).

$ pip install classiq
...
$ python3
>>> import classiq
...
.../lib/python3.12/site-packages/pyomo/core/base/component.py", line 427, in __getstate__
    state[key] = val
    ~~~~~^^^^^
TypeError: 'tuple' object does not support item assignment
>>>
  • This issue is not found in my older environment with Python 3.11.4.
  • I found a similar issue Issues #2600 is resolved by Pyomo team.

I have tried to force update the Pyomo package to 6.7.1, and imported classiq successfully with only a few deprecation warnings. I wonder this will break anything important.

$ pip install --force pyomo
...
$ python3
>>> import classiq
WARNING: DEPRECATED: the 'EqualityExpression' class has been moved to
'pyomo.core.expr.relational_expr.EqualityExpression'.  Please update your
import.  (deprecated in 6.4.3) (called from <frozen importlib._bootstrap>:488)
WARNING: DEPRECATED: the 'InequalityExpression' class has been moved to
'pyomo.core.expr.relational_expr.InequalityExpression'.  Please update your
import.  (deprecated in 6.4.3) (called from <frozen importlib._bootstrap>:488)
>>>

My suggestion

  • Update the import code and requirements.txt.
  • Use GitHub Actions to make sure mainstream versions can operate without problems.

Portfolio Optimization

Using https://github.com/Classiq/classiq-library/blob/main/applications/finance/portfolio_optimization/portfolio_optimization.ipynb as-is in Google Colab I'm getting:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-8-1a7f624b202c>](https://localhost:8080/#) in <cell line: 1>()
----> 1 from classiq import construct_combinatorial_optimization_model
      2 from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig
      3 
      4 qaoa_config = QAOAConfig(num_layers=1)

8 frames
[/usr/local/lib/python3.10/dist-packages/pyomo/core/expr/current.py](https://localhost:8080/#) in <module>
     35     from pyomo.core.expr import numeric_expr as _numeric_expr
     36     from .base import ExpressionBase
---> 37     from pyomo.core.expr.numeric_expr import (_add, _sub, _mul, _div, _pow,
     38                                               _neg, _abs, _inplace, _unary,
     39                                               NumericExpression,

ImportError: cannot import name '_add' from 'pyomo.core.expr.numeric_expr' (/usr/local/lib/python3.10/dist-packages/pyomo/core/expr/numeric_expr.cpython-310-x86_64-linux-gnu.so)

Create a basic tutorial for running a VQE primitive with Classiq

The variational quantum eigensolver (VQE) is arguably the most common variational quantum algorithm. As every other quantum algorithm, it can be done easily with Classiq. The goal of this issue is to demonstrate this.

You should create a Jupyter Notebook that implements the same basic VQE algorithm that is demonstrated in this video from the Classiq Bootcamp 2023. NOTE this video follows an old version of Classiq that is not supported anymore, but the idea behind it remains the same.

Concretely, your algorithm should find the minimal energy of the Hamiltonian Z+0.1X where Z and X are the Pauli operators, and the ansatz you should use is a simple RY gate.

You can use theexplanation about the Classiq primitives in the user guide for your help. In addition, feel free to use the Classiq Slack community for any question and help.

In order to complete the issue follow the contribution guidelines and enter your adapted notebook to the directory classiq-library/community/basic_examples/vqe.

Happy quantum coding!

Refactor the HHL notebook to follow the "Algorithms" structure

The goal of this issue is to standardize the HHL notebook to follow a specific structure, to improve its visibility and usability.

There is a general initiative to standardize the algorithms directory, putting all notebooks in a specific template. The fixed structure of the notebook allows to deliver the main idea of the algorithm, as well as the rational of high-level modelling with Classiq. Examples can be seen in: Deutsch Jozsa, Bernstein Vazirani, and Simon algorithms notebooks.

In this issue the HHL notebook should be rewritten to have the following structure:

  • The title should be the name of the algorithm.
  • Below the title a short explanation of the algorithm, including its input, promise, and output. Include a figure of the algorithm blocks.
  • The sections structure is:
    1. "How to Build the Algorithm with Classiq"
      1.1. "The quantum part" (include all quantum functions)
      1.2. "The classical postprocess" (include all classical post-processing functions)
    2. "Example: exact Hamiltonian evolution"
    3. "Example: approximated Hamiltonian evolution"
    4. "Technical notes"

Further guidelines:

  • Go over the already standardized examples mentioned above, to understand the aimed structure of the notebook.
  • Heavy technical explanations should be moved to section 4.
  • Section 1.1 should include an hhl qfunc whose declaration is hhl( rhs_vector: CArray[float], precision: CInt, hamiltonian_evolution_with_power: QCallable[CInt, QArray[QBit]], res: Output[QArray[QBit]], indicator: Output[QBit]).
  • Section 1.2 should include a pythonic function that gets the execution results and returns the solution vector for the linear equation.
  • Section 2 should include defining the Hamiltonian evolution with Classiq's unitary built-in function.
  • Section 3 should include the decomposition of a matrix to the Pauli basis and the definition of a specific Hamiltonian evolution with Classiq's suzuki-trotter built-in function.
  • Make sure to generate a qmod (using the write_qmod function) for the two different examples.
  • Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  • Follow the contribution guidelines to open a pull request.

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Womanium Final Assignment - Karan Islur

Algorithm for creating the quantum walk operator for the case of a circle with 4 nodes, and design the quantum walk operator for the case of a line with 16 nodes:.

Optimize Quantum Discrete Logarithm Algorithm Implementation in the "discrete_log.ipynb" file

Description
Optimize the implementation of the code. The suggested changes includes better variable naming, type annotations and code structure improvements

** Type of change**
Please delete options that are not relevant.

  • Refactored variable names for clarity and consistency
  • Added type annotations for function parameters and return types
  • Checked for potential optimizations in quantum and classical operations
  • Added error handling mechanisms for better reliability
from classiq.qmod import (
    CInt,
    Output,
    QArray,
    QBit,
    QNum,
    allocate,
    inplace_prepare_int,
    modular_exp,
    qfunc,
    hadamard_transform,
    invert,
    qft,
    Constraints,
    create_model,
    write_qmod,
    Preferences,
    show,
    synthesize,
    execute,
)

We can import all at once instead of importing multiple times

from math import ceil, log

We can also use ceiling and log from math

MODULUS_NUM = 5
BASE = 3
EXPONENT = 2
MODULUS_ORDER = MODULUS_NUM - 1

We can maintain consistency by using variable names like these

def discrete_log_oracle(
    base: CInt,
    exponent: CInt,
    modulus: CInt,
    order: CInt,
    x1: QArray[QBit],
    x2: QArray[QBit],
    func_res: Output[QArray[QBit]],
) -> None:
    reg_len = ceil(log(modulus, 2))
    allocate(reg_len, func_res)
    inplace_prepare_int(1, func_res)
    modular_exp(modulus, exponent, func_res, x1)
    modular_exp(modulus, base, func_res, x2)

We can improve the functions for better code readability like this.

Add initial conditions to the arithmetic example in the arithmetic_expressions notebook

The Arithmetic Expressions notebook demonstrates the capabilities of the Classiq's synthesis engine, in the framework of quantum arithmetics. The notebook shows a single quantum model, consisting a complex arithmetic expression, and synthesizes it with two different optimization scenarios.

The example in the notebook does not include an execution of the resulting quantum programs. Moreover, execution of the current example will result in a non-indicative measurement, as the arithmetic expression operates on two quantum variables, x and y, which are initialized to the zero state, and the result of the expression is trivial.

The goal of this issue is to add initial conditions and execution to the arithmetic_expressions notebook.
To complete this issue, follow these steps:

  1. Open the Arithmetic Expressions notebook, using any jupyter editor (e.g. jupyter lab, google colab, etc).
  2. In the quantum model, replace the allocate calls for the quantum numbers x and y with appropriate prepare_int calls.
  3. For the two quantum programs in the notebook, add an execute call, print the results and compare to the expected result.
  4. Make sure to run the write_qmod line, which will automatically update the .qmod files for this example.
  5. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  6. Follow the contribution guidelines to open a pull request.
  7. Commit all the files changed under the tutorials/technology_demonstrations/arithmetic_expressions/ directory.
  8. If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Quantum Algorithm Zoo: Quantum Group Testing

In this issue, we will create an implementation of the following paper: Efficient Quantum Algorithms
for (Gapped) Group Testing and Junta Testing
. The problem is interesting as for some cases in group testing, there is a proven quartic speedup, which is quite unusual among quantum algorithms.

The tutorial should follow the structure of the Deutsch Jozsa algorithm implementation.
Once finished, the implementation will be added to the Quantum Algorithm Zoo, and of course credit will be given to the implementor.

To complete this issue, follow these steps:

  1. Read the following paper: Efficient Quantum Algorithms for (Gapped) Group Testing and Junta Testing. You can pick one of the problems in the paper, such as the QGGT, to solve in the tutorial.
  2. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  3. Use Classiq's SDK to create a simple implementation of the problem, and showcase the results. If you have any implementation questions or challenges, the Classiq team will assist you, either on Github or in our slack community. Follow the Deutsch Jozsa algorithm implementation example for the structure of the notebook.
  4. Create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX. You can view the source or the superposition notebook to see how this is done. Chat GPT is an excellent LaTeX assistant.
  5. After creating the notebook, make sure you insert the write_qmod(model, "group_testing.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  6. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  7. Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/advanced_examples/group_testing

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Add examples and insights that demonstrates Classiq's HW-aware synthesis capability

In this issue, we will add practical examples to demonstrate Classiq's Hardware-Aware Synthesis capability.

Quantum computers differ from one other in many significant parameters, such as basis gates, connectivity, and error rates. The device specifications determine the possibility of executing the quantum program, and logically equivalent programs might require different implementations to optimize the probability of success.

The Classiq platform allows you to provide information about the hardware you want to use to run your quantum program. The synthesis engine takes the parameters of this hardware into account. For example, the engine could choose the implementation of a function that requires the least number of swaps, given the connectivity of the hardware.

In this issue we will synthesize a simple MCX circuit with at least 2 different HW-aware configuration settings and examine the differences in their implementations.

To complete this issue, follow these steps:

  1. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  2. Similar to the HW-aware Synthesis of MCX notebook, create a new notebook that implements a multiple control-x (MCX) logic and sets 2 different HW-aware synthesis preferences configurations (other than the ones used in the notebook linked above).
  3. Synthesize your MCX circuit with the 2 HW-aware synthesis preferences, view the implementation result and write a short paragraph with your insights.
  4. After creating the notebook, make sure you insert the write_qmod(model, "hardware_aware_YOUR_CONFIGURATION_NAME.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  5. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.

Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/basic_examples/hw_aware_synthesis

Modify the mcx function to include a ctrl_state parameter,

Currently, the mcx function in the classiq quantum circuit library lacks the ability to specify the control state for the multi-controlled X gate explicitly. This limits flexibility in certain quantum algorithm implementations and hardware optimization scenarios where controlling qubits in states other than '1' is advantageous.

Proposed Change:
Modify the mcx function to include a ctrl_state parameter, enabling users to specify the control state of the multi-controlled X gate. This parameter should accept values such as decimal integers or bitstrings (e.g., '1', '0', '01'), defaulting to controlling the '1' state if not provided explicitly.

Expected Behavior:
Upon calling the mcx function, users can pass the ctrl_state parameter to specify the desired control state configuration for the multi-controlled X gate. This enhancement will broaden the functionality of the mcx function, allowing for more precise control over quantum operations and optimizations.

Implementation Details:
Function Modification: Update the mcx function to accept the ctrl_state parameter.
Parameter Handling: Ensure the function correctly interprets and utilizes the ctrl_state parameter, integrating it into the construction of the multi-controlled X gate.
Backward Compatibility: Maintain compatibility with existing usage patterns of the mcx function while introducing the new parameter for enhanced functionality.

@TomerGoldfriend let me know

Classiq Basics: Quantum Entanglement

In this issue, we will create a simple tutorial of quantum entanglement using Classiq.
This tutorial should follow the structure of the quantum superpostion tutorial:
To complete this issue, follow these steps:

  1. Create a new jupyter notebook (.ipynb file). Use any jupyter editor (e.g. jupyter lab, google colab, etc).
  2. Use Classiq's SDK to create the bell state: $|\psi\rangle = \frac{1}{\sqrt{2}} (|00\rangle + |11\rangle) $. To do this, apply a $H$ (Hadamard) gate to one qubit, and then apply a $CX$ gate controlled on the qubit in superposition.
  3. Similar to the superposition notebook, create a short mathematical explanation of the work. Jupyter notebooks support markdown cells, which can contain LaTeX. You can view the source or the superposition notebook to see how this is done. Chat GPT is an excellent LaTeX assistant.
  4. After creating the notebook, make sure you insert the write_qmod(model, "bell_state.qmod") line. Run the notebook, and you will automatically generate the .qmod file for this example.
  5. Make sure the notebook looks well, does not have any typos / mistakes, and is running properly.
  6. Follow the contribution guidelines to open a pull request. Submit the tutorial to the directory: classiq-library/community/basic_examples/entanglement

If you have any questions or comments, you can ask them here in the issue, or in our slack community, and the Classiq team will be happy to assist.

Happy quantum coding!

Error: 'classiq' not found on import

I use Lubuntu and have created a virtual environment on it. Within this environment, I launched Jupyter Lab. In one of the cells, I executed "!pip install -U classiq", and the installation indicated "success". However, when I attempted to execute "import classiq", I encountered an error stating that "classiq" could not be found.

Here's how I solved this problem:

  1. Execute "!pip show classiq" to check the installation details.
  2. Import the sys module with "import sys".
  3. Print the list of paths with "print(sys.path)".

The issue was that the path listed under "Location" in step 1 wasn't inclueded in the paths from step 3. To resolve this, I added the following line:

  1. "sys.path.append('<Path from the Location in step 1>')"

This solution worked well for me, and I hope it can help others facing a similar issue.

Controlled Increment and Decrement Gates

Description
The current quantum computing framework lacks built-in functionalities for performing controlled increment and decrement operations on quantum registers. These operations are essential for various quantum algorithms and simulations.

Proposed Solution
Introduce two new gates:

Controlled Increment Gate (increment function):
This gate performs a controlled increment operation on a quantum register.
Iterates over each qubit in the register, applying multi-controlled Toffoli gates to increment the binary number by 1.
Controlled Decrement Gate (decrement function):
This gate performs a controlled decrement operation on a quantum register.
Iterates over each qubit in the register, applying multi-controlled Toffoli gates to decrement the binary number by 1.
Operation Details
Controlled Increment Gate (increment function):

Iterates over each qubit in the register qr (from least significant to second-to-last qubit).
For each qubit qr[j]:
Apply a multi-controlled Toffoli gate with controls from qr[0] to qr[j], targeting qr[j+1].
Controlled Decrement Gate (decrement function):

Iterates over each qubit in the register qr (from least significant to second-to-last qubit).
For each qubit qr[i]:
Apply a multi-controlled Toffoli gate with controls from qr[0] to qr[i], targeting qr[i+1].
Motivation
These gates are fundamental for implementing quantum arithmetic operations and can significantly enhance the capabilities of the quantum computing framework for algorithm development and simulations.

Additional Notes
Ensure the gates are implemented efficiently using multi-controlled Toffoli gates (mct gates).
Consider compatibility with various quantum simulators and hardware platforms supported by the framework.
Proposed Changes
Implement the increment(qc, qr) function to perform a controlled increment operation on the quantum register qr.
Implement the decrement(qc, qr) function to perform a controlled decrement operation on the quantum register qr.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.