Quantum-Prerequisites

Prerequisites:

Prerequisite1:(Linear Algebra) (4 hours)
Linear Algebra: All the quantum gates are unitary matrices and each Quantum Operation is obtained by applying different techniques of linea>

1.1. Definition and Properties of Vectors
1.2. Vector Operations (Addition, Subtraction, Scalar Multiplication)
1.3. Definition and Properties of Matrices
1.4. Matrix Operations (Addition, Subtraction, Scalar Multiplication)
1.5. Matrix Multiplication
1.6. Transpose and Inverse of Matrices

1.7. Eigenvalues and Eigenvectors

Prerequisite2(Python+Numpy): (8 hours)

All the Quantum Gates and Quantum Operations will be performed by leveraging the power of Numpy’s model of vector computation. As most of t>

  1. Introduction to Numpy

2.1. Introduction to NumPy

2.2. NumPy Arrays and Operations
2.3. Solving Systems of Linear Equations with NumPy
2.4. Eigenvalues and Eigenvectors with NumPy
2.5 Matrix Operations and Transformations using NumPy

[Part-2]Quantum Course Syllabus[Project Work]

Project 1:

Creation of HPC Quantum Cluster using Python based distributed-computing Libraries to create Multi-Qubit system.

Project 2:

Creating Hybrid Machine Learning models where Quantum Algorithms will be used alongside Traditional ML Algorithms like Neural-Network to increase the performance of ML-Models.

Project 3:

Creating a Cloud based Quantum-Computing system to make it open for students and professors of other Universities to collaborate.

Project4:

Specific Training to become IBM certified Qiskit brand Ambassador. Qiskit is Quantum Computing Framework developed by IBM.

Project5:

Creating Quantum Simulator from Scratch using JuliaLang to run on Google TPU. This Simulator will be dedicated to run on Google TPUs which will be one of the Unique and Fastest ever created.

[Part-1][Quantum Course Syllabus] Introduction to Quantum Realm, Practical approaches of Quantum Computing in Software Engineering and Machine-Learning

Theoretical Section: (Part 3 to 7) (32-48 hours)(4 days to One Week))

Before Working with Quantum Computations it is very important to understand/Evaluate some of the very basic Questions that why such phenomenon even exist? , What is the need of Quantum Computer ? From Where the word Quantum is coming? What are the basics Units of Quantum Operations?

3. Quantum mechanics and associated phenomena

3.1 The Ultraviolet catastrophe
3.2 The Photoelectric effect
3.3 The Double-slit experiment
3.4 Quantum Superposition
3.5 Quantum Entanglement

4. Quantum Logic gates

4.1. Pauli gates
4.2. Hadamard gate
4.3. Rotation gates

4.4. Multi-qubit gates

5. Quantum Circuits
5.1 HZH Circuit
5.2 Bell Circuit
5.3 Phase Kickback
5.4 GHZ Circuit
5.5 W State Circuit

6. Quantum logic gates

6.1 Pauli gates
6.2 Hadamard gate
6.3 Rotation gates
6.4 Multi-qubit gates

7. Quantum Algorithms

7.1 The Deutsch-Jozsa algorithm
7.2 Bernstein-Vazirani Algorithm
7.3 Superdense Coding
7.4 Quantum Teleportation
7.5 Quantum Key Distribution using the BB84 protocol100
7.6 Quantum Fourier Transform
7.7 Shor’s Algorithm
7.8 Quantum Phase Estimation
7.9 Grover’s Algorithm

Practical Section (Coding and Development of Quantum Algorithms) (7-10 days of work)

In the Machine-Learning World we have Frameworks like TensorFlow, PyTorch, Jax and Many more to build, train, test Quantum Algorithms, Same in the section of Quantum World we have following Popular Frameworks which comes with their own set of Rules and approaches of developments of Quantum-algorithms.

Some of the Well Known Frameworks are as follows.

  1. Qiskit Framework (Based on Python, developed by IBM) (1.5 days)
    2. Cirq (based on Python, C++, developed by Google) (1.5 days)
    3. Bracket(based on Python, Developmed by Amazon) (1.5 days)
    4. Pennylane(based on Python, Developed by Xanadu) (1.5 days)
    5. Yao (based on Julialang, Developed by Chinese Academy of Sciences) (1.5 days)

In the practical Section, All the Quantum-Algorithms studied in Theoretical-Section will brought into life and Exploration of Practical use cases of Quantum-Algorithms will be introduced.

Practical use Cases of Quantum Technologies in Industry: (Advance Section for Future Software Engineers) (15-20 days)

  1. Development of Hybrid Quantum Models with the combination of Machine Learning models.
    2. Participation into Quantum Hackathon and recognition.
    3. Guide to Open source Contribution into Quantum Technologies.
    4. Implementation of Quantum Technologies into Finance World. (Stock’s Trading)
    5. Implementation of Quantum Technologies into Network-Communication world.
    6. Implementation of Quantum Technologies into Supply Chain Industry. (E-Commerce)
    7. Implementation of Quantum Technologies into internet Security.

Basic Quantum Gates implementation in Numpy! [Single Qubit Only!]

In this blog post, we will discuss how to implement some common quantum gates using NumPy in Python. We will cover single-qubit gates like Pauli-X, Pauli-Y, Pauli-Z, Hadamard, S-gate, T-gate, U1, U2, U3, and rotation gates (Rx, Ry, and Rz). These gates form the building blocks for more complex quantum circuits and algorithms.

First, let’s import the necessary libraries:

python
import math
import numpy as np

Now, we define the Pauli-X, Pauli-Y, and Pauli-Z gates:

python
# Pauli-Gate
pauli_x = np.array([[0, 1], [1, 0]])
pauli_y = np.array([[0, -1j], [1j, 0]])
pauli_z = np.array([[1, 0], [0, -1]])

Next, we define the Hadamard gate, which creates superposition states:

python
# Hadamard Gate
hadamard_gate = 1 / np.sqrt(2) * np.array([[1, 1], [1, -1]])

The S-gate, also known as the phase gate, applies a phase shift to the |1⟩ state of a qubit:

python
# S-gate (phase-gate)
s_gate = np.array([[1, 0], [0, 1j]])

The T-gate is another phase gate that applies a π/4 phase shift to the |1⟩ state:

python
# T-Gate representation
t_gate = np.array([[1, 0], [0, np.exp(1j * np.pi / 4)]])

The U1, U2, and U3 gates are general unitary gates that can represent any single-qubit transformation:

python
def get_U3(theta, lamda, psi):
    U3 = np.array([[math.cos(theta/2), -np.exp(1j * lamda) * math.sin(theta/2)],
                   [np.exp(1j * psi) * math.sin(theta/2), np.exp(1j * (psi + lamda)) * math.cos(theta/2)]])
    return U3

def get_U2(lamda, psi):
    theta = math.pi / 2
    return get_U3(theta, lamda, psi)

def get_U1(lamda):
    theta = 0
    psi = 0
    return get_U3(theta, lamda, psi)

Finally, we define the rotation gates Rx, Ry, and Rz, which perform rotations around the X, Y, and Z axes of the Bloch sphere, respectively:

python
def rotate_X(theta):
    rotation_X = np.array([[math.cos(theta/2), -1j * math.sin(theta/2)],
                           [-1j * math.sin(theta/2), math.cos(theta/2)]])
    return rotation_X

def rotate_Y(theta):
    rotation_Y = np.array([[math.cos(theta/2), -math.sin(theta/2)],
                           [math.sin(theta/2), math.cos(theta/2)]])
    return rotation_Y

def rotate_Z(theta):
    rotation_Z = np.array([[np.exp(-1j * theta/2), 0],
                           [0, np.exp(1j * theta/2)]])
    return rotation_Z

With these functions, we have implemented a set of fundamental quantum gates using NumPy. These gates can be used as building blocks to create more complex quantum circuits and algorithms in Python.

Data-Models [Part-2]Related to Architectural Designs

MVC pattren Model-VIEW-Controller

Model : Responsible to Manage the data-Model
Controller: Responsible to accept the data from user and transform i
it to manipulate data.
View: Representation to the user.

Data-Model

Relational databases
Non-Relational Databases
Small Databases like SQL-Lite

The primary key is used to reference that record, when necessary, in
other tables. This creates the relation aspect of the database. When a
column in a table makes reference to another table, this is called a
foreign key.

Non-relational

Key-Value Store
Document Store
Wide-Column database (Casandra and BigTable by Google)
Graphdatabase – (Neo4J)

Database-Transactions:

Atomicity in DataBases.

Atomicity assures the transactions should be fully completed or should not be executed at all. for example in the Banking application the transactions for deduct and credit happen at the same time, if any of the process fails then all transaction should roll-back!

Consistency in DataBases:

Consistency assures the redundancy in Databases. For example in the library management system one is keeping all the books by unique identification number. So to keep the entries unique before each new record database should check if new entry for specific Book ID is existed or not, Otherwise new entry will fail.

Isolation in Databases:

For example there are two transactions which are running concurrently.

1. Keeping total balance of all the accounts of the bank

2. Transferring the balance from account1 to account2.

Both of the above transactions on DB level should run in Some-Sequence to it will not effect each other.

For example, the transaction calculating the total balance should see a consistent view of the data and should not be affected by the ongoing transfer between Account X and Account Y.

Durability:
Suppose you successfully transfer $200 from Account C to Account D. Once the transaction is committed, the durability property ensures that the changes made by the transaction are permanent, even in the event of system failures, crashes, or power outages. This means that after the transaction is completed, the new account balances are safely stored and can be retrieved, ensuring the integrity of the data in the database.

for example
ACID properties in Database. (Atomicity, Consistency, Isolation, Durability)

Distributed Relational Databases.

Three SQL Databases.
One is for Write Queries.
Replication will happen each time! (There will a replication Lag!)
two will be for Read Quires.

  • If there is an issue then Replica can be promoted to new-primary!

Sharding:

A possible solution is to horizontally partition the data. This means
dividing the data into different databases according to a specific key,
so all related data can go to the same server. Each of the different
partitions is called a shard.

  • Sharding can be considered as Horizontal-partitioning.
    There could be many other types of partitions as well!
  • Pure-Sharding!
  • Mixed-Sharding!

Disadvantages of Sharding:

  1. System and Configuration becomes very complicated.
  2. Native support for sharding is available only in a small number
    of databases, like MongoDB, but relational databases don’t have
    the feature implemented natively. This means that the
    complexity needs to be handled with ad hoc code, which will
    require an investment in developing it.

Schema Design

  1. many to many
  2. One to many
  3. One to Zero

Schema Normalization

Data Indexing

Data layer

Using ORMs:

  1. SQLALchemy
  2. DjangoORM
  3. PonyORM
  4. Pewee
  5. GORM

[API-Design][Part-1]Related to Architectural Designs

Conway’s Law:

https://www.thoughtworks.com/insights/articles/demystifying-conways-law

Micro-Services By Thoughtworks:

https://www.thoughtworks.com/insights/blog/microservices-nutshell

Two important values while designing the system.

  • What kind of interface we will be using.(API Design)
  • How the data should be saved inside the System.(Data Modeling)

Things to know while designing APIs(Restful APIs)

  • Abstractions
  • Leaky-Abstractions

RESTFUL Interfaces:
It uses HTTP Interface as Basis to use the Software/System.

  1. Client-Server Interface
  2. Stateless
  3. Cache ability
  4. Layered System
  5. Code On Demand

While Designing the REST-APIs headers are one of the most important
parts.

All the Headers Can be found here;
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

Statuses for REST APIs:

  • 200 Will return OK for status and return BODY.
  • 201 Created- Or POST OK
  • 204 OK request but does not return Body, For Example DELETE or PATCH
  • 301 Resource has been moved permanently to different URI, It should return with URI
    address. For example movement of Http to https
  • 302 Resource has been moved to different URI temporary.
  • 304 – what is 304? Not sure!
  • 400 – A generic Error in the Request, Seems the wrong of sending request.
  • 401 – Unauthorized, You are not authenticated to make that Request.
  • 403 – Authentication is done but authorization is also required!
  • 404 – The resource used by URI cannot be found!
  • 405 – The requested method cannot be used. for example not able to delete.
  • 500 – generic error in the server,
  • 502 – bad Gateway, when service is not available or something else!!
  • 503 – Service unavailable.
  • 504 – 502 bad gateway, when service is not able to respond in the given time!

Pagination:

Pagination is important to implement into the API design, so that one will
not confuse with lots of data either.

Generate API-Code from Swagger of YAML
[Python]https://medium.com/@ratrosy/building-apis-with-openapi-ac3c24e33ee3
[Go-Lang] https://github.com/getkin/kin-openapi
[Go-Lang] Swagger?
[Python] https://pypi.org/project/connexion/


Same as we write .Proto Files and Proto-Server and client is being Generated!

API Specifications.

All the API specifications:

  1. Request Structure
  2. Response
  3. Request-headers
  4. Request-Body

API-Authentication

Authentication is another important Aspect of REST APIs,
we need to understand and work on one of more authentication methods!

Oauth2 – Not a protocol but certain ideas like how Authentication can be done!

JWT = JSON WEB token, need to know/understand more about JWTs

JWT has following values:

  1. Header
  2. Body
  3. Signature

API-versioning

With time many things do change for APIs like implementation-logic,
database, server and other things related to infrastructure.
We need to make sure to use specific versioning strategy and need to maintain
the versions as well.

MVC pattern Model-VIEW-Controller

Model : Responsible to Manage the data-Model
Controller: Responsible to accept the data from user and transform i
it to manipulate data.
View: Representation to the user.

Fixing GPU issue on Ubuntu-Linux(Nvidia, CUDA, Linux, Ubuntu, Tensorflow, Deep-Learning)

https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tensorflow

To run NVIDIA GPU Cloud (NGC) containers on Ubuntu, you’ll first need to set up NVIDIA Container Toolkit (previously known as NVIDIA Docker). Here’s a step-by-step guide:

  1. Update your system: Update your package list and installed packages to the latest versions:
$ sudo apt-get update
$ sudo apt-get upgrade

  1. Install Docker: If you don’t have Docker installed, follow the instructions to install Docker for Ubuntu: https://docs.docker.com/engine/install/ubuntu/
  2. Install NVIDIA Drivers: To use the GPU, you need to install the NVIDIA drivers for your specific GPU. Follow the instructions in the official NVIDIA documentation: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu-installation
  3. Install NVIDIA Container Toolkit: Add the NVIDIA package repositories and install the NVIDIA Container Toolkit:
  4. Also find required driver’s version from Nvidia’s website, After checking the version you can also check https://www.nvidia.com/Download/index.aspx?lang=en-us
# Add the package repositories
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

# Update the package list
sudo apt-get update

# Install the NVIDIA Container Toolkit
sudo apt-get install -y nvidia-docker2

  1. Restart Docker: Restart the Docker daemon to apply the changes:
sudo systemctl restart docker

  1. Run an NGC container: Now you can run an NGC container using Docker. For example, to run the latest TensorFlow container:
docker run --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 -it --rm nvcr.io/nvidia/tensorflow:22.02-tf2-py3

This command will download the latest TensorFlow container from the NGC registry and run it with GPU support. Once inside the container, you can use TensorFlow as usual, and it will leverage the GPU for computation.

For other containers, replace nvcr.io/nvidia/tensorflow:latest with the desired container image. You can browse available containers at https://ngc.nvidia.com/catalog/containers.

Go-Lang Secure Server Notes

Golang Security Notes while creating a Server.

You also need to learn more about TLS from following Link:
https://www.cloudflare.com/learning/ssl/transport-layer-security-tls/

Currently, the only acceptable TLS protocols are TLS 1.2 and TLS 1.3.

TLS = Transport Layer Security
SSL =

  1. Crypto-TLS work!

* ListenAndServeTLS() how to pass more variable to this?

[Most-important]* However, you should still set PreferServerCipherSuites to ensure safer and
faster cipher suites are preferred, and CurvePreferences to avoid unoptimized
curves: a client using CurveP384 would cause up to a second of CPU to be consumed on our machines.

&tls.Config{
// Causes servers to use Go’s default ciphersuite preferences,
// which are tuned to avoid attacks. Does nothing on clients.
PreferServerCipherSuites: true,
// Only use curves which have assembly implementations
CurvePreferences: []tls.CurveID{
tls.CurveP256,
tls.X25519, // Go 1.8 only
},

}

*Most-Secre with compatibility issues!.
MinVersion: tls.VersionTLS12,
CipherSuites: []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, // Go 1.8 only
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, // Go 1.8 only
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,

    // Best disabled, as they don't provide Forward Secrecy,
    // but might be necessary for some clients
    // tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
    // tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
},
  • Lucky-13 Atacks! (What is Luck-13 attack?)
    How to avoid Lucky-13 attacks?

2.golang.org/x/crypto/acme/autocert package’s GetCertificate function.

  • Important things while running on your local or any other service!

If you want to bind to a privileged port (ports less than 1024).
You either need to be root or have the CAP_NET_BIND_SERVICE capability.

setcap ‘cap_net_bind_service=+ep’ /path/to/program

setcap ‘cap_net_bind_service=+ep’ /usr/local/go/bin/go
SSL by default run on 443 Port.

authbind –deep ./autocert-server localhost

authbind –deep go run autocert-server.go localhost

sudo authbind –deep ./working-certs-server -domain dev.local.io

  1. HSTS
    This is the way to set headers!
    w.Header().Set(“Strict-Transport-Security”, “max-age=15768000 ; includeSubDomains”)
    You need to know much more about setting headers and how to od that one way or other!!
  2. Timeouts

Read Timeouts issues(sometimes)

Sadly, ReadTimeout breaks HTTP/2 connections in Go 1.7. Instead of being reset
for each request it’s set once at the beginning of the connection and never reset,
breaking all HTTP/2 connections after the ReadTimeout duration. It’s fixed in 1.8.

A zero/default http.Server, like the one used by the package-level helpers
http.ListenAndServe and http.ListenAndServeTLS,
comes with no timeouts. You don’t want that.

There are following three timeouts we need to mention/do….
4.1. ReadTimeout # start with making a connection
4.2. WriteTimeout # start with WriteTimeout normally covers the time from the end of the request header read to the end of the response write
However, when the connection is over HTTPS, SetWriteDeadline is called immediately after Accept
4.3. IdleTimeout

  1. HTTP/2

Command to generate certifictes for localhost:
mkdir -p certs
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout certs/localhost.key -out certs/localhost.crt \
-subj “/C=IND/ST=Punjab/L=Kutba/O=SDPS Chhapa/OU=Development/CN=localhost/[email protected]

Command to generate custom Domain certificate:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout certs/localhost.key -out certs/dev.local.io.crt \
-subj “/C=IND/ST=Punjab/L=Kutba/O=SDPS Chhapa/OU=Development/CN=localhost/[email protected]

  1. You can generate your own certificate: https://marcofranssen.nl/build-a-go-webserver-on-http-2-using-letsencrypt
  2. You could also use lego library for that!
    https://go-acme.github.io/lego/
    use following code to know more about Lego and stuff
    file:///home/quantum-machine/Desktop/blackberry-project/mydata/use-the-acme-dns-challenge-to-get-a-tls-certificate.html
    First learn about ListenAndServeTLS() in Goalng, Write your own server and make request
    form LocalHost!
  3. TCP Keep Alive tcpKeepAliveListener If you use ListenAndServe (as opposed to passing a net.Listener to Serve, which
    offers zero protection by default) a TCP Keep-Alive period of three minutes will
    be set automatically.
  4. Server-mux
    Package level functions like http.Handle[Func] (and maybe your web framework)
    register handlers on the global http.DefaultServeMux which is used
    if Server.Handler is nil. You should avoid that.
  5. Metrics
  6. Logging