Giter Club home page Giter Club logo

classiq / classiq-library Goto Github PK

View Code? Open in Web Editor NEW
292.0 8.0 111.0 31.51 MB

The Classiq Library is the largest collection of quantum algorithms, 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.98% Python 0.02%
quantum-algorithms quantum-software quantum-applications quantum-open-source quantum-optimization quantum-synthesis quantum-compiler quantum-machine-learning

classiq-library's Introduction

Version PyPI - Python Version

Classiq

Your entry-point for creating & running quantum programs.

This repository holds a wide collection of quantum functions, algorithms, applications and tutorials built with Classiq.



โ€ƒ โš›๏ธ Platform โ€ƒ|โ€ƒ ๐Ÿ‘‹ Join Slack โ€ƒ|โ€ƒ ๐Ÿ“– Documentation โ€ƒ | โ€ƒ Getting Started โ€ƒ


Installation

Working with Classiq's latest GUI requires no installations! Just head over to Classiq's platform and follow the examples below over there :)

If you'd rather work programmatically, using Python, Classiq also provides an SDK, which can be installed as follows:

pip install classiq

Please note that the latest Classiq SDK for Python doesn't work in Python 3.12 yet. Please refer to Issue #17.

Running This Repository's Demos

This repository has 2 kinds of demos: .qmod and .ipynb.

The .qmod files are intended for usage with Classiq's platform. Upload those .qmod files into the Synthesis tab

The .ipynb files are intended to be viewed inside JupyterLab.

Create Quantum Programs with Classiq

The simplest quantum circuit has 1 qubit, and has a single X gate.

Using Classiq's SDK, it would like like so:

from classiq import *

NUM_QUBITS = 1


@qfunc
def main(res: Output[QBit]):
    allocate(NUM_QUBITS, res)
    X(res)


model = create_model(main)
quantum_program = synthesize(model)

show(quantum_program)

result = execute(quantum_program).result()
print(result[0].value.parsed_counts)
# [{'res': 1.0}: 1000]

Let's unravel the code above:

  1. def main : We define the logic of our quantum program. We'll expand on this point soon below.
  2. create_model : We convert the logic we defined into a Model.
  3. synthesize : We synthesize the Model into a Quantum Program. From a logical definition of quantum operations, into a series of quantum gates.
  4. execute : Executing the quantum program. Can be executed on a physical quantum computer, or on simulations.

1) Defining the Logic of Quantum Programs

The function above had 4 lines:

@qfunc
def main(res: Output[QBit]):
    allocate(NUM_QUBITS, res)
    X(res)

The 1st line states that the function will be a quantum one. Further documentation.

The 2nd line defines the type of the output. Further examples on types

The 3rd line allocates several qubits (in this example, only 1) in this quantum variable. Further details on allocate

The 4th line applies an X operator on the quantum variable. Further details on quantum operators

More Examples

Initializing $\ket{-}$ state:

@qfunc
def prep_minus(out: Output[QBit]) -> None:
    allocate(1, out)
    X(out)
    H(out)

A part of the Deutsch Jozsa algorithm (see the full algorithm here)

@qfunc
def deutsch_jozsa(predicate: QCallable[QNum, QBit], x: QNum) -> None:
    hadamard_transform(x)
    my_oracle(predicate=lambda x, y: predicate(x, y), target=x)
    hadamard_transform(x)

A part of a QML encoder (see the full algorithm here)

@qfunc
def angle_encoding(exe_params: CArray[CReal], qbv: Output[QArray[QBit]]) -> None:
    allocate(exe_params.len, qbv)
    repeat(
        count=exe_params.len,
        iteration=lambda index: RY(pi * exe_params[index], qbv[index]),
    )

For more, see this repository :)

2) Logic to Models

As we saw above, the main function can be converted to a model using model = create_model(main).

A model is built out of 2 parts: a qmod, and synthesis options. The former is a quantum language used for defining quantum programs, while the latter is a configuration for the execution of the program.

The model can be saved via write_qmod(model, "file_name"), which will save 2 files: file_name.qmod and file_name.synthesis_options.json. You may encounter these files in this repository.

3) Synthesis : Models to Quantum Program

This is where the magic happens. Taking a model, which is a set of logical operations, and synthesizing it into physical qubits and the gates entangling them, is not an easy task.

Classiq's synthesis engine is able to optimize this process, whether by requiring the minimal amount of physical qubits, thus reusing as many qubits as possible, or by requiring minimal circuit width, thus lowering execution time and possible errors.

4) Execution

Classiq provides an easy-to-use way to execute quantum programs, and provides various insights of the execution results.

Diagrams

1 diagram is worth a thousand words

flowchart
    IDEInput[<a href='https://platform.classiq.io/'>Classiq IDE</a>]

    SDKInput[<a href='https://docs.classiq.io/latest/reference-manual/python-sdk/'>Classiq python SDK</a>]

    Model[<a href='https://docs.classiq.io/latest/reference-manual/platform/qmod/'>Quantum Model</a>]

    Synthesis[<a href='https://docs.classiq.io/latest/classiq_101/classiq_concepts/optimize/'>Synthesis Engine</a>]

    QuantumProgram[Quantum Program]

    Execution[<a href='https://docs.classiq.io/latest/classiq_101/classiq_concepts/execute/'>Execution</a>]

    Analyze[<a href='https://docs.classiq.io/latest/classiq_101/classiq_concepts/analyze/'>Analyze & Debug</a>]

    IBM[IBM]
    Amazon[Amazon Braket]
    Azure[Azure Quantum]
    Nvidia[Nvidia]


    IDEInput --> Model;
    SDKInput --> Model;
    Model --> Synthesis;
    Synthesis --> QuantumProgram;
    ExternalProgram <--> QuantumProgram;
    QuantumProgram --> Analyze;
    QuantumProgram --> Execution;
    Execution --> IBM
    Execution --> Amazon
    Execution --> Azure
    Execution --> Nvidia
Loading

Build Your Own

With Classiq, you can build anything. Classiq provides a powerful modeling language to describe any quantum program, which can then be synthesized and executed on any hardware or simulator. Explore our Documentation to learn everything.

SDK : Classiq's Python Interface

Example: 3+5 with Classiq

from classiq import (
    QArray,
    Output,
    allocate,
    qfunc,
    X,
    QNum,
    synthesize,
    create_model,
    show,
    execute,
)


@qfunc
def get_3(x: Output[QArray]) -> None:
    allocate(2, x)
    X(x[0])
    X(x[1])


@qfunc
def get_5(x: Output[QArray]) -> None:
    allocate(3, x)
    X(x[0])
    X(x[2])


@qfunc
def main(res: Output[QNum]) -> None:
    a = QNum("a")
    b = QNum("b")
    get_3(a)
    get_5(b)
    res |= a + b  # should be 8


model = create_model(main)
quantum_program = synthesize(model)

show(quantum_program)

result = execute(quantum_program).result()
print(result[0].value.parsed_counts)

IDE : Classiq's Platform

The examples found in this repository can be accessed via Classiq's platform, in the model tab, under the same folder structure.

Additionally, one may write his own model in the model editor (highlighted in green) or upload his own model (highlighted in red)

writing_models.png

Example: 3+5 with Classiq

  1. Create a model (paste in the model tab)
qfunc get_3(output x: qnum){
allocate<2>(x);
 X(x[0]);
 X(x[1]);
}

qfunc get_5(output x: qnum){
 allocate<3>(x);
 X(x[0]);
 X(x[2]);
}

qfunc main(output res: qnum){
 a: qnum;
 b: qnum;
 get_3(a);
 get_5(b);
 res = a + b;
}
  1. Press Synthesize:

Model_Screenshot_3_plus_5.png

  1. Press Execute:

Program_Screenshot_3_plus_5.png

  1. Press Run:

Execution_Screenshot_3_plus_5.png

  1. View Results:

Jobs_Screenshot_3_plus_5.png


Have questions? Feedback? Something to share? Welcome to join our open Slack Community

classiq-library's People

Contributors

adam-godel avatar adrabi-abderrahim avatar amir-naveh avatar arielsmoler avatar aswkok avatar bill-wisotsky avatar bogachana avatar classiqdor avatar classiqroi avatar clausia avatar cvanbommel avatar giacomoranieri avatar henryafangideh avatar infi-dos avatar joalgago avatar jyotiraj-code avatar nadav138 avatar priyabratabag avatar qcmp34 avatar qubit1718 avatar ramasatyasai avatar razeen-ud-din avatar samyak3690 avatar smml1996 avatar sunitacodehub avatar szyli avatar talicohn avatar thedaemon-wizard avatar umer066 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

classiq-library's Issues

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!

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!

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!

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

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: 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: 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.

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.

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: 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!

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!

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!

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{}.

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!

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

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.

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.

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!

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!

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

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.

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!

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!

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.