<jupyter_start><jupyter_text><img src="qbraid-logo.png"    height="10" width="60"      style="float: left; vertical-align:top; margin-right: 40px; margin-left: 10px;" />Aloha, Quantum World!  'Hello, World!' has been the most iconic computer program. There is a good chance that you, our reader, also began your journey in the world of programming by printing 'Hello, World!' on your screen. In this article, we aim to develop a quantum version of the 'Hello, World!' program that we call 'Aloha, Quantum World!'. Before we do that, let us discuss the significance of the traditional "Hello, World!" program. The Hello world program was developed by <NAME>, in 1974. Its purpose was to be- the simplest possible program for the language- a demonstration of the syntax for a particular language - and to check everything is working correctly. Remember these were the days when people were still figuring out how to connect a display device to a computer. So, the program also checked if the program compiled correctly and if the connection to the input and output devices (such as a monitor) is not erring. Following the reasoning behind the classical 'Hello, World!', let us discuss what we would want to accomplish with quantum 'Hello, World!'- Similar to 'Hello, World!' we would want it to be the simplest quantum program. And, our version of quantum 'Hello, World!' is called 'Aloha, World!'.- 'Aloha, World!' should go through the quantum software and hardware layer to ensure the faithfulness of the stack.- Then, we want to go one step further. If you look into the details of 'Aloha, World!', it should present to you the details for how quantum computing is fundamentally different than classical computing. A few more comments about the state of quantum computers now compared to the state of classical computers when the 'Hello, World!' was developed. - The number of transistors in a microprocessor were in a few thousands in 1970s compared to a few ten's of qubits available in quantum computers currently.- People were starting develop high level languages for programming classical computers. 'Hello, World!' was first reference in 'B' a predecessor to the language 'C'. In comparison, most quantum computers are being programmed using python. Now, let us present to you the 'Aloha, Quantum World!' program. The function is called using the following piece of code:<jupyter_code>print('Hello World!')
from demo_funcs import aloha_quantum_world
aloha_quantum_world()
aloha_quantum_world('quantum')
aloha_quantum_world('quantum')<jupyter_output>Hello World!
Bye World!
Hello World!<jupyter_text>Just like the classical 'Hello, World!' program, it is a simple program. If it is called without input, it always outputs 'Hello, World!'. But, if 'quantum' is passed as input then, it sometimes outputs the 'Hello, World!' and other times it outputs 'Bye, World!'. This is the reason why we thought naming this article 'Aloha, Quantum World!' was apt. If ran enough number of times, one will observe that the program in-fact prints 'Hello, World!' and 'Bye, World!' 50% of the time. We encourage you to play with the code to convince yourself.Now, you may ponder as to what may be going on behind the scenes in the program. Since the program seems to be printing 'Hello, World!' and 'Bye, World!' with 50% probability, your initial guess maybe that it is similar to a coin flip, And yes, it is similar but not quite! First, note that in the macroscopic world for which we have built our intuition, probability arises out of incomplete knowledge of a given system. e.g. in the case of a coin flip, if all the parameters for the coin flip are known, like the force with which it was flipped, the exact force of gravity, friction due to air, etc. then theoretically it will be possible to predict whether it will turn up heads or tails. But, because you don't know these parameters, the best you can do is predict with some probabilities. Again, I want you to appreciate that in the  classical world probabilities arise out of not knowing.Another important detail to note is that when the coin lands on the ground, it lands on either heads or tails. Let us say that you toss a coin in a dark room where you can't see whether the heads or tails have turned up. Even before you turn on the light to look, you can be sure that it is either heads or tails, it cannot be both at the same time.The program `aloha_quantum_world('quantum')` that we ran above is non-compliant with the two points that we just mentioned. The program uses a qubit or quantum bit in a 'superposition' of being '0' and '1'. Qubit is a quantum analog of a bit. A qubit could behave like a bit but also allows for more exotic behavior.Quantum Superposition, in very simple terms, is the property of quantum systems which allow them to be in two distinct states at the same time. When measured, the qubit returns, either 0 or 1. Corresponding to the two points we mentioned for a coin, note the following points for a qubit in superposition:First, even with complete knowledge of the state of a qubit, knowing everything that there is to be known for a state of a qubit, we will still not be able to predict the outcome. In fact, the universe itself does not 'know' whether the qubit will return 0 or 1 when measured. The probability in quantum systems does not arise from 'not knowing' but is actually built into the fabric of nature.Second, the qubit in the state of equal superposition of '0' and '1', is not like a coin lying on the ground in a dark room where it is one of those but we just don't know, but it is both '0' and '1' at the same time!!It is understandable if you are shaking your head in disbelief and asking yourself, 'How could this be?'. You are not alone in asking this question and the answer is: 'It is just the way nature is, and quantum mechanics is a theory based on observations.'. To learn more about quantum computation, we invite you to take our [QuBes Course](./Qubes_course/0_Introduction.ipynb) (quantum beginners) course on qBraid.com. We introduce all the background material and teach you quantum computing. The background material will cover the experiments that convinced physicist that,nature is probabilistic, anda qubit in superposition is both '0' and '1' at the same time. The superposition of a qubit could be leveraged to make quantum algorithms faster than their classical counterparts. One such algorithm covered in QuBes course is Deutsch's algorithm. You will be able to run the algorithm on IBM's actual quantum computer to see it in action! Behind the scenes of "Aloha, Quantum World!"  In this section, we present details for the inner workings of the `aloha_quantum_world('quantum')` program. Before, we present the details, let us present a different version of the classical 'Hello, World!' program. This would help us better understand the quantum program by brining out the contrast.The following is a python program which is a varriant of Hello World. Here, the string 'Hello World' is associated with the state '0' of a Bool variable, and 'Bye World' is associated with the state '1'. Our aim here is to associate the strings with the values of a bit (done using the type Bool in python), which is the fundamental unit of information in classical computing. The program takes as an input a bit value and outputs the corresponding string.<jupyter_code>def hello_bye_world(bit_val):
    if bit_val==0:
        print('========================')
        print('       Hello, World!')
        print('========================')
    elif bit_val==1:
        print('========================')
        print('       Bye, World!')
        print('========================')
        
hello_bye_world(0)
hello_bye_world(1)<jupyter_output>========================
       Hello, World!
========================
========================
       Bye, World!
========================<jupyter_text>It is easy to see that the bit can only have two values, 0 and 1. So, the function could run with only two inputs, as demonstrated above. We now ask, what are the different operations possible on a bit. Note 1: we wrote the program that takes an input bit and returns a string corresponding to the bit value.Now, we ask, what are the possible operations that can be performed on a bit? And it can be seen that the only non-trivial operation possible on a bit is the bit-flip, where one changes the value of the bit, $0 \rightarrow 1$ and $0 \rightarrow 1$. We can write the code for a function that implements the bit flip operation:<jupyter_code>def bit_flip(bit_val):
    return not bit_val<jupyter_output><empty_output><jupyter_text>We can use this bit-flip function in conjunction with our hello_bye_world() function, to turn a hello world into a bye world.<jupyter_code>bit_val=0
hello_bye_world(bit_val)
bit_val=bit_flip(bit_val)
hello_bye_world(bit_val)<jupyter_output>========================
       Hello, World!
========================
========================
       Bye, World!
========================<jupyter_text>Note 2: The only possible operation on a bit is a bit-flip operation.The program so far, is deterministic. We ask, how can we make a probabilistic 'Hello, World!' program. For that we write a coin flip program which returns each '0' and '1', 50% of the time.<jupyter_code>def coin_flip():
    import numpy as np
    bit_val = np.random.randint(2)
    return bit_val<jupyter_output><empty_output><jupyter_text>With this program we can write a small program for printing 'Hello, World!' and 'Bye, World!' randomly.<jupyter_code>hello_bye_world(coin_flip())<jupyter_output>========================
       Hello, World!
========================<jupyter_text>It can be checked by running the program multiple times that the outputs are random. Note 3: The randomness in the numbers generated by the numpy package arises out of some incomplete knowledge of the processes in the cpu of your computer.Now, we finally move on to the aloha_quantum_world('quantum') program. Following is the code for the `aloha_quantum_world()`:<jupyter_code>def aloha_quantum_world(input_str='classical', applyX=False):
    from qiskit import QuantumCircuit, Aer, execute
    circ = QuantumCircuit(1,1) 
    if input_str=='quantum':
        circ.h(0)
    if applyX:
        circ.x(0)
    circ.measure([0],[0])

    backend_sim = Aer.get_backend('qasm_simulator')
    sim = execute(circ, backend_sim, shots=1)
    sim_result = sim.result()
    counts = sim_result.get_counts(circ)
    for key in counts:
        if key=='0':
            print('Hello World!')
        elif key=='1':
            print('Bye World!')<jupyter_output><empty_output><jupyter_text>The above program uses a 'qubit' or a quantum bit for two state system. A qubit just like a bit can be '0' or '1' state. If the aloha_quantum_world() is called without an argument, it initializes the qubit in state '0' and measures it. The measurement returns '0' and prints 'Hello, World!'<jupyter_code>aloha_quantum_world()<jupyter_output>Hello World!<jupyter_text>The `aloha_quantum_world()` can also take an argument for applying an X-gate which is similar to the NOT-gate in classical computing. And it can be seen that the application of `aloha_quantum_world('classical', True)` prints 'Bye, World!'<jupyter_code>aloha_quantum_world('classical', True)<jupyter_output>Bye World!<jupyter_text>So, we can establish that the qubits can behave like bits and return the greeting corresponding to the value (Note 1).Recall that the there was only one single-bit possible in classical computing (Note 2). In constrast, quantum computing allows for an infinite number of single qubit gates and states of a qubit which are a superposition of '0' and '1'. Loosely speaking, the superposition implies that the qubit could both '0' and '1' at the same time* until one measures at which point the state of the qubit collapses to being '0' or '1'. Let's run the aloha_quantum_world('quantum'), 5 times.*(for precise definition, we encourage the reader to take the QuBes course on qBraid.com)<jupyter_code>for i in range(5):
    aloha_quantum_world('quantum')<jupyter_output>Hello World!
Hello World!
Hello World!
Hello World!
Bye World!
{'fraction_non_alphanumeric': 0.0887923259817988, 'fraction_numerical': 0.0063130277937197676, 'mean_word_length': 4.692020531964536, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '87922', 'license': 'MIT', 'n_tokens_mistral': 3246, 'n_tokens_neox': 3015, 'n_words': 1769, 'path': 'MIT_sloan_presentation/01 - First program.ipynb', 'repo_name': 'qBraid/presentations', 'size': '12206'}