Abstract
This paper describes a quantum programming environment, named \(QSI\rangle \) , to support quantum programming using a quantum extension of the \(\mathbf {while}\)language. Embedded in the .Net framework, the \(QSI\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 \(QSI\rangle \) in use. Quantum behaviors are simulated on classical platforms with a combination of components and the compilation procedures for different backends are described in detail. \(QSI\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 \(QSI\rangle \) is available at http://www.qcompiler.com.).
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
References
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)
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)
Bennett, C.H., Brassard, G.: Quantum cryptography: public key distribution and coin tossing. Theor. Comput. Sci. 560, 7–11 (2014)
Bettelli, S., Calarco, T., Serafini, L.: Toward an architecture for quantum programming. Eur. Phys.J. DAtomic, Mol. Opt. Plasma Phys. 25(2), 181–200 (2003)
Dawson, C.M., Nielsen, M.A.: The solovaykitaev algorithm. arXiv preprint quantph/ arXiv:0505030 (2005)
Devroye, L.: Samplebased nonuniform random variate generation. In: Proceedings of the 18th conference on Winter simulation, pp. 260–265 (1986)
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)
Grover, L.K.: A fast quantum mechanical algorithm for database search. In: Proceedings of the twentyeighth annual ACM symposium on Theory of computing, pp. 212–219. ACM (1996)
Harrow, A.W., Hassidim, A., Lloyd, S.: Quantum algorithm for linear systems of equations. Phys. Rev. Lett. 103(15), 150502 (2009)
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)
qubit backend: IBM QX team,: ibmqx3 backend specification. Retrieved from https://ibm.biz/qiskitibmqx3 (2017)
qubit backend: IBM QX team,: ibmqx2 backend specification. Retrieved from https://ibm.biz/qiskitibmqx2 (2017)
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)
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)
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)
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)
Nielsen, M.A., Chuang, I.L.: Quantum Computation and Quantum Information. Cambridge University Press, Cambridge (2010)
Ömer, B.: A procedural formalism for quantum computing (1998)
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). https://doi.org/10.1007/10722010_6
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). https://doi.org/10.1007/9783540247548_1
Shende, V., Bullock, S., Markov, I.: Synthesis of quantumlogic circuits. IEEE Trans. Comput.Aided Des. Integr. Circuits Syst. 25(6), 1000–1010 (2006)
Shor, P.W.: Polynomialtime algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM Rev. 41(2), 303–332 (1999)
Shor, P.W., Preskill, J.: Simple proof of security of the bb84 quantum key distribution protocol. Phys. Rev. Lett. 85(2), 441 (2000)
Smelyanskiy, M., Sawaya, N.P., AspuruGuzik, A.: qhipster: the quantum high performance software testing environment. arXiv preprint arXiv:1601.07195 (2016)
Smith, R.S., Curtis, M.J., Zeng, W.J.: A practical quantum instruction set architecture. arXiv preprint arXiv:1608.03355 (2016)
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)
Veldhorst, M., Yang, C., Hwang, J., Huang, W., Dehollain, J., Muhonen, J., Simmons, S., Laucht, A., Hudson, F., Itoh, K., et al.: A twoqubit logic gate in silicon. Nature 526(7573), 410–414 (2015)
Wecker, D., Svore, K.M.: Liquid: A software design architecture and domainspecific language for quantum computing. arXiv preprint arXiv:1402.4467 (2014)
Ying, M.: Floydhoare logic for quantum programs. ACM Trans. Program. Lang. Syst. (TOPLAS) 33(6), 19 (2011)
Ying, M.: Foundations of Quantum Programming. Morgan Kaufmann, Burlington (2016)
Ying, M., Feng, Y.: Quantum loop programs. Acta Inf. 47(4), 221–250 (2010)
Ying, M., Feng, Y.: A flowchart language for quantum programming. IEEE Trans. Soft. Eng. 37(4), 466–485 (2011)
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)
Ying, M., Yu, N., Feng, Y., Duan, R.: Verification of quantum programs. Sci. Comput. Program. 78(9), 1679–1700 (2013)
Acknowledgments
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
Editor information
Editors and Affiliations
Appendices
A Setup and Configuration of \(QSI\rangle \)
\(QSI\rangle \) mainly relies on IDE (Visual Studio) to provide the details of the program. After coding a program using \(QSI\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 \(QSI\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 “https://api.nuget.org/v3/index.json” to their Visual Studio 2017 configuration. This will add the package resources and automatically configure them for the platform.
\(QSI\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 uptodate Math.net, etc. Examples are stored in the subfolder UnitTest. All entrylevel examples can be found in the ‘Program.cs’ file in UnitTest.
B ExperimentQloop 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.
1.1 B.1 Input and Output
Input:

\(\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\).
Output:

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 superoperators, 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.

Superoperator 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 \(112556\), \(26140\), \(33095\), \(\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 clientserver model is used as a prototype for a multiuser 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.

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.
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.
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.
Alice sends the \(KetEncArray \) through a quantum channel. In this case, she sends it through the I channel.

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

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

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.
Bob broadcasts the \(measureRawArray \) to Alice using a classical channel.

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.
Alice sends the sequence \(correctBroadArray \) to Bob.

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.
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.
GlobalView: We use a function compare whether every position [i] in \(FinalALiceKey \) and \(FinalBobKey[i] \) are the same.
This case shows some useful features,

Clientserver mode. The process uses a clientserver 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, Multiclient
The multiclient 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 clientserver 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 \(QSI\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 Iidentity 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\),
an amplitude damping channel with a noise parameter of \(\gamma =0.5\),
a bit flip channel with a noise parameter of \(p=0.25\),
a bit flip channel with a noise parameter of \(p=0.5\),
bit flip channel with noise parameter \(p=0.75\),
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 100shot 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 tradeoff 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).
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. Subfigure (d),(e) and (f) illustrate the communication capacity of the BB84 protocol in the other three channels. Note that the Iidentity 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 wellknown quantum algorithm. It solves searching problems in databases consisting of N elements, indexed by number \(0,1,\ldots ,N1\) 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.
Output:

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{N1}}\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
Every rotation makes the \(\theta \) to the solution where
When N is larger, the gap between the measurement result and the real position number is less than \(\theta =\arcsin \frac{2\sqrt{N1}}{N}\approx \frac{2}{\sqrt{N}}\). Therefore, it is almost impossible to generate the wrong answer within r times.
1.2 D.2 Multiobject Grover’s Search Algorithm
This experiment considers a more general Grover’s search algorithm: a multiobject 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 multiobject 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 multipleanswers, 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 multiobject search algorithm is not very good.
Features and analysis It worth noting that due to multiobjects, 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
Copyright information
© 2018 Springer Nature Switzerland AG
About this chapter
Cite this chapter
Liu, S. et al. (2018). \(QSI\rangle \) : A Quantum Programming Environment. In: Jones, C., Wang, J., Zhan, N. (eds) Symposium on RealTime and Hybrid Systems. Lecture Notes in Computer Science(), vol 11180. Springer, Cham. https://doi.org/10.1007/9783030014612_8
Download citation
DOI: https://doi.org/10.1007/9783030014612_8
Published:
Publisher Name: Springer, Cham
Print ISBN: 9783030014605
Online ISBN: 9783030014612
eBook Packages: Computer ScienceComputer Science (R0)