<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mustafa Efe Güzel on Medium]]></title>
        <description><![CDATA[Stories by Mustafa Efe Güzel on Medium]]></description>
        <link>https://medium.com/@mustafaefeguzel?source=rss-3e0fb6c3c326------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Mustafa Efe Güzel on Medium</title>
            <link>https://medium.com/@mustafaefeguzel?source=rss-3e0fb6c3c326------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 21:12:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mustafaefeguzel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Coolest Mathematical Constant You’ve Never Heard Of]]></title>
            <link>https://medium.com/@mustafaefeguzel/the-coolest-mathematical-constant-youve-never-heard-of-c7bbabed5e44?source=rss-3e0fb6c3c326------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7bbabed5e44</guid>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Mustafa Efe Güzel]]></dc:creator>
            <pubDate>Fri, 14 Oct 2022 20:39:29 GMT</pubDate>
            <atom:updated>2022-10-14T20:39:29.328Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Suppose we want to model a population of rabbits (or your favorite animal). How do we write an equation for that? If you know about logistic differential equations, you already know the answer. But even if you don’t, no worries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*VhXVlBkuZfNS8iLKWop7zA.png" /></figure><p>where previous_population and next_population denote the rate of the population relative to the maximum population possible.</p><p>Each year, the population will increase based on the birth rate. However, there will be a maximum number of rabbits we can have before they begin having too much competition and the population decreases. That makes sense, right?</p><p>Let’s try plugging in 2.6 as the growth rate, and 0.25 as the initial population. We want to predict how the population changes over the next few years. Try iterating the equation a couple of times and see if you can get anything.</p><p>You should see that after some deviation, the population stabilizes at somewhere between 0.61 and 0.62.</p><p>Now, I want you to play around with the numbers a little bit. Why don’t you try changing the initial population while not touching the growth rate, or vice versa? What do you think is the connection between the two parameters and the population on which we’re eventually settled?</p><p>That’s right — the initial population doesn’t affect the final population. The final population only depends on the growth rate. And intuitively, the higher the growth rate, the more bunnies in the stable population — or is it?</p><h4>Patterns, chaos, and finding order in chaos</h4><p>After we set the growth rate to a value that’s above 3, an interesting phenomenon happens. We begin to bounce between two values without seemingly stabilizing on one population value.</p><p>This phenomenon is called bifurcation, where the stable population value splits into two.</p><p>Let’s increase the growth rate even more, say, to 3.45. Now, there are not only 2, but 4 population values we bounce between! This means that we’ve had another bifurcation.</p><p>The more we increase the growth rate, the more frequent bifurcations become. Going further, we can get cycles with periods of 8, 16, and so on.</p><p>Can we plot a graph of the values we settle on, given the growth rate? Here’s what the graph, commonly known as the bifurcation diagram, looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*uernSWKV4KsdFbxd.png" /></figure><p>This beautiful graph shows us a mind-boggling fact: past a certain growth rate, things become chaotic! To clarify, here chaotic means very difficult to predict, not a state with no rules.</p><p>So if your growth rate is, say, 3.7, it might look like you’re repeating seemingly meaningless numbers forever. But you do move between all of the population values periodically, even if there are tens of them.</p><p>Does this state of chaos go on forever? No! For a small range of growth rates, e.g., on 3.83, we get a relatively stable periodic cycle of 3 years. These windows of obvious pattern aren’t too large though, as chaos returns at around 3.86.</p><h4>How frequent are the bifurcations though?</h4><p>If we were to write down the growth rate differences between bifurcations, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Sf6DpjnFDI0BtNVat92rIg.png" /></figure><p>we can start looking for a pattern between these numbers, and there is one!</p><p>The ratio of the consecutive lengths converges to the number 4.669…<strong> </strong>That number is called<strong> </strong>the<strong> Feigenbaum constant <em>δ</em></strong>, and it’s one of the most underrated numbers in mathematics.</p><p>It’s possible to stumble across this constant in many day-to-day items and phenomena. As an example, a dripping faucet may look like it drips randomly. What’s really surprising is that by adjusting the pressure of the liquid, it’s possible to bifurcate the drops and get chaotic behavior!</p><p>Stay curious!</p><p>References:</p><p>1- <a href="https://www.youtube.com/watch?v=ovJcsL7vyrk">https://www.youtube.com/watch?v=ovJcsL7vyrk</a></p><p>2- <a href="https://www.youtube.com/watch?v=ETrYE4MdoLQ">https://www.youtube.com/watch?v=ETrYE4MdoLQ</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7bbabed5e44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming for Quantum Computing Pt. 2: Qiskit]]></title>
            <link>https://medium.com/quantum-untangled/programming-for-quantum-computing-pt-2-qiskit-53a4c05be281?source=rss-3e0fb6c3c326------2</link>
            <guid isPermaLink="false">https://medium.com/p/53a4c05be281</guid>
            <category><![CDATA[quantum-computer]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[qiskit]]></category>
            <category><![CDATA[quantum]]></category>
            <dc:creator><![CDATA[Mustafa Efe Güzel]]></dc:creator>
            <pubDate>Thu, 24 Jun 2021 14:52:34 GMT</pubDate>
            <atom:updated>2021-06-25T17:13:05.494Z</atom:updated>
            <content:encoded><![CDATA[<p>If you haven’t read our previous <a href="https://medium.com/quantum-untangled/programming-for-quantum-computing-pt-1-numpy-d3e0c5a843ef">article about NumPy</a>, make sure to check it out before reading this article.</p><p>Yeah, NumPy can be useful, but it’s definitely not your only library if you’re doing quantum computing. NumPy is predominantly a math library, but as we know, quantum computing is an intersection of math, physics, computer science and many more fields, so using a plain math library is insufficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*fZ1QhXq20-y6IlYT91WHaw.png" /><figcaption>Qiskit logo. All rights to IBM</figcaption></figure><p><a href="http://qiskit.org/">Qiskit</a>, on the other hand, is an open source library by IBM that is high level and quite comprehensive. Qiskit allows you to build, run, simulate quantum circuits with a wide variety of gates and quantum hardware. Best of all, Qiskit has a brilliant community which supports the development of the library, prepares resources, and organizes events.</p><h4>Getting Started with Qiskit</h4><p>You can install Qiskit with a simple shell command, just like how you installed NumPy:pip3 install qiskit. It is recommended to run Qiskit on Anaconda.</p><p>Another way to use Qiskit is the Quantum Lab of <a href="https://quantum-computing.ibm.com/">IBM’s Quantum Experience</a> service, which is essentially an online Jupyter Notebook, similar to Google Collab, but optimized for quantum development.</p><h4>How does Qiskit work?</h4><p>To explore this framework, let’s have a look at IBM Quantum Experience’s Quantum Composer, which is the drag and drop version of Qiskit. Of course, it doesn’t let you do everything you can do on Qiskit, but it definitely makes understanding Qiskit easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4S8bbymrS_AR63O8GXbO0w.png" /><figcaption>The interface of the Quantum Composer, and a simple test circuit I’ve built</figcaption></figure><p>When you open up the Quantum Composer for the first time, it can be easy to get confused, but it’s quite simple! The lines in the middle symbolize the quantum circuit that you’re trying to run, and right above the circuit are the operator/gates that you can apply to your qubits. On the bottom part, you’ll see some graphs which you can customize per what you want, and on the right edge, you’ll see a bunch of code that we’ll understand later on.</p><p>Your circuit consists of qubits and classical bits; the purpose of classical bits is to store the results of measured qubits. You can click on qubits to remove them, or use the + button to add more.</p><p>Try dragging and dropping some random gates to the qubits below; at this point your circuit doesn’t have to solve a problem, we’re just learning. As you add gates, you’ll notice that the graphs are changing: If you add an X gate (AKA a NOT gate) to q0, the state vector graph moves from 000 with 1 amplitude to 001 with 1 amplitude. If you add an H gate instead, you’ll see that both of these states get 0.707 amplitude each, which is 1/√2. Given the purpose of the X and H gates, these changes on the graph should make sense.</p><p>Don’t forget to add measurements to the end of the circuit. Once you add them, you’ll notice that the measurements have collapsed from a superposition state to amplitude 1 or 0. At first, I thought this was a bug, but it isn’t, since qubits no longer stay in their superpositions after a measurement, and the graphs are designed to simulate that phenomenon.</p><p>Now let’s run this circuit by clicking on the blue button in the top right corner. You’ll be asked to configure some things, choose the quantum computer with the smallest queue and run your circuit. After a few moments, you’ll receive the results of your job, just like how I did with the circuit above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3JUzGLK4sOtQaH3_fK5MJw.png" /><figcaption>Results of the circuit above</figcaption></figure><p>Invite your friends over and pop a bottle of champagne to celebrate that you’ve used a quantum computer for the first time, and then have a look at the results. In that circuit, q0 and q2 were in a |1⟩ state, and the q1 state was in an equal superposition of |0⟩ and |1⟩ states. Any outcome other than |101⟩ and |111⟩ are the result of noise, and should be ignored.</p><p>This is essentially how Qiskit works: You build a circuit with a given number of qubits and classical bits, you add the gates and measurements of your choice, and you run your circuit on hardware. Even algorithms that showcase quantum advantage, like <a href="https://medium.com/quantum-untangled/the-deutsch-jozsa-algorithm-math-circuits-and-code-quantum-algorithms-untangled-f3b28be4cfd3">Deutsch-Jozsa</a> or <a href="https://medium.com/quantum-untangled/grovers-algorithm-mathematics-circuits-and-code-quantum-algorithms-untangled-c4aa47d506e5">Grover’s</a>, can be implemented using Qiskit’s gate and circuit model.</p><h4>OK, let’s start to write some code then!</h4><p>As I said, the Quantum Composer is the drag and drop version of Qiskit, so it is possible to convert Quantum Composer circuits into Qiskit code. In fact, this conversion is automatically done for you — check out the code on the right side! But resist the urge to copy that code, because we’ll write it line by line. I’ll write my code using IBM Quantum Lab, but you can use any other code editor of your preference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0LFZLGA3z7nzmpcbFMdDqw.png" /><figcaption>A Jupyter Notebook on IBM Quantum Lab. The first cell is for login and imports, which I’ve edited.</figcaption></figure><p>First, I usually import everything from those libraries so that I can use all the functions. Although this makes the runtime longer and the from library import * syntax may cause conflicts, it’s OK to do this on small projects.</p><p>Declaring a new circuit is quite similar to declaring a variable:circuitName = QuantumCircuit(numberOfQubits, numberOfClassicalBits). Then, add gates using the circuitName.gate(qubit) method. If you feel confused, have a look at the code I’ve written to replicate the same circuit as shown in the Composer:</p><pre>myCircuit = QuantumCircuit(3,3)<br>myCircuit.x(0)<br>myCircuit.x(1)<br>myCircuit.x(2)<br>myCircuit.h(1)<br>myCircuit.cx(0,1)<br>myCircuit.measure(0,0)<br>myCircuit.measure(1,1)<br>myCircuit.measure(2,2)</pre><p>The first line means that I declared a circuit named myCircuit and assigned 3 qubits and 3 classical bits for the purpose of measurement. Then, I applied X gates to all 3 qubits (0 based indexing as in Python lists — don’t forget!) and a Hadamard gate to the 2nd qubit. The CX gate’s method takes the first argument as the control qubit, and the second argument as the target qubit. And, the measurement method takes the first argument as the qubit, and the second argument as the classical bit which will store the measured value of that qubit. There are many more gate/operator functions built into Qiskit that we can’t cover them all in this article, so you can check out the documentation. You can use the circuitName.draw() method to have an eye on the circuit. You might see this method as circuitName.draw(&#39;mpl&#39;) in other resources, which AFAIK does the same thing with the former.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WwroKkq-pFEZPkG1ZuOGPg.png" /><figcaption>The usage of the .draw() method.</figcaption></figure><p>The numbers next to the measurement arrows show the classical bits they’re connected to, and have nothing to do with the measured values of the qubits.</p><p>Now, let’s have a look at the slightly more complex part, that is running the circuit. Here’s an example code block that runs a circuit:</p><pre>backend = Aer.get_backend(&quot;aer_simulator&quot;)<br>job = execute(myCircuit, backend)<br>result = job.result()<br>counts = result.get_counts(myCircuit)<br>graph = visualization.plot_histogram(counts)<br>display(graph)</pre><p>I admit that this looks complicated, and I copy and paste this every time I run a circuit. You have to specify a backend, i.e. a quantum hardware or simulator that will run your code. I chose to use a simulator since at the time of writing this article, the queue was too long on all the quantum hardware, but if you want to run on quantum hardware you can use provider instead of Aer and enter the name of a system from the list on <a href="http://provider = IBMQ.get_provider(&quot;ibm-q&quot;)">this page</a>. The rest is pretty standard, though you can tweak the command to get different ways of visualization, such as using this code to see the results on the Bloch sphere:</p><pre>backend = Aer.get_backend(&quot;statevector_simulator&quot;)<br>result = execute(myCircuit, backend).result().get_statevector()<br>plot_bloch_multivector(result)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*3W7HIgAX_1kMpN_bgMizDg.png" /><figcaption>The histogram of the circuit results.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*oHdeRJJLhvo-_Yu1hcfO8g.png" /><figcaption>The qubits, shown as Bloch spheres. Perfect if you want to visualize which operation does what.</figcaption></figure><h4>More Qiskit</h4><p>Qiskit is one of the most common quantum computing frameworks, and it offers way more than what we can explain in an article. In fact, the Qiskit I’ve explained in this article is called Qiskit Terra, or “the earth element, the foundation on which the rest of Qiskit lies”. Other Qiskit projects include Qiskit Metal for quantum hardware design, Qiskit Nature for chemistry, and Qiskit Machine Learning for, well, machine learning. If you want to pursue your works in the field of quantum, I recommend you to <a href="https://qiskit.org/advocates/">get involved with the Qiskit community</a>. You can both develop yourself and contribute to the quantum community.</p><p>In this article, we’ve covered Qiskit to build and run quantum circuits on actual hardware. Please follow our publication to not miss out on future quantum content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53a4c05be281" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quantum-untangled/programming-for-quantum-computing-pt-2-qiskit-53a4c05be281">Programming for Quantum Computing Pt. 2: Qiskit</a> was originally published in <a href="https://medium.com/quantum-untangled">Quantum Untangled</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming for Quantum Computing Pt. 1: NumPy]]></title>
            <link>https://medium.com/quantum-untangled/programming-for-quantum-computing-pt-1-numpy-d3e0c5a843ef?source=rss-3e0fb6c3c326------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3e0c5a843ef</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[quantum]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mustafa Efe Güzel]]></dc:creator>
            <pubDate>Thu, 15 Apr 2021 19:49:01 GMT</pubDate>
            <atom:updated>2021-04-16T12:18:18.254Z</atom:updated>
            <content:encoded><![CDATA[<p>Now that you’ve started learning the physics behind quantum computing, you might be wondering: “Hey, to actually use a quantum computer, do you really have to build quantum devices by hand?” And the answer is, well, there is a reason why quantum computers are called computers: they’re programmable!</p><p>In this series, we will be learning to build software to simulate the math concepts and to run on quantum computers. We will be using Python to write our code since it’s a clean, modern, and library-rich language. Please do note, however, that we won’t be covering the basics here, so you should have a grasp of Python fundamentals to follow this series.</p><h3>Getting started with NumPy</h3><p>NumPy is a must-have library if you’re working on scientific stuff with Python. As its name suggests, it can be used to compute almost anything math related, including vectors and matrices which are essential for quantum computing. It comes preinstalled in most systems, but just to make sure, you can run this command on your command prompt/terminal:</p><pre>$ pip3 install numpy</pre><p>… and you’re good to go.</p><p>To run our code, we need a new Python shell or file. I’ll be using shells in my articles, but it’s just a personal preference. Open the one of your choice, and import NumPy:</p><pre>import numpy as np</pre><p>The as np at the end denotes how you will call your library throughout your code. np is the convention, but you can import your library as anything you want, or even remove the as np if you’re fine with numpy.</p><h3>Vectors and Matrices</h3><p>Vectors in NumPy are declared fairly easily and similar to Python’s regular variables. Here is an example:</p><pre>a = np.array([0,2,3,4+2j])</pre><p>This code declares a new vector a with the np.array function, whose parameter is the content of the vector. Two key points on this example:</p><ol><li>The j in this code is nothing but our beloved friend<strong> i (</strong>the imaginary unit). The reason they went with j rather than i is that i is the symbol of current in electrical engineering. Also, always use a number before j, because according to Python, j is a string, so it won’t work in numerical operations. Try 1j instead.</li><li>“a” is a row vector, because NumPy interprets values between the same pair of square brackets as a single row. If you add more pairs of square brackets, the values in the nth pair will be the nth row. This is how we would declare “a” as a column vector:</li></ol><pre>a = np.array([[0],[2],[3],[4+2j]])</pre><p>In the code above, each value between square brackets is an element of the column vector. Don’t forget the outer square brackets, doing so is a common mistake that causes an error.</p><p>Remember that vectors are special kinds of matrices that are one dimensional? Defining matrices aren’t much different from defining vectors.</p><pre>a = np.array([[0,3j],[2,67],[3,354],[4+2j+83657]])</pre><p>Voilà! You’ve just defined a 4×2 matrix! Each group of values in inner square brackets is a row of your matrix, and the outer pair of square brackets surround them all. You can play around with this using as many rows and columns as you want, but just make sure that all of your rows are in the same length. Otherwise, you’ll get list index errors.</p><p>If you want to revise your knowledge about vectors, you can check out <a href="https://medium.com/quantum-untangled/vectors-and-scalars-linear-algebra-for-qc-ee1e25278f77">our article about vectors</a>.</p><h3>Vector and Matrix Operations</h3><p>NumPy has a wide variety of operations that can be applied to vectors and matrices. Let’s start with the most basic ones:</p><pre>a = np.array([[1,2],[3,4],[5,6]])<br>b = np.array([[7,8],[9,10],[11,12]])</pre><pre>&gt;&gt;&gt; a+b <br> array([[8, 10], <br> [12, 14], <br> [16, 18]])<br>&gt;&gt;&gt; a-b <br> array([[-6, -6], <br>[-6, -6], <br>[-6, -6]]) <br>&gt;&gt;&gt; a*b <br> array([[7, 16], <br>[27, 40], <br>[55, 72]]) <br>&gt;&gt;&gt; b/a <br> array([[7. , 4. ], <br>[3. , 2.5], <br>[2.2, 2. ]])</pre><p>You can do the four basic mathematical operations with matrices as long as they’re the same shape. Vector operations work the same way, but there is a caveat with matrix-vector operations: the matrix and vector’s shapes must match. Here’s what I mean:</p><pre>b = np.array([[1,2]]) <br>&gt;&gt;&gt; a+b<br> array([[2, 4], <br>[4, 6], <br>[6, 8]])</pre><p>The code above will work, because we’re calculating the sum of a 3x2 matrix and a 1x2 vector. But what if we try to do something different and use a vector that is smaller or larger?</p><pre>&gt;&gt;&gt; b = np.array([[1,2,3]])<br>&gt;&gt;&gt; a+b<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>ValueError: operands could not be broadcast together with shapes (3,2) (1,3) <br>&gt;&gt;&gt; b = np.array([[1],[2]])<br>&gt;&gt;&gt; a+b<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>ValueError: operands could not be broadcast together with shapes (3,2) (2,1)</pre><p>As a rule of thumb, always take your time to read error messages as they usually contain valuable information to debug your code. Those tracebacks clearly state that if shapes don’t match, you simply can’t do vector-matrix operations.</p><p>After this point, everything that applies to matrices applies to vectors as well, so I’ll just use the word “matrix” to refer to both of them.</p><p>Scalar-matrix operations also work, and there isn’t much to explain for them.</p><pre>&gt;&gt;&gt; a+17<br>array([[18, 19],<br>       [20, 21],<br>       [22, 23]])<br>&gt;&gt;&gt; a*3<br>array([[ 3,  6],<br>       [ 9, 12],<br>       [15, 18]])</pre><h4>Trig Functions</h4><p>NumPy lets you easily use the numerical values inside a matrix as angles. Radians are the default unit, and they’re preferred to use, because they’re more intuitive in a scientific context. Think it this way: In a unit circle, the curve of the angle that is α radians is α units long.</p><p>What if I told you that you can easily apply trigonometrical functions to all the values of a matrix?</p><pre>&gt;&gt;&gt; np.sin(a)<br>array([[ 0.84147098,  0.90929743],<br>       [ 0.14112001, -0.7568025 ],<br>       [-0.95892427, -0.2794155 ]])<br>&gt;&gt;&gt; np.cos(a)<br>array([[ 0.54030231, -0.41614684],<br>       [-0.9899925 , -0.65364362],<br>       [ 0.28366219,  0.96017029]])<br>&gt;&gt;&gt; np.tan(a)<br>array([[ 1.55740772, -2.18503986],<br>       [-0.14254654,  1.15782128],<br>       [-3.38051501, -0.29100619]])</pre><p>In case you’re confused how the sine of 4 is negative, remember that NumPy uses radians by default. If you want to use degrees for any reason, there’s a function for that, just like how there’s a function for everything in NumPy.</p><pre>&gt;&gt;&gt; np.rad2deg(a)<br>array([[ 57.29577951, 114.59155903],<br>       [171.88733854, 229.18311805],<br>       [286.47889757, 343.77467708]])<br>&gt;&gt;&gt; np.rad2deg(45)<br>2578.3100780887044<br>&gt;&gt;&gt; np.rad2deg(np.pi)<br>180.0</pre><pre>&gt;&gt;&gt; b = np.array([[30,45],[60,90],[120,135]])<br>&gt;&gt;&gt; b<br>array([[ 30,  45],<br>       [ 60,  90],<br>       [120, 135]])<br>&gt;&gt;&gt; np.sin(np.deg2rad(b))<br>array([[0.5       , 0.70710678],<br>       [0.8660254 , 1.        ],<br>       [0.8660254 , 0.70710678]])</pre><p>The np.rad2deg() function takes a matrix of radians and returns that matrix, but in degrees. Matrices of degrees and matrices of radians aren’t data types nor anything that are strictly separate. So, this doesn’t mean that you can’t use some functions if the values of a matrix is in degrees, or radians. The np.deg2rad() function does the reverse: it takes a matrix of degrees and returns a matrix of radians, which is the default unit for NumPy operations.</p><p>Given this information, let’s break this code down line by line. First, I asked NumPy for the degree conversion of the matrix a. With a calculator, you can prove yourself that those values are correct. Next, to show that this function is also compatible with regular int (and also float, of course) values, I have converted 45 radians into degrees. np.pi is a constant that returns pi to 15 digits. Since pi radians = 180 degrees by definition, the value we get is 180.</p><p>But all of this code isn’t efficient when you want to apply operations to degrees. Instead, the function you should be using is np.deg2rad() because it converts degrees to radians, which is the unit of operations. I have created a new matrix b to make it easier to explain and printed it out. And, in the last line, I converted b into radians and took the sine of all of its elements.</p><p>We introduce some other common operations in the code block below, one of which being the tensor product, which we’ve reviewed in <a href="https://www.reddit.com/r/QuantumComputing/comments/mrmi1a/simons_algorithm_quantum_algorithms_untangled/">this article</a>!</p><h4>Some Other Matrix Operations</h4><pre>&gt;&gt;&gt; c=np.array([[534],[924]])<br>&gt;&gt;&gt; np.dot(a,c) #Lets you take the dot product of 2 matrices<br>array([[2382],<br>       [5298],<br>       [8214]])<br>&gt;&gt;&gt; np.kron(a,b) #This function takes the tensor product of 2 matrices. Tensor products are also known as Kronecker products, named after the mathematician Leopold Kronecker<br>array([[ 30,  45,  60,  90],<br>       [ 60,  90, 120, 180],<br>       [120, 135, 240, 270],<br>       [ 90, 135, 120, 180],<br>       [180, 270, 240, 360],<br>       [360, 405, 480, 540],<br>       [150, 225, 180, 270],<br>       [300, 450, 360, 540],<br>       [600, 675, 720, 810]])</pre><p>To learn more about this operation, you can check out <a href="https://medium.com/quantum-untangled/tensor-products-linear-algebra-for-qc-8f7bb5020c6c">our article about tensor products</a>.</p><h3>Cool, but how does it link to quantum computing?</h3><p>If you remember, every quantum gate can be represented with a matrix, and every qubit state can be represented with a vector. If you denote your qubits and gates on NumPy, using all those functions, you can simulate quantum computing in a very intuitive way.</p><p>Let’s say that we have two qubits. We want to entangle them by putting in a ψ-plus state. You can do this on NumPy without using Qiskit at all. Even though Qiskit definitely makes things way easier and more convenient, NumPy is a lower level library, and using it will help you build intuition.</p><p>Let’s declare two variables, one for each qubit:</p><pre>&gt;&gt;&gt; qubit0 = np.array([[1],[0]])<br>&gt;&gt;&gt; qubit1 = np.array([[1],[0]])</pre><p>The ground state, also known as the zero state, is the default state for a qubit, thus it’s the value we use when declaring a qubit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*PHZCU-BiiiCFDKTuKJEDKQ.png" /></figure><p>A ψ-plus state is a Bell state in which two qubits always have the opposite value, as seen on the image. In order to create a ψ-plus state, we need to apply the X gate on one qubit and the Hadamard gate to the other qubit first, and then entangle them using the CNOT gate. Let’s define the gates:</p><pre>&gt;&gt;&gt; xGate = np.array([[0,1],[1,0]])<br>&gt;&gt;&gt; hGate = np.array([[1,1],[1,-1]])/np.sqrt(2) #The actual Hadamard gate is usually defined as just [[1,1],[1,-1]], but I normalized it to make things easier<br>&gt;&gt;&gt; cnotGate = np.eye(4)<br>&gt;&gt;&gt; cnotGate[2:,2:] = xGate</pre><p>“Hey, ”, you might ask, “I don’t see an actual definition of the CNOT gate in that code!”. That’s a small trick to blow away the minds of beginners. The np.eye(n) function creates an n×n identity matrix. The other line means “Remove the first two elements of both dimensions from the matrix, and replace the remaining part with the X gate I have previously defined”. Now, there are two reasons why I have done such a thing: a) to make it clear that a CNOT is an identity matrix and an X gate combined, and b) I was too lazy to type the values by hand.</p><p>So, let’s get going. Don’t forget that when you take the dot product of a gate and a qubit, the gate should always be on the left, and the qubit should be on the right. Unlike scalar multiplication, the order does matter in matrices, because matrix multiplication isn’t commutative.</p><pre>&gt;&gt;&gt; qubit0 = np.dot(hGate, qubit0)<br>&gt;&gt;&gt; qubit1 = np.dot(xGate, qubit1)<br>&gt;&gt;&gt; qubit01 = np.kron(qubit0, qubit1)<br>&gt;&gt;&gt; np.dot(cnotGate,qubit01)<br>array([[0.        ],<br>       [0.70710678],<br>       [0.70710678],<br>       [0.        ]])</pre><p>First, we applied a Hadamard gate to the 0th qubit and an X gate to the first qubit with dot products. Then, we took the tensor product of these two qubits and saved it to another variable - no right indexing here. Finally, by applying the CNOT gate, we get the probability amplitudes of these qubits. But what do these numbers mean?</p><p>Think about it as counting in binary. You start with 0, then 1, 10, 11, 100, 101, and so on. The zeroth element of the result vector is the probability of the state 00, the first element is the probability of 01, and you got the point. Looking at the vector we got that has the probability amplitudes, the 00 and 11 states each have 0% probability, and the 01 and 10 states each have 50% probability (that number is the square root of 1/2). Of course, you can calculate circuits with more qubits with this method. For n qubits, your result vector will have 2^n elements.</p><p>Using NumPy, you can simulate many quantum computing circuits in an easier, lower-level way. Please follow our publication to not miss out on Pt. 2, which will be about using Qiskit to build and run quantum circuits on actual hardware.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3e0c5a843ef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quantum-untangled/programming-for-quantum-computing-pt-1-numpy-d3e0c5a843ef">Programming for Quantum Computing Pt. 1: NumPy</a> was originally published in <a href="https://medium.com/quantum-untangled">Quantum Untangled</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>