Backing up WordPress db

It is very important to backup wordpress db. This is done using mysqldump command. In the basic form:

mysqldump -u wpreader --password='password' wordpress > backup.sql

But we need to automate this and protect the password. This is done by following the steps at https://www.linode.com/docs/databases/mysql/use-mysqldump-to-back-up-mysql-or-mariadb/.

First create a user backupagent that has necessary privileges (read and lock tables) to all the databases

mysql> CREATE USER 'backupagent'@'localhost' IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.00 sec) mysql> grant select on *.* to 'backupagent'@'localhost'; Query OK, 0 rows affected (0.00 sec) mysql> grant lock tables on *.* to 'backupagent'@'localhost'; Query OK, 0 rows affected (0.00 sec)

Create a file .my.cnf under $HOME directory that stores

[client] user=backupagent password=backup agent's password (put it in quotes to be safe)

chmod this file to 600. Write a bash script backup.sh

and a cronjobs.txt

and create a crontab:

$ crontab cronjobs.txt

The cron job will run under your credentials but it will only get a handful of environment variables. To see the env variable it gets, I added an entry to the cron file as explained in https://askubuntu.com/a/23438/393311

* * * * * env > /tmp/env.output

Every minute of every day of every week of every month, that command runs. https://serverfault.com/a/162389/77118

with this, I get:

$ cat /tmp/env.output HOME=/home/siddjain LOGNAME=siddjain PATH=/usr/bin:/bin LANG=C.UTF-8 SHELL=/bin/sh PWD=/home/siddjain

Somewhere I read that cron job will inherit all environment variables defined in /etc/environment but that does not seen to be the case above:

$ cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
Posted in Software | Tagged | 1 Comment

Fabric CA Step by Step – Part 2

Restart Fabric CA server. This time we don’t use -b switch since we have a fabric-ca-server-config.yaml from previous run. Even if we used -b switch it will be ignored.

note that it says

2020/03/27 10:38:13 [INFO] The CA key and certificate already exist

so its picking up the key and certificate from previous run.

Register a new user tom

The register command can only be executed by a registrar – only a registrar can register new users.

when fabric-ca-client is run, it runs under identity of a user (except when enrolling a user). This identity is picked from from $FABRIC_CA_CLIENT_HOME/msp by default. This can be overridden using -M switch.

Enroll tom. his credentials will be saved under $PWD/tom. During this time the -M switch acts differently. This time -M switch is used to specify the location where tom’s credentials should be stored.

Next the registrar can check if a user already exists in the CA db using fabric-ca-client identity list command

and retrieve his X.509 certificate if needed using fabric-ca-client certificate list command

if you run above commands with tom’s identity they will fail as tom is not a registrar.

Posted in Software | Tagged | Leave a comment

Step by Step with Fabric CA

fabric-ca-server (v. 1.4.5) can be started without giving it any config or its own self-identity (public cert and private key)
from an empty directory

run below command. in below bob is the bootstrap user and bobpw is his password. we need a user to bootstrap the CA. this user automatically becomes an admin user.

it will automatically generate config file and identity for itself

if you open this config observe following section in it that stores bob and bobpw

if you start the CA and give it a config file, it will ignore the -b switch and use the identities section for bootstrap user and password. try it.

enroll the bootstrap user. from the client directory which is also empty

run

note that it is the client who is generating the private key (and also the CSR) not the server and the client never sends the private key to the server. now have several files in client directory

server logs show

to test if a given public private key-pair match use

lets look inside the sqlite3 db on the server

log in to the sqlite3 db

list tables

list users

the second entry is bob’s hashed password.

list certificates

the server has a copy of the public cert but it does not have bob’s private key.

credentials table is empty

to see the schema of a table (note no semi-colon at end of command)

to log out of sqlite3 use Ctrl+D

Posted in Software | Tagged | Leave a comment

Steps to add Like button to your custom installation of wordpress

WordPress (WP for short) does not come with any like button functionality built-in. You have two choices to add the like button. Use a 3rd party plugin. The caveat with these is that they will send your data to a remote server. Of course, you also have to pay for these services and create an account. The other option is to do-it-yourself (DIY). This post describes the second option.

I used following code https://github.com/JonMasterson/WordPress-Post-Like-System/. So first read through it.

Steps I followed to get it working (with the twentynineteen theme):

  1. Add content of https://raw.githubusercontent.com/JonMasterson/WordPress-Post-Like-System/master/css/simple-likes-public.css to the end of wp-content/themes/twentynineteen/style.css – this defines the styles for button but not the heart SVG.
  2. Add new javascript file simple-likes-public.js under wp-content/themes/twentynineteen/js– this makes the AJAX call to backend when button is clicked.
  3. Add the content of https://raw.githubusercontent.com/JonMasterson/WordPress-Post-Like-System/0.5.3/post-like.php to bottom of wp-content/themes/twentynineteen/functions.phpThis file is really doing most of the work. It also defines the heart SVG in get_liked_icon(). I suggest using font-awesome in this function to display the heart shape instead of a custom SVG. To use font-awesome, add it to the list of downloads:

    data/wordpress/wp-content/themes/twentynineteen/functions.php: wp_enqueue_style( ‘font-awesome‘, ‘https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css’ );

    and modify the get_liked_icon and get_unliked_icon as follows:

    function get_liked_icon() {

    $icon = ‘<span class=”sl-icon”><i class=”fa fa-heart”></i></span>’;

    return $icon;

    } // get_liked_icon()

    function get_unliked_icon() {

    $icon = ‘<span class=”sl-icon”><i class=”fa fa-heart-o”></i></span>’;

    return $icon;

    } // get_unliked_icon()

  4. Another change I made is that I replaced all occurrences of "YourThemeTextDomain" with wp_get_theme()->get( 'TextDomain' ) as this user has commented ref. The other important thing was to comment out all the code that allowed anonymous user to like.
  1. The final step is to edit wp-content/themes/twentynineteen/inc/template-tags.php and add the line echo get_simple_likes_button( get_the_ID() ); in the function twentynineteen_entry_footer(). This will add the button to the posts. I did not add the like button to comments.

Re: shortcode, these are codes like , that you add when authoring your posts. There was no need to add shortcode in php. The [jmliker] shortcode does exactly what echo get_simple_likes_button( get_the_ID() ); does and is defined in function sl_shortcode() in functions.php.

The like button code creates some fields in the wp_postmeta table:

mysql> select meta_key from wp_postmeta; +
Posted in Software | Tagged | Leave a comment

What is Quantum Computing – Part II

1. Summary

  • Definition (from Jack Hidary’s book): A quantum computer is a device that leverages specific properties described by quantum mechanics to perform computation.
  • A quantum computer is not a parallel computer.
  • Any quantum computation is described by a series of matrix multiplications.
  • Not any matrix is permitted. The matrix has to be reversible plus there are other constraints as well imposed by laws of quantum physics.
  • So the whole computation or circuit as it is called – just like we have a Boolean circuit in classical computing – can be reduced to a matrix operation known as the unitary matrix of the circuit denoted by U.
  • The input to the circuit is a familiar bit string of n bits and output is also a n bit string. E.g., with n=4, example input: 0101 and example output: 1100.
  • However, the output of a quantum circuit is not deterministic. A quantum circuit can put the bits into superposition and entanglement with the result that the output bit string is described by a joint probability distribution function ||Ψ||2. So there will be a ||Ψ0000||2 that gives the joint distribution of the output bits when input is 0000 and a different ||Ψ0001||2 that gives the joint distribution of output bits when input is 0001. Keeping the input fixed at 0000 if we make repeated measurements, we will get different outputs (e.g., in one measurement it can be 0011, in another measurement it can be 1010) whose frequency of occurrence will obey ||Ψ0000||2. Take a pause and let this sink in. Now we can see if we have nbits, there are total 2n possible outputs and so ||Ψ||2 for a given input is a real-valued vector of length 2n. And if we consider all the inputs, we get a matrix of order 2n × 2n. This matrix is nothing but ||𝑈||2. The ij entry in this matrix ||𝑈||2𝑖𝑗 is the probability that when the circuit is given input j, the output will be i.
  • We can see from above that it becomes exponentially difficult to simluate the outcome of a quantum computer using a classical computer. That fact in itself provides a somewhat contrived use-case where quantum computers would outperform classical computers and is at the heart of Google’s Quantum Supremacy achievement.
  • Given an input, if the joint probability distribution of output bits can be factored out into a multiplication of individual probabilities i.e., if ||Ψ||2=Π𝑖||𝜓𝑖||2 or taking an example of n=4 bits, if following holds ||Ψ||2=||𝜓𝑎||2⋅||𝜓𝑏||2⋅||𝜓𝑐||2⋅||𝜓𝑑||2. Stated in English we are saying that if the probability we will get an output of abcd – where each of a, b etc. is a 0 or 1 – is equal to the probability that the 0 bit is equal to d which we denote by ||𝜓𝑑||2 and further this number ||𝜓𝑑||2 doesn’t depend on what the other bits are, multiplied by the probability that the 1st bit is equal to c given by ||𝜓𝑐||2 and so on, then this corresponds to the case when there is no entanglement. So the definition of entanglement is a joint pdf that cannot be factored out. If there is no entanglement then we only need to store 2𝑛 numbers for the individual probabilities (0 or 1) of the n output bits to calculate ||Ψ||2 for a given input. But this case does not make for any interesting applications.
  • Superposition is the process that puts a classical bit (a classical bit is a definite 0 or 1) into a quantum state when it is no longer a 0 or 1 but is simultaneously both with some probability. We call this a qubit. What does it mean physically? The spin of an electron is a good candidate for a qubit. Whenever we measure the spin, it is either up or down but before measurement it can be in a superposition of both up and down states. A classical bit is put in a superposition state by application of a Hadamard gate. The application of a Hadamard followed by a controlled not CNOT puts two bits into entanglement. We can see why. The CNOT gate takes two bits as input – one is a control bit and the other is a target bit. The CNOT gate will flip the target bit depending on whether the control bit is set. And the control bit itself is neither 0 or 1. Its in a superposition of the two states. That entangles the two bits as their fate is entertwined now.
  • Superposition and entanglement are the essence of quantum physics.

2. An example: putting it all together

Install the Cirq library by following the steps at https://github.com/quantumlib/Cirq/blob/master/docs/install.md#installing-on-docker

docker pull quantumlib/cirq

Check it works

docker run -it quantumlib/cirq
 python -c "import cirq; print(cirq.google.Foxtail)"
 # should print:
 # (0, 0)───(0, 1)───(0, 2)───(0, 3)───(0, 4)───(0, 5)───(0, 6)───(0, 7)───(0, 8)───(0, 9)───(0, 10)
# │ │ │ │ │ │ │ │ │ │ │
 # │ │ │ │ │ │ │ │ │ │ │
 # (1, 0)───(1, 1)───(1, 2)───(1, 3)───(1, 4)───(1, 5)───(1, 6)───(1, 7)───(1, 8)───(1, 9)───(1, 10)

Run the image

docker run -it quantumlib/cirq

Create a random circuit of 4×4 qubits arranged in a grid. The code is from the book Quantum Computing by Jack Hidary. It uses the cirq.experiments.generate_supremacy_circuit_google_v2_grid method which is no longer available in latest version of cirq but is there in the version of cirq in the Docker image (as of this writing):

root@eb880b341bec:/examples# python Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.
>>> import cirq
 >>> nrows=4
 >>> ncols=4
>>> depth=5
>>> supremacy_circuit=cirq.experiments.generate_supremacy_circuit_google_v2_grid(nrows, ncols, depth, seed=123)
 >>> print(supremacy_circuit)
 ┌──────┐ (0, 0): ───H───@───X^0.5─────────T───────@────────X^0.5───H─── │ │ (0, 1): ───H───@───X^0.5─────────@───────┼X^0.5───T───────H─── │ │ (0, 2): ───H───T─────────────────@───────┼@───────@───────H─── ││ │ (0, 3): ───H───T─────────────────────────┼┼───────@───────H─── ││ (1, 0): ───H───T───@─────────────Y^0.5───@┼───────@───────H─── │ │ │ (1, 1): ───H───T───┼──────────────────────┼───────@───────H─── │ │ (1, 2): ───H───@───┼────@────────X^0.5────@───────X^0.5───H─── │ │ │ (1, 3): ───H───@───┼────┼X^0.5───T────────────────────────H─── │ │ (2, 0): ───H───@───@────┼────────Y^0.5───T────────────────H─── │ │ (2, 1): ───H───@───X^0.5┼────────@───────@────────X^0.5───H─── │ │ │ (2, 2): ───H───T────────@────────@───────┼X^0.5───@───────H─── │ │ (2, 3): ───H───T─────────────────────────┼@───────@───────H─── ││ (3, 0): ───H───T─────────────────────────┼┼───────@───────H─── ││ │ (3, 1): ───H───T─────────────────────────@┼───────@───────H─── │ (3, 2): ───H───@───Y^0.5─────────T────────┼───────────────H─── │ │ (3, 3): ───H───@───X^0.5─────────T────────@───────X^0.5───H─── └──────┘

Increasing the depth of the circuit will expand it in the horizontal direction (i.e., more to the right) and insert more quantum gates. Let’s calculate the unitary of this circuit:

>>> U = cirq.unitary(supremacy_circuit)
 Killed

Oops! well, we have 16 qubits, meaning we are trying to calculate a matrix of 216 x 216 complex numbers. This will take total

>>> import math
>>> a=math.pow(2,16)
 >>> a*a*2*4 34359738368.0

bytes (this is 34GB in case you missed it) assuming each real number is stored as 4 byte float. So we can see its very difficult for classical computers to simulate what we will get from a quantum computer.

Let’s reduce the circuit to 3×3 qubits and try again

>>> import cirq
 >>> nrows=3
>>> ncols=3
 >>> depth=5
>>> supremacy_circuit=cirq.experiments.generate_supremacy_circuit_google_v2_grid(nrows, ncols, depth, seed=123)
 >>> print(supremacy_circuit)
 (0, 0): ───H───@───X^0.5────T───────@────────────X^0.5───H─── │ │ (0, 1): ───H───@───X^0.5────@───────┼────Y^0.5───T───────H─── │ │ (0, 2): ───H───T────────────@───────┼────@───────X^0.5───H─── │ │ (1, 0): ───H───T───@────────X^0.5───@────┼───────@───────H─── │ │ │ (1, 1): ───H───T───┼─────────────────────┼───────@───────H─── │ │ (1, 2): ───H───T───┼────@───Y^0.5────────@───────X^0.5───H─── │ │ (2, 0): ───H───@───@────┼───X^0.5───T────────────────────H─── │ │ (2, 1): ───H───@───X^0.5┼───@───────X^0.5────────T───────H─── │ │ (2, 2): ───H───T────────@───@───────Y^0.5────────T───────H───

Ready to calculate unitary? Try it:

>>> U=cirq.unitary(supremacy_circuit)
 >>> import numpy
 >>> numpy.shape(U) (512, 512)

Let’s see Ψ0 – the wave function when input to the circuit is 000000000 (remember we have 3×3 or 9 qubits). Its a complex valued vector. The first 3 elements are shown:

>>> psi_0 = U[:,0]
 >>> psi_0[0:3]
 array([-0.00457646-0.02209709j, -0.03772209-0.00457646j,
-0.05334709-0.03314563j])

Measuring the circuit will collapse the wave function to a definite state and the probabilities of getting 000000000, 000000001, 000000010, 000000011 and so on in the output will be given by the square of the modulus (also known asamplitude) of the complex numbers. We can calculate it like this

>>> prob = numpy.square(numpy.abs(psi_0))

Verify

>>> numpy.sum(prob)
 1.0000000000000018

Let’s take a random entry in the matrix U

>>> U[45,33]
 (-0.06897208691207966+0.03772208691207965j)

What does this entry mean? It means that if this circuit is fed an input of

>>> "{0:09b}".format(33)
 '000100001'

the output will be

>>> "{0:09b}".format(45)
 '000101101'

with a probability

>>> numpy.square(numpy.abs(U[45,33]))
 0.006180104614009962

Google’s quantum supremacy experiment generated a random circuit of 𝑛×𝑛 qubits. They then keep the input fixed at 000⋅⋅⋅000 and sample the output of the circuit many times. The results from sampling the output are used to create a pdf which is then verified against the expected pdf calculated using a classical computer. This tells them that the quantum circuit is behaving correctly. They slowly increase n until they reach a point (n=52) where calculation of expected pdf using a classical computer becomes infeasible – the moment of quantum supremacy.

One can see that one natural application of quantum computers will be to generate truly random numbers. This corresponds to a wave function where each ||𝜓𝑖||2=𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 corresponding to a uniform pdf.

There are two challenges in quantum computing: One is that keeping the qubits entangled and superimposed becomes very difficult as the number of bits and the depth of the circuit increases. This is the hardware challenge and this is what Google accomplished with their recent results on quantum supremacy. The other is finding problems that can be expressed as quantum computations – where quantum computing can outperform classical computing. This is the software challenge. The famous example is Shor’s factorization algorithm which can be used to break RSA cryptography that forms the backbone of secure communications between computers today, but it will take sometime for it to become practical since the number of qubits it requires is outside what today’s quantum computers can provide.

Posted in Software | Leave a comment

Fabric JIRA queries and links to uncommon resources

To see the issues that I am watching (https://stackoverflow.com/a/45876107/147530)

https://jira.hyperledger.org/browse/FAB-17584?jql=key%20in%20watchedIssues()%20ORDER%20BY%20created%20DESC

or navigate to Issues -> Search and type

key in watchedIssues() ORDER BY created DESC

To see the issues I have filed

https://jira.hyperledger.org/browse/FABN-1234?jql=reporter%20%3D%20siddjain

or type reporter = siddjain in search bar

Questions I have asked on Fabric DL: https://lists.hyperledger.org/g/fabric/search?ev=false&q=posterid%3A1540551&ct=1

list open issues of node-sdk

labels = node-SDK and status != Complete

https://jira.hyperledger.org/issues/?jql=labels%20%3D%20node-SDK%20%20and%20status%20!%3D%20Complete%20

Community Calls: https://wiki.hyperledger.org/display/fabric/Fabric+Application+Developer+Community+Calls

Posted in Software | Tagged | Leave a comment

A note on how environment variables are handled in Bash

Say you h​ave a bash script that looks like


​#!/bin/bash
SOME_VARIABLE=hello
some_program

where some_program ​is just some executable. Further this script is executed like

$ FOO=bar ./my_script.sh

Observation: the variable FOO=bar ​will make it to some_program ​whereas SOME_VARIABLE=hello ​will not.

To pass SOME_VARIABLE=hello to some_program turn on following flag in your script:

set -a

or put SOME_VARIABLE=hello on the same line as some_program in the script as shown below:

SOME_VARIABLE=hello some_program

It can be tested as follows

  1. Create a file JavaEnvironmentVariables.java with this code
  2. Compile this program by running
    ​$ javac JavaEnvironmentVariables.java
  3. ​Write test script as follows
    #!/bin/bash

    SPAM=eggs

    java JavaEnvironmentVariables

  4. Chmod755 the script and execute it
    $ FOO=bar ./my_script.sh
  5. Observe that FOO=bar makes it to the java program but SPAM=eggs does not
    Now re-run the script again but this time add set -a to the script

    #!/bin/bash

    set -a

    SPAM=eggs

    java JavaEnvironmentVariables

  6. Verify

    $ ./my_script.sh | grep SPAM

    SPAM=eggs

Posted in Software | Leave a comment

Debugging Go code with Delve Command Line Debugger

This post contains some notes on how to debug Hyperledger Fabric codebase that is written in Go. It is not meant to be an exhaustive tutorial and there can be gaps in documentation. The intent is to capture some notes that may be useful later on. First step is to clone the Fabric repository. Then install Go and Delve. After that a debug session can be started like

this gave me

Next I wanted to stick a breakpoint in https://github.com/hyperledger/fabric/blob/release-2.0/core/chaincode/lifecycle/serializer.go#L290.

To do that enter

break <filename>:<line>

as shown below

then enter continue to continue the execution i.e.,

(dlv) continue

below is screenshot when breakpoint is hit

we can see the arguments passed to the function by typing args

we can see the local variables by typing locals

we can inspect a variable using the print command

the print command cannot evaluate function calls. it can only inspect things that have been evaluated and are sitting in memory. One problem you might run into is that print truncates the output and limits the display of long strings to 64 characters or so. To display more than 64 characters use the slice operation as described here.

It looks like there is no way to evaluate function calls. There is a command call but its experimental and note that it resumes execution of the code so be careful when trying to use it. when I tried it I got error

https://github.com/go-delve/delve/issues/1910

you can check where you are at any point by using list command

and you can move to next line by using next command

To step into a function use the step command. E.g., in below we are at

Screen Shot 2020-03-03 at 5.10.02 PM

and running step will step into the function IsDevMode as shown below

Screen Shot 2020-03-03 at 5.11.52 PM

Use stepout to step out of a function

to see the current callstack use the stack command

Screen Shot 2020-03-04 at 11.11.25 AM

To move down the stack use the up command (yes its not a typo)

up

and to move up the stack use the down command

down

we can use git grep -n command to search for some string in the codebase. E.g.:

Screen Shot 2020-03-04 at 11.36.20 AM

and then we can use break to insert breakpoints at those lines. E.g.:

Screen Shot 2020-03-04 at 11.36.48 AM

To see all your breakpoints use the breakpoints command

To exit the debugger use exit

To recap, we covered following functions of delve. This should be enough for most of your debugging needs.

  • print
  • break
  • breakpoints
  • continue
  • list
  • next
  • step
  • stepout
  • locals
  • args
  • stack
  • up
  • down
  • exit
could not find symbol value for github.com/hyperledger/fabric/core/chaincode/platforms/util · Issue #1910 · go-delve/delve
What version of Delve are you using (dlv version)? $ dlv version Delve Debugger Version: 1.3.2 Build: $Id: 569ccbd514fc47c8b4c521b142556867ec5e6917 What version of Go are you using? (go version)? $…
github.com

reference: https://github.com/go-delve/delve/tree/master/Documentation/cli

delve/Documentation/cli at master · go-delve/delve · GitHub
Adds an optional scope prefix to the `regs` command which allows printing registers for any stack frame (as long as they were somehow saved). Issue #1838 is not yet to be closed since we are still not recovering the registers of a segfaulting frame. Updates #1838
github.com
Posted in Software | Leave a comment

What is Quantum Computing?

1. Abstract

This article is my attempt to explain and understand what is quantum computing. As I am new to the subject and learning it myself, the information contained in the article could be potentially wrong. But it would be an interesting exercise to write this brief article documenting what I think it is – based on just a few hours of reading a book – and see if my understanding was correct as time passes by and I learn more about the subject.

2. So what is it?

I’d like to give the analogy of Fourier Optics as for me analogies are the best way I understand things. From Wikipedia, see the section titled Fourier transforming property of lenses: If a transmissive object is placed one focal length in front of a lens, then its Fourier transform will be formed one focal length behind the lens. So if you want to compute a 2D Fourier Transform (FT) you could do it the conventional way where you write some code in your favorite programming language, run it on a computer and get the result. Or another way to “compute” the FT would be to use a lens and its Fourier transforming property. The Wikipedia article goes on: “All FT components are computed simultaneously – in parallel – at the speed of light. As an example, light travels at a speed of roughly 1 ft (0.30 m) / ns, so if a lens has a 1 ft (0.30 m) focal length, an entire 2D FT can be computed in about 2 ns (2 x 10−9 seconds). If the focal length is 1 in., then the time is under 200 ps. No electronic computer can compete with these kinds of numbers or perhaps ever hope to, although supercomputers may actually prove faster than optics, as improbable as that may seem. However, their speed is obtained by combining numerous computers which, individually, are still slower than optics.”

Quantum Computing is completely analogous. The behavior/evolution of quantum particles or a quantum system can be described by operation of matrices – linear algebra. The equations governing quantum mechanics are linear – that is why a quantum particle or system can exist in superposition of states because for a linear equation if X and Y are solutions, then any linear combination of X and Y is also a solution. So say you have a problem which requires you to calculate something which is nothing but basically a sequence of special matrix operations. You could do it the conventional way, or if you could build a quantum system (circuit), you could let it evolve and monitor (measure) it to get the answer – that is basically a quantum computer.

Conventional computers are Turing machines which evaluate Boolean logic. Quantum computers evaluate matrix operations and using the property of entanglement they can run many inputs in parallel. Boolean logic is composed of a handful of operators – OR, AND, NOT and combinations of those. In case of QC we have special matrices that form the building blocks. Conventional computers speak the language of Boolean Logic. Quantum Computers speak and understand the language of matrix computations.

There are two things from which quantum computers derive all their power – superposition and entanglement.

3. Challenges

The challenge with QC is that building a quantum system is hard and the difficulty increases as the number of particles (i.e., number of qubits) to be entangled increases. The system can quickly get disentangled due to decoherence so the challenge is in being able to build and control the system. This is the hardware challenge. Another challenge is finding useful problems that can be expressed as quantum computations. Computing 2D FT is is very useful problem in image processing. We need to find useful problems that can be expressed as quantum (err.. matrix) computations. This is the software challenge.

A bibliography of quantum algorithms is available at https://quantumalgorithmzoo.org/ – these are essentially the use-cases. If you have a problem that can be reduced or mapped to one of these cases, then you can use a QC to solve it. However there is a catch here that many algorithms require using a number of qubits which is out of reach of today’s quantum computers. E.g., Shor’s algorithm for factorization is a famous example of quantum computation that can be used to break RSA cryptography. But it requires a # of qubits which is out of reach of today’s QC. The hardware challenge is being solved by companies like Google and IBM. They will make quantum computers and make them accessible via the cloud just like we can access GPU and other beefy machines today using AWS or other cloud providers.

One of the things I have noticed in my limited exploration of this topic is that the current software libraries for quantum computation (Google’s Cirq and Microsoft’s Q# are some examples) are high-level languages but the code is written to express a “low-level” quantum circuit. Its like asking you to program a classical computer by writing code to create the underlying Boolean Logic circuit – no one does that these days. I wonder if in future the libraries will evolve so that one does not have to write a “low-level” circuit. Maybe its the way it is because quantum computer has an advantage over classical computer only when the computation can be expressed as a quantum circuit – basically a sequence or flowchart of special matrix operations – special because not every matrix operation is qualified to be permitted in a quantum circuit. Only special matrix operations are permitted – in particular the matrices must be invertible.

4. What does Google’s recent Quantum Supremacy claim mean?

Google’s recent announcement of Quantum Supremacy made big news every where. What is it about? It basically demonstrated that they were able to build a 54-qubit processor and put it to some use. Its about the hardware challenge. Building a QC becomes very difficult as the number of qubits increase because its very difficult to keep them entangled and pure and prevent them from getting disentangled as the computation progresses (the depth of the circuit). The problem they solved was not interesting per se – they sampled the probability distribution resulting from a random circuit. The input to the problem is a state vector that can take on 2n possible values where n is the number of qubits. This state vector essentially undergoes transformation by a random quantum circuit to yield the output vector. This output vector can be in so many states and we are interested in finding or rather sampling from its probability distribution. Google team did this computation using both a quantum computer as well as a classical computer. They then compared result of QC with result of classical computer to validate and verify that the QC was giving correct results – this would not have happened if the qubits had gotten disentangled. Sotheir achievement was in being able to demonstrate a system that could control and keep 54 qubits in entanglement through the course (depth) of their circuit. Ultimately as n increases they reach a point where classical calculation becomes infeasible.

5. Quantum Computing: Pop Quiz

Think you understand quantum computing. See if you can answer following question:

In QC, it is said that the quantum state of N qubits can be expressed as a vector in a space of dimension 2N. E.g., if you have 1 qubit there are two state vectors (0,1) and (1,0) which are written as |0> and |1> respectively. For a system of 2 qubits, there are 4 state vectors (0,0,0,1), (0,0,1,0), (0,1,0,0) and (1,0,0,0) written as |00>, |01>, |10>, |11>. Note that in each case, all entries are zero except 1. 2N seems like a big space but given a vector in this space – all components will be zero except 1. So there are only 2N possible values the state vector can take. So why don’t we say the space is N dimensional? A N-bit string has 2N possible values. To make the question more provocative, the total memory required to store the state vector is claimed to be of the order of 2N. This quickly becomes out of reach when we try to do classical simulation and is at the heart of Google’s Quantum Supremacy. For system of only 50 qubits we would need petabytes of storage to store the state vector. But we only need N bits to store the position of the 1 in the state vector – rest all entries are zero. So what gives?

Posted in Science | Leave a comment

Generating random passwords

[software]


here is a useful command to generate a random password from the command line

$ openssl rand -base64 8
BTz1bGHrs6s=

change the last argument to change the length of the password

Posted in Software | Leave a comment