Skip to main content

\(Q|SI\rangle \) : A Quantum Programming Environment

  • Chapter
  • First Online:
Symposium on Real-Time and Hybrid Systems

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 11180))


This paper describes a quantum programming environment, named \(Q|SI\rangle \) , to support quantum programming using a quantum extension of the \(\mathbf {while}\)-language. Embedded in the .Net framework, the \(Q|SI\rangle \) platform includes a quantum \(\mathbf {while}\)-language compiler and a suite of tools to simulate quantum computation, optimize quantum circuits, analyze and verify quantum programs. This paper demonstrates \(Q|SI\rangle \) in use. Quantum behaviors are simulated on classical platforms with a combination of components and the compilation procedures for different back-ends are described in detail. \(Q|SI\rangle \) bridges the gap between quantum hardware and software. As a scalable framework, this platform allows users to code and simulate customized functions, optimize them for a range of quantum circuits, analyze the termination of a quantum program, and verify the program’s correctness (The software of \(Q|SI\rangle \) is available at

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

USD 16.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 16.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others


  1. 1.

  2. 2.

  3. 3.


  1. Barenco, A., Bennett, C.H., Cleve, R., DiVincenzo, D.P., Margolus, N., Shor, P., Sleator, T., Smolin, J.A., Weinfurter, H.: Elementary gates for quantum computation. Phys. Rev. A 52(5), 3457 (1995)

    Article  Google Scholar 

  2. Beals, R., Brierley, S., Gray, O., Harrow, A.W., Kutin, S., Linden, N., Shepherd, D., Stather, M.: Efficient distributed quantum computing. In: Proc. R. Soc. A. vol. 469, p. 20120686. The Royal Society (2013)

    Google Scholar 

  3. Bennett, C.H., Brassard, G.: Quantum cryptography: public key distribution and coin tossing. Theor. Comput. Sci. 560, 7–11 (2014)

    Article  MathSciNet  Google Scholar 

  4. Bettelli, S., Calarco, T., Serafini, L.: Toward an architecture for quantum programming. Eur. Phys.J. D-Atomic, Mol. Opt. Plasma Phys. 25(2), 181–200 (2003)

    Google Scholar 

  5. Dawson, C.M., Nielsen, M.A.: The solovay-kitaev algorithm. arXiv preprint quant-ph/ arXiv:0505030 (2005)

  6. Devroye, L.: Sample-based non-uniform random variate generation. In: Proceedings of the 18th conference on Winter simulation, pp. 260–265 (1986)

    Google Scholar 

  7. Green, A.S., Lumsdaine, P.L., Ross, N.J., Selinger, P., Valiron, B.: Quipper: a scalable quantum programming language. In: ACM SIGPLAN Notices, vol. 48, pp. 333–342. ACM (2013)

    Google Scholar 

  8. Grover, L.K.: A fast quantum mechanical algorithm for database search. In: Proceedings of the twenty-eighth annual ACM symposium on Theory of computing, pp. 212–219. ACM (1996)

    Google Scholar 

  9. Harrow, A.W., Hassidim, A., Lloyd, S.: Quantum algorithm for linear systems of equations. Phys. Rev. Lett. 103(15), 150502 (2009)

    Article  MathSciNet  Google Scholar 

  10. Hirata, Y., Nakanishi, M., Yamashita, S., Nakashima, Y.: An efficient conversion of quantum circuits to a linear nearest neighbor architecture. Q. Inf. Comput. 11(1&2), 142–166 (2011)

    MathSciNet  MATH  Google Scholar 

  11. qubit backend: IBM QX team,: ibmqx3 backend specification. Retrieved from (2017)

  12. qubit backend: IBM QX team,: ibmqx2 backend specification. Retrieved from (2017)

  13. JavadiAbhari, A., et al.: Scaffcc: a framework for compilation and analysis of quantum computing programs. In: Proceedings of the 11th ACM Conference on Computing Frontiers, p. 1 (2014)

    Google Scholar 

  14. JavadiAbhari, A., Patil, S., Kudrow, D., Heckey, J., Lvov, A., Chong, F.T., Martonosi, M.: Scaffcc: scalable compilation and analysis of quantum programs. Parallel Comput. 45, 2–17 (2015)

    Article  Google Scholar 

  15. Jones, C., Gyure, M.F., Ladd, T.D., Fogarty, M.A., Morello, A., Dzurak, A.S.: A logical qubit in a linear array of semiconductor quantum dots. arXiv preprint arXiv:1608.06335 (2016)

  16. Liu, T., Li, Y., Wang, S., Ying, M., Zhan, N.: A theorem prover for quantum hoare logic and its applications. arXiv preprint arXiv:1601.03835 (2016)

  17. Nielsen, M.A., Chuang, I.L.: Quantum Computation and Quantum Information. Cambridge University Press, Cambridge (2010)

    Google Scholar 

  18. Ömer, B.: A procedural formalism for quantum computing (1998)

    Google Scholar 

  19. Sanders, J.W., Zuliani, P.: Quantum programming. In: Backhouse, R., Oliveira, J.N. (eds.) MPC 2000. LNCS, vol. 1837, pp. 80–99. Springer, Heidelberg (2000).

    Chapter  Google Scholar 

  20. Selinger, P.: A brief survey of quantum programming languages. In: Kameyama, Y., Stuckey, P.J. (eds.) FLOPS 2004. LNCS, vol. 2998, pp. 1–6. Springer, Heidelberg (2004).

    Chapter  MATH  Google Scholar 

  21. Shende, V., Bullock, S., Markov, I.: Synthesis of quantum-logic circuits. IEEE Trans. Comput.-Aided Des. Integr. Circuits Syst. 25(6), 1000–1010 (2006)

    Article  Google Scholar 

  22. Shor, P.W.: Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM Rev. 41(2), 303–332 (1999)

    Article  MathSciNet  Google Scholar 

  23. Shor, P.W., Preskill, J.: Simple proof of security of the bb84 quantum key distribution protocol. Phys. Rev. Lett. 85(2), 441 (2000)

    Article  Google Scholar 

  24. Smelyanskiy, M., Sawaya, N.P., Aspuru-Guzik, A.: qhipster: the quantum high performance software testing environment. arXiv preprint arXiv:1601.07195 (2016)

  25. Smith, R.S., Curtis, M.J., Zeng, W.J.: A practical quantum instruction set architecture. arXiv preprint arXiv:1608.03355 (2016)

  26. Svore, K.M., Aho, A.V., Cross, A.W., Chuang, I., Markov, I.L.: A layered software architecture for quantum computing design tools. IEEE Comput. 39(1), 74–83 (2006)

    Article  Google Scholar 

  27. Veldhorst, M., Yang, C., Hwang, J., Huang, W., Dehollain, J., Muhonen, J., Simmons, S., Laucht, A., Hudson, F., Itoh, K., et al.: A two-qubit logic gate in silicon. Nature 526(7573), 410–414 (2015)

    Article  Google Scholar 

  28. Wecker, D., Svore, K.M.: Liquid: A software design architecture and domain-specific language for quantum computing. arXiv preprint arXiv:1402.4467 (2014)

  29. Ying, M.: Floyd-hoare logic for quantum programs. ACM Trans. Program. Lang. Syst. (TOPLAS) 33(6), 19 (2011)

    Article  Google Scholar 

  30. Ying, M.: Foundations of Quantum Programming. Morgan Kaufmann, Burlington (2016)

    Chapter  Google Scholar 

  31. Ying, M., Feng, Y.: Quantum loop programs. Acta Inf. 47(4), 221–250 (2010)

    Article  MathSciNet  Google Scholar 

  32. Ying, M., Feng, Y.: A flowchart language for quantum programming. IEEE Trans. Soft. Eng. 37(4), 466–485 (2011)

    Article  Google Scholar 

  33. Ying, M., Ying, S., Wu, X.: Invariants of quantum programs: characterisations and generation. In: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, pp. 818–832. ACM (2017)

    Google Scholar 

  34. Ying, M., Yu, N., Feng, Y., Duan, R.: Verification of quantum programs. Sci. Comput. Program. 78(9), 1679–1700 (2013)

    Article  Google Scholar 

Download references


We are grateful to Professors Michael Blumenstein, Ian Burnett, Yuan Feng, and Glenn Wightwick for their helpful discussions and their strong supports of this project. We also acknowledge use of the IBM Q experience for this work. The views expressed are those of the authors and do not reflect the official policy or position of IBM or the IBM Q experience team.

Author information

Authors and Affiliations


Corresponding author

Correspondence to Shusen Liu .

Editor information

Editors and Affiliations


A Setup and Configuration of \(Q|SI\rangle \) 

\(Q|SI\rangle \) mainly relies on IDE (Visual Studio) to provide the details of the program. After coding a program using \(Q|SI\rangle \) , the programmer needs to build and compile it. This feature is considered to be an essential component because a smarter IDE is a basic way of ensuring the syntax is correct as programs grow in size and complexity. This feature is unlike IScasMC or QPAT which are not able to execute a program.

NuGet is a part of the .Net development platform and is used in \(Q|SI\rangle \) to manage the packages. All packages used to provide functions, such as matrix computation, random number generation, and Roslyn, etc., can be automatically controlled by NuGet. To access all the essential packages, a user needs only to add the NuGet feed v3 “” to their Visual Studio 2017 configuration. This will add the package resources and automatically configure them for the platform.

\(Q|SI\rangle \) is compatible with any version of Visual Studio 2015 and later. However, we recommend the Enterprise version of Visual Studio 2017 because of its premium features, e.g., the ability to draw quantum circuits with DGML tools, the most up-to-date, etc. Examples are stored in the sub-folder UnitTest. All entry-level examples can be found in the ‘Program.cs’ file in UnitTest.

B Experiment-Qloop Case

The first example showcases the Qloop case. It uses quantum channels, measurement, quantum \(\mathbf {while}\)-clause and quantum variables. The Qloop case can also be treated as a simplified quantum walk. The flow path is shown in Fig. 5.

Fig. 5.
figure 5


Fig. 6.
figure 6

Qloop data

1.1 B.1 Input and Output


  • \(\rho _0:=\left| +\right\rangle \left\langle +\right| \);

  • \(\mathcal {E}:=\{ E_0=\left| 0\right\rangle \left\langle 0\right| +\left| 1\right\rangle \left\langle 1\right| /\sqrt{2},E_1=\left| 0\right\rangle \left\langle 1\right| /\sqrt{2}\}\);

  • \(M:=\{M_0=\left| 0\right\rangle \left\langle 0\right| ,M_1=\left| 1\right\rangle \left\langle 1\right| \}\);

  • \(H:=\left| +\right\rangle \left\langle 0\right| +\left| -\right\rangle \left\langle 1\right| \);

  • \(Counter:=0\).


  • num: the number of circles is num.

1.2 B.2 Results

The Qloop experiment executes for approximately 100, 000 shots with the results shown in Fig. 6.

1.3 B.3 Features and Analysis

After calculation, it is clear that \(\rho _1=\mathcal {E}(\rho _0)=\frac{3}{4}|0 \rangle \langle 0 |+\frac{1}{4}|1 \rangle \langle 1 |+\frac{1}{2\sqrt{2}}|0 \rangle \langle 1 |+\frac{1}{2\sqrt{2}}|1 \rangle \langle 0 |\), \(\rho _2=|1 \rangle \langle 1 |\), \(\rho _1^\prime =|+ \rangle \langle + |\) and \(\rho _3=|0 \rangle \langle 0 |\).

The three main features of this experiment include super-operators, unitary transformation, and measurement operations. In addition, processes that consider a qubit’s collapse and measurement probability are inherently involved as part of quantum mechanics.

  • Super-operator operation. The initial state passes through a quantum channel and becomes \(\rho _1\). Let M be performed on the state \(\rho _1\) in each shot. There is a \(\frac{3}{4}\) probability that the state will change to \(\rho _3\) and then terminate. Likewise, there is a \(\frac{1}{4}\) probability of moving in a circle and having the process recorded by the counter. So if the program is executed many times, such as in a 100, 000 shot experiment, the counter should show that the state enters the circle about 25, 000 times.

  • Measurement operations and unitary transformations. After the first measurement, \(\rho _1\) may change to \(\rho _2\) and continue, or it may change to \(\rho _3\) and terminates. If the state changes to \(\rho _2\) after a Hadamard operator which is a unitary transformation, it becomes \(\rho _1^\prime =|+ \rangle \langle + |\) and the counter records the circle once. When a measurement M is performed on the state, we can assert that almost half the time \(\rho _1^\prime \) becomes \(|0 \rangle \langle 0 |\) and the other half of the time it becomes \(|1 \rangle \langle 1 |\). If the result is \(|1 \rangle \langle 1 |\), it will enter into the loop body again be recorded by the counter. The counter number shows how many circles the state enters into in total. Obviously, this decreases at almost half the rate of a geometric progression, as in say \(1-12556\), \(2-6140\), \(3-3095\), \(\ldots \)

C BB84 Case

BB84 is a basic quantum key distribution (QKD) protocol developed by Bennett and Brassard in 1984 [3].

1.1 C.1 Simple BB84 Case

In this case, a client-server model is used as a prototype for a multi-user communication protocol. A “quantum type converter” is used to convert a ‘Ket’ into a density operator. For simplicity and clarity, this example only consider ‘Ket’ quantum types, not quantum channels or Eves. The entire flow path is shown in Fig. 7.

Fig. 7.
figure 7

Simple BB84 protocol

  1. 1.

    Alice randomly generates a sequence of classical bits called a \(rawKeyArray \). Candidates from this raw key sequence are chosen to construct the final agreement key. The sequence length is determined by user input.

  2. 2.

    Alice also randomly generates a sequence of classical bits called \(basisRawArray \). This sequence indicates the chosen basis to be used in next step. Alice and Bob share a rule before the protocol:

    • They use \(\{\left| +\right\rangle ,\left| -\right\rangle \}\) or \(\{\left| 0\right\rangle ,\left| 1\right\rangle \}\) to encode the information.

    • A classical bit of 0 indicates a \(\{\left| 0\right\rangle ,\left| 1\right\rangle \}\) basis while a classical bit of 1 indicates \(\{\left| +\right\rangle ,\left| -\right\rangle \}\). This rule is used to generate Alice’s qubits and to check Bob’s basis.

  3. 3.

    Alice generates a sequence of quantum bits called a \(KetEncArray \), one by one according to the following rules:

    • If the \(basisRawArray[i] \) in position [i] is 0 and the \(rawKeyArray[i] \) in position [i] is 0, \(KetEncArray[i] \) would be \(\left| 0\right\rangle \).

    • If the \(basisRawArray[i] \) in position [i] is 0 and the \(rawKeyArray[i] \) in position [i] is 1, \(KetEncArray[i] \) would be \(\left| 1\right\rangle \).

    • If the \(basisRawArray[i] \) in position [i] is 1 and the \(rawKeyArray[i] \) in position [i] is 0, \(KetEncArray[i] \) would be \(\left| +\right\rangle \).

    • If the \(basisRawArray[i] \) in position [i] is 1 and the \(rawKeyArray[i] \) in position [i] is 1, \(KetEncArray[i] \) would be \(\left| -\right\rangle \).

  4. 4.

    Alice sends the \(KetEncArray \) through a quantum channel. In this case, she sends it through the I channel.

  5. 5.

    Bob receives the \(KetEncArray \) through the quantum channel.

  6. 6.

    Bob randomly generates a sequence of classical bits called \(measureRawArray \) to indicate the chosen basis to be used in next step.

  7. 7.

    Bob generates a sequence of classical bits called \(tempResult \), using quantum measurement according to the rules:

    • If the \(measureRawArray[i] \) in [i] position is a classical bit 0, Bob uses a \(\{\left| 0\right\rangle ,\left| 1\right\rangle \}\) basis to measure the \(KetEncArray[i] \) while a classical bit 1 indicates using a \(\{\left| +\right\rangle ,\left| -\right\rangle \}\) basis.

  8. 8.

    Bob broadcasts the \(measureRawArray \) to Alice using a classical channel.

  9. 9.

    Alice generates a sequence of classical bits called \(correctBroadArray \), by comparing Bob’s basis \(measureRawArray \) and her basis \(basisRawArray \). If the position [i] is correct, the \(correctBroadArray[i] \) would be 1; otherwise, it would be 0.

  10. 10.

    Alice sends the sequence \(correctBroadArray \) to Bob.

  11. 11.

    Alice generates a sequence of classical bits called FinalALiceKey using the rule:

    • If position [i] in \(correctBroadArray[i] \) is 1, she keeps \(rawKeyArray[i] \) and copies it to \(FinalALiceKey \) , else she discards \(rawKeyArray[i] \).

  12. 12.

    Bob generates a sequence of classical bits called FinalBobKey using the rule:

    • If position [i] in \(correctBroadArray[i] \) is 1, he keeps \(tempResult[i] \) and copies it to \(FinalBobKey[i] \), else he discards \(tempResult[i] \).

  13. 13.

    GlobalView: We use a function compare whether every position [i] in \(FinalALiceKey \) and \(FinalBobKey[i] \) are the same.

This case shows some useful features,

  • Client-server mode. The process uses a client-server model to simulate the BB84 protocol. The model includes many implicit features, such as waiting threads and concurrent communications which are also used in the next example.

  • Measurement. According to theory, choosing a random measurement basis may arrive at half of the correct result. As a result, the agreement of classical shared bits should be almost half the length of the raw keys.

1.2 C.2 BB84 Case, Multi-client

The multi-client BB84 model offers a more attractive and practical example. In this model, one Alice generates the raw keys while many Bobs construct an agreement key with Alice.

In this case, users can specify the number of clients. Also, a typical BB84 flow path would occur for every client-server pair of this model.

This case highlights:

  • The threads model. Many clients are generated and communicate with Alice. Each of them finally reaches an agreement.

  • Measurement threads. In this case, Alice generates raw keys, and Bob measures the quantum bits. However, this raises a serious question that about clients generate raw keys while a server conducts the measurement: How can we ensure the server correctly and fairly conducts the measurement for the client.

1.3 C.3 BB84 Case with Noise

A practical topic for the \(Q|SI\rangle \) to consider is the BB84 model with noisy quantum channels. Noisy quantum operations are the key tools for describing the dynamics of open quantum systems.

In this example, different channels such as bit flip, depolarizing, amplitude damping and I-identity channels are described by quantum operations performed as the evolution of quantum systems in a wide variety of circumstances. Alice and Bob use these quantum channels to communicate with each other via the BB84 protocol as Fig. 7 shows. However, during communication, verification steps also need to be considered.

Input and output In this example, the basic quantum channels are defined as follows:

a deplarizing channel with a noise parameter of \(p=0.5\),

$$ \mathcal {E}:=\left\{ \begin{bmatrix} \frac{\sqrt{5}}{\sqrt{8}}&0\\ 0&\frac{\sqrt{5}}{\sqrt{8}}\\ \end{bmatrix}, \begin{bmatrix} 0&\frac{1}{\sqrt{8}}\\ \frac{1}{\sqrt{8}}&0\\ \end{bmatrix} \begin{bmatrix} 0&\frac{-i}{\sqrt{8}}\\ \frac{i}{\sqrt{8}}&0\\ \end{bmatrix} \begin{bmatrix} \frac{1}{\sqrt{8}}&0\\ 0&-\frac{1}{\sqrt{8}}\\ \end{bmatrix} \right\} \,; $$

an amplitude damping channel with a noise parameter of \(\gamma =0.5\),

$$ \mathcal {E}:=\left\{ \begin{bmatrix} 1&0\\ 0&\frac{1}{\sqrt{2}}\\ \end{bmatrix}, \begin{bmatrix} 0&\frac{1}{\sqrt{2}}\\ 0&0\\ \end{bmatrix} \right\} \,; $$

a bit flip channel with a noise parameter of \(p=0.25\),

$$ \mathcal {E}:=\left\{ \begin{bmatrix} \frac{1}{2}&0\\ 0&\frac{1}{2}\\ \end{bmatrix}, \begin{bmatrix} 0&\frac{\sqrt{3}}{2}\\ \frac{\sqrt{3}}{2}&0\\ \end{bmatrix} \right\} \,; $$

a bit flip channel with a noise parameter of \(p=0.5\),

$$ \mathcal {E}:=\left\{ \begin{bmatrix} \frac{1}{\sqrt{2}}&0\\ 0&\frac{1}{\sqrt{2}}\\ \end{bmatrix}, \begin{bmatrix} 0&\frac{1}{\sqrt{2}}\\ \frac{1}{\sqrt{2}}&0\\ \end{bmatrix} \right\} \,; $$

bit flip channel with noise parameter \(p=0.75\),

$$ \mathcal {E}:=\left\{ \begin{bmatrix} \frac{\sqrt{3}}{2}&0\\ 0&\frac{\sqrt{3}}{2}\\ \end{bmatrix}, \begin{bmatrix} 0&\frac{1}{2}\\ \frac{1}{2}&0\\ \end{bmatrix} \right\} \,. $$

The flow path follows the simple BB84 protocol shown in Fig. 7. The only differences are in Step 4 and the addition of a sampling step.

  • Alice sends the \(KetEncArray \) through a quantum channel. In this case, it is one of the channels mentioned above.

  • Sampling check step: Alice randomly publishes some sampling positions with the bits against these positions in her key string. Bob checks these bits against his key strings. If all the bits in these sampling strings are the same, he believes the key distribution is a success; otherwise, the connection fails.

To use a statistical quantity to characterize success in a channel with the BB84 protocol, we executed a 100-shot experiment for each channel. In every shot for every channel, different sampling percentages and package lengths were considered. The results provided in Fig. 8 shows the trade-off between success times, different sampling proportions and package lengths for each of the quantum channels.

Results. Success times for different sampling percentages in different channels over 100 shots (see Fig. 8).

Fig. 8.
figure 8

Statistics of success communication via BB84 with channels

Features and Analysis’. The example generates some ‘erroneous’ bits during communication due to quantum channels which cause a connection failure. Additionally, not all error bits can be found in the sampling step because, in theory, almost half the bits are invalid in the measurement step. Further, the sampling step is also a probability verification step which means it does not use all the agreed bits to verify the communication procedure.

Subfigures (a), (b) and (c) in Fig. 8 are bit flip channels with different probabilities. Overall, the number of successful shots increases as p increases and the raw key length shortens. This is because p is a reflection of the percentage of information that remains in the bit flip channel and an increase in p means fewer errors in communication. A shorter raw key length ensures fewer bits are sampled. Sub-figure (d),(e) and (f) illustrate the communication capacity of the BB84 protocol in the other three channels. Note that the I-identity channel has a 100% success rate, which means it is a noiseless channel and can keep information intact during the transfer procedure.

D Grover’s Search Algorithm

Grover’s search algorithm is a well-known quantum algorithm. It solves searching problems in databases consisting of N elements, indexed by number \(0,1,\ldots ,N-1\) with an oracle provides the answer as a position. This algorithm can find solutions with a probability of O(1) within \(O(\sqrt{N})\) steps.

1.1 D.1 A Simple Grover’s Search Algorithm

In this example, we assume there is only one answer to the question, i.e., the oracle will only reverse one position at a time. Further, the oracle is assumed to be working as a black box and can reverse the correct position of the answer. After querying the oracle \(r=\frac{\pi }{4}\sqrt{N}\) times with the corresponding phase rotations, the quantum state contains the correct information to answer the question.

Input and output. Input:

  • The total number of spaces N. For convenience, we have restricted \(N=2^n\).

  • The correct position of the search that is used to construct the oracle.


  • The final position of the measurement result.

  • Oracle time r.

Results. The simple Grover’s search algorithm has only one result, and the final measurement result shows the correct answer to the searching problem.

Features and analysis. Suppose \(\left| \alpha \right\rangle =\frac{1}{\sqrt{N-1}}\sum _{x}^{''}\left| x\right\rangle \) is not the solution but rather \(\left| \beta \right\rangle =\sum _{x}^{'}\left| x\right\rangle \) is the solution where \(\sum _{x}^{'}\) indicates the sum of all the solutions. The initial state \(\left| \psi \right\rangle \) may be expressed as

$$ \left| \psi \right\rangle =\sqrt{\frac{N-1}{N}}\left| \alpha \right\rangle +\sqrt{\frac{1}{N}}\left| \beta \right\rangle \, . $$

Every rotation makes the \(\theta \) to the solution where

$$ \sin \theta =\frac{2\sqrt{N-1}}{N}\, . $$

When N is larger, the gap between the measurement result and the real position number is less than \(\theta =\arcsin \frac{2\sqrt{N-1}}{N}\approx \frac{2}{\sqrt{N}}\). Therefore, it is almost impossible to generate the wrong answer within r times.

1.2 D.2 Multi-object Grover’s Search Algorithm

This experiment considers a more general Grover’s search algorithm: a multi-object Grover’s search algorithm. This case supposes that there may be more than one correct answer (position) for the oracle to find. We use a strategy that adds a blind box to reverse the proper position of the answer. This experiment reveals that Grover’s algorithm leads to an avalanche of error in a multi-object setting, indicating that algorithm needs to be modified in some way.

A new blind box (a unitary gate) is added, which reverses the proper position of the answer. In short, the oracle is a matrix where all the diagonal elements are 1, but all the answer positions are \(-1\). Thus, the blind box is a diagonal matrix where all elements are 1, and all the answer position that have been found are \(-1\). When these two boxes are combined, we create a new oracle with the answers to all the questions except for the ones that were found in previous rounds.

Input and output The input is

  • The total number of spaces N. For convenience, we have restricted \(N=2^n\).

  • All correct positions of the search.

The output is

  • The final position of the measurement result.

  • Oracle time r.

Results The measurement shows different probabilities of the final result. The theory holds that if we have multiple-answers, the state after r times oracles and phase gates becomes a state near to both. For example, if the answers are \(\left| 2\right\rangle \, ,\left| 14\right\rangle \in \mathcal {H}_{64}\), the state before the measurement is expected to be almost \(\frac{1}{\sqrt{2}}(\left| 2\right\rangle +\left| 14\right\rangle )\). We should get \(\left| 2\right\rangle \) or \(\left| 14\right\rangle \) the first time and the other one the next time. However, we get results other than \(\left| 2\right\rangle \) and \(\left| 14\right\rangle \) with high probability, which indicates that the multi-object search algorithm is not very good.

Features and analysis It worth noting that due to multi-objects, the real state after using Grover’s search algorithm becomes \(a(\left| 2\right\rangle +\left| 14\right\rangle )+b(\left| 1\right\rangle +\left| 3\right\rangle +\left| 4\right\rangle +\left| 5\right\rangle +....)\) where \(a,b \in \mathcal {C}\) and \(|a|^2+|b|^2=1\). However, b cannot be ignored even if it is very small. An interesting issue occurs when the wrong position index is found. If the wrong index is measured, the algorithm creates an incorrect blind box and reverses the wrong position of the oracle, i.e., it adds a new answer to the questions. In next round, the proportion of correct answers is further reduced. In the last example, we would measured an incorrect answer, say \(\left| 5\right\rangle \). After the new procedure, the state would become: \(a(\left| 2\right\rangle +\left| 14\right\rangle +\left| 5\right\rangle )+b(\left| 1\right\rangle +\left| 3\right\rangle +\left| 4\right\rangle +\left| 5\right\rangle +....)\), making it even harder to find the correct answer.

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Liu, S. et al. (2018). \(Q|SI\rangle \) : A Quantum Programming Environment. In: Jones, C., Wang, J., Zhan, N. (eds) Symposium on Real-Time and Hybrid Systems. Lecture Notes in Computer Science(), vol 11180. Springer, Cham.

Download citation

  • DOI:

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-01460-5

  • Online ISBN: 978-3-030-01461-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics