0% found this document useful (0 votes)
7 views95 pages

Module 0 - Prerequisite - Theory and Practical Perspective of QC

The document outlines the prerequisites for learning quantum programming, emphasizing the importance of classical computing and programming fundamentals. It discusses various programming languages, particularly Python, and their relevance in scientific computing, along with principles of programming and memory management. Additionally, it covers data types, structures, and memory allocation in Python, providing insights into effective programming practices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views95 pages

Module 0 - Prerequisite - Theory and Practical Perspective of QC

The document outlines the prerequisites for learning quantum programming, emphasizing the importance of classical computing and programming fundamentals. It discusses various programming languages, particularly Python, and their relevance in scientific computing, along with principles of programming and memory management. Additionally, it covers data types, structures, and memory allocation in Python, providing insights into effective programming practices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 95

Part I

Pre-requisite

Fundamental required as per AICTE and DST guidelines

09/14/2025 1
Pre-requisite: Basics Quantum
Programming

Basics of programming and Data


Structures

Fundamental required as per AICTE and DST guidelines


Basic of Programming
”The only way to do great work is to love what you do.” - Steve
Jobs

”Programs must be written for people to read and only

incidentally for machines to execute.” – Harold Abelson,

Structure and Interpretation of Computer Programs

”First, solve the problem. Then, write the code.” – John Johnson

3
Basic of Programming
• As of today, Quantum systems do not operate in isolation; they rely on

classical computing systems for a variety of essential functions.

Classical + Quantum = Hybrid Computation

• These include receiving user inputs, processing and displaying results,

managing job payloads, and facilitating various other computational

tasks. The new Quantum Algorithms are based on leveraging the

power of both classical and Quantum Systems in the areas where they

lead over the other.


4
Basic of Programming
• Currently, the execution of Quantum Jobs is made possible
through

specialized libraries that serve as interfaces between users

and quantum hardware.

• Some of the most widely used libraries include IBM Qiskit,

Google Cirq, Microsoft Q#, PennyLane, and Amazon

Braket, among others. These libraries enable users to

construct, simulate, and execute quantum algorithms on


5
Basic of Programming
• As learners in the field of quantum computing, it is imperative to

develop proficiency in utilizing these libraries.

• Understanding how to formulate and execute quantum programs

tailored to specific computational problems will allow us to

harness the potential of this revolutionary technology.

6
Basic of Programming
• By mastering these tools, we take a crucial step toward leveraging the
power

of quantum computing for scientific discovery, optimization,

cryptography, and beyond.

• In the field of scientific computing, various programming

languages are available, each tailored to meet specific challenges

and computational requirements.

• Languages such as Python, C, C++, Julia, and Rust have become


essential tools

and
for researchers and scientists across disciplines like physics, 67
Basic of Programming
• C and C++ have long been favored for their ability to provide direct
control

over system resources, which allows for performance optimization in


large-

scale simulations & real-time systems.

• While these languages are powerful, they require a deeper

understanding of memory management & can be more complex to

work with.

78
• Julia is a relatively new programming language designed for high
Basic of Programming
• Julia combines the speed of C with a level of simplicity that makes it
ideal

for tasks such as solving complex differential equations and processing

large datasets. However, its ecosystem is still developing in

comparison to more established programming languages.

• Rust is becoming increasingly popular due to its ability to ensure


memory

safety and its support for concurrent programming.

• These features make it an excellent choice for performance-intensive

applications
promise, it isthat
still require
evolvinghigh reliability.
in the realm ofHowever,
scientificwhile Rust shows 89
great
Basic of Programming
• Despite the advantages of these languages, Python has emerged as the

language of choice for many in the scientific community.

• Its simplicity and readability make it incredibly accessible, even for


those

without extensive programming experience.

• With a rich ecosystem of libraries, such as NumPy for numerical

computations, SciPy for scientific algorithms, and Matplotlib for data

visualization, Python offers a comprehensive toolkit for tackling a wide

range of scientific problems. 1


0
Basic of Programming
• It balances ease of use with powerful capabilities, making it ideal
for

rapid prototyping, data analysis, and even complex simulations,

without the steep learning curve of other languages.

• For these reasons, Python is often selected as the go-to

language for scientific computing in many educational and

research settings.

• This is the reason all Quantum Computing Library today are 1


1
Fundamental Principles of
Programming
key principles of programming:

• clarity, simplicity, modularity, DRY (Don’t Repeat Yourself),

efficiency, maintainability, error handling, scalability, testability,

abstraction, encapsulation, re-usability, separation of

concerns, and consistency.

1
2
Fundamental Principles of
Programming
• These principles serve as essential guidelines for creating well-
structured,

efficient, and maintainable code.

• Mastering these principles is crucial for any programmer, as they

provide the foundation for building complex systems and

writing clean, understandable, and scalable code.

• By adhering to these principles, developers can write code that is


not only 1
3
Fundamental Principles of
Programming
• By mastering these fundamental principles of programming,
developers can

create high-quality code that is efficient, scalable, reliable, and

easy to maintain.

1
4
Programs are Algorithms for
Computers
• Computers only know how to do what we tell them to do.

• Programs communicate with a computer and tell it what to do.

• Algorithms can be expressed as programs in many different

programming languages. Different languages use different syntax

(wording) and commands, but they all share the same set of

algorithmic concepts.
1
5
• What is computer?
About Computer
• Machine for computation

• Essentially, no big difference from abacus

• In our history, we have several kinds of machines used for


computing

• Abacus(counting frame/hand operating calculating frame)

• Difference engine

• Tide-predicting machine

1
6
About Computer: the model
• What is computing

• Input data and needed operations

• Output the answer

• This is actual the model proposed by Alan


Turing

1
7
About Computer : the
framework
• Think aloud about the major components of a
computer

• CPU: central processing unit

• Memory

• Hard disc / SSD

• Keyboard

• graphics card + Monitor/screen

• Music card + microphone + speaker


1
8

About Quantum Computer : the
framework

1
9
About Quantum Computer
: the framework

2
0
Why programming?

2
1
Why programming?

• Instructions and data fetch from memory to CPU for


processing

• The results are returned back to memory 2


2
Why High Level
Programming
Language?
• Natural language is the media that we
communicate with each other

• Computer language is the media that we


communicate with computer

• We should use the language that computer could


understand

• At least, we need an interpreter/translator

2
3
Why programming Language?

• Instructions are binary codes

• Machine only accepts/understands binary


codes 2
4
Why programming Language?

2
5
Why programming Language?

• For the convenience of operation, binary instructions


are
denoted with readable symbols

2
6
Why programming Language?

2
7
Why programming Language?

• We write a text file in specified format (grammar)

• These are instructions that we basically understand

• The translator converts the text instructions into machine


codes

• Machine then runs these binary codes one by one

• Different translators lead to different programming


languages
2
8
The life-time of a computer
program

2
9
Python is Simple and Highly
Useful
• The Python programming language is designed to be easy to read
and simple to implement algorithms in.

• There are also a huge number of libraries that implement useful


things in Python.

• We'll use libraries that support graphics, data analysis, machine


learning, and more.

• Python's main weakness is efficiency − it can be slower than other


languages.

3
0
Data holds
Information

• Most programs we write will keep track of some kind of information

• and change it with actions. We call that information data

• Data have different types depending on their properties.

• We'll start by going over three core types: numbers, text, and

truth values

3
1
Types of Data Structure

3
2
Data Types in Statistics

temperature
income levels blood type, zip
(Farenheit), pulse, weight,
“50K-100K code, gender
temperature length
(Celcius)
3
3
Data Types

3
4
Data Types in
Python

3
5
Numbers and operations in
Python
integers (0, 14, 7) are whole numbers.

floating point (3.0, 5.735, 8e10) include a


decimal point

A term like 4 ** 2 or(5 -2) / 3 is called an


expression;
that's a piece of code that evaluates to a data 3
6
Numbers and operations in
Python

• Most programs we write will keep track of some kind of information

• and change it with actions. We call that information data

• Data have different types depending on their properties.

• We'll start by going over three core types: numbers, text, and

truth values

3
7
Advanced Math
Operations
• There are two additional math operations that might not be as
familiar to
you.

• Floor division , or div (//) divides numbers rounding down to


nearest whole number. This effectively cuts off any digits after
the decimal point.
For example, 7 // 4 is equal to 1, not 1.75.

• Modulo , or mod (%) finds the remainder when one number is


divided by another. For example, 7 % 4 is equal to 3.

• Div and Mod are primarily used as a floor operator and to repeat 3
8
Text in Python

• Text values in Python are called strings

• Text is recognized by Python when it is put inside of quotes, either

single quotes (' Hello') or double quotes (" Hello").

• Strings can be concatenated together using addition.

• E.g , "Hello" + " World” produces " HelloWorld".

3
9
Type Mismatches Cause
Errors
• Be careful when mixing types in Python, which can cause error
messages .

An error message is how the computer tells you it doesn’t


understand a

command you wrote.

• For example, "Hello" + 5 results in a TypeError

• Similarly, "Hello" -"World" results in a TypeError

4
0
Truth Values in
Python
• Finally, Python can evaluate whether certain expressions are true or
false.

These types of values are called Booleans , after mathematician


George

• Booleans can be either True or False (no quotes and capitals are
required).

These names are built into Python directly.

• To get a Boolean, we can use True and False directly or do a


comparison .
4
1
Names of Types in
Python
• In addition to the built in operations, there are also built in
commands in

Python called functions . These are algorithms that have already

been added into the language. When we run a function on an

input, it evaluates to an output.

• type(value) is a built in function that determines the type of the

given value. This can be int (integer), float (floating point

number), str (string), or bool (Boolean).


4
2
Type casting Changes
Types
• We can also use these type names as functions, to change a value
from one

type to another.

• For example, str(42) evaluates to “42” and int(3.14) evaluates to 3

• Type casting is mainly useful for converting values to and from


strings.

4
3
Interpreter for Short Tasks, Files for Long
• The interpreter evaluates a
single

line of code, then shows the

result. For longer programs,

we'll want to write code in a

file , where we can save it and

run all of the lines together as

often as we want.

4
• Python file names should end 4
The print Function Displays
Results
• Code run from a file doesn't show the evaluated result of every line.
If we

want to display a result; we need to use the print function .

Print just takes the input and displays the evaluated result in

the interpreter.

• For example:

• print(4 - 2) displays 2 in the interpreter.

• print("15 - 110") displays 15 110 ; the quotes aren’t


included.
4
5
Variables Let Us Store Data
• Core building block is the variable . Variables let us save data so
we can

reuse them in future computations.

• A variable itself is just a name that we define in the program

(without quotes), like x or result .


• We define a variable with an equals sign:
variable = value
For example:
x=5+2
dog = "Stella" 44
66
Dr. Mukta Nivelkar
Assistant Professor
FCRIT, Vashi

4
7
Part II
Pre-requisite

09/14/2025 48
Data
Storage
Data
Storage
Data
Storage
Data Storage
#include<stdio.h>
Data Storage
int main()
{
long double d;
long double
arr[1000];
printf("Size of Long Double is - %u \n", sizeof(d));
printf("Size of Long Double Array is - %u \n", sizeof(arr));
return 0;
}
#include<stdio.h>
Array
int main()
{
long double d;
long double
arr[1000];
printf("Size of Long Double is - %u \n", sizeof(d));
printf("Size of Long Double Array is - %u \n", sizeof(arr));
return 0;
}
Memory Management in Python
• Memory Management involves handling the temporary data
storage

needed during program execution, such as variables and literals.

• As programs expand, efficient memory management becomes

crucial to maintain speed and efficiency, especially in Python,

which powers

large-scale applications in Artificial Intelligence and Data Science.


Python Memory Allocation
• Python Memory Manager is responsible to manage memory
allocation and

deallocation to various processes that are under execution in


python.

• Every python process has two types of memory allocated to it

• Static Memory

• Dynamic Memory

• All the functions we declare in python code has each of these


memory
Memory Handling
• We know variable are reference to memory address, lets dive in
to see

how the memory is allocated for variable, how the cpu access

the memory locations & the how the memory the code uses is

cleared when program execution stops.


Type of Memories Used by a Program
• When a Code runs, it becomes a program ( running process) .
Each

program is allocated some memory in terms of Stack, Some

memory as Heap , Some memory for Code segment.


Static Memory Allocation
• Whenever a new function or class is declared it is very
common to

have some variable declaration inside them, these declarations

are associated with the function itself and do not change in the

runtime.

• They occupy a fixed memory size.

• Hence these are stored in the stack area.


Static Memory Allocation
Tall stack allocation:

• For every function call in python, there is a structure

maintained in the memory of the process. This structure is

called a function block.

• Python memory manager maintains a stack of such function


blocks.

When a function is called its function block is pushed onto this


Static Memory Allocation
The below example demonstrates variables that are stored in the
stack

memory.
Dynamic Memory Allocation
• The heap memory is separate from the static stack memory,
as this

memory can be dynamically requested (allocated) and

released (deallocated) in runtime.

• The memory size required for such variables cannot be

determined beforehand, and hence it is called Dynamic

memory.
Dynamic Memory Allocation
• The below code demonstrates the use of dynamic heap
memory.
Memory Deallocation in Python
• Python manages memory deallocation through reference
counting and

garbage collection.

• An object is removed from memory when its reference count


drops to

zero, releasing its memory back to the heap for future use.

• Python's garbage collector, which runs periodically, employs a

mark- and-sweep algorithm to detect and eliminate objects no


Memory Deallocation in Python
• The process starts with marking all accessible objects that are
still

needed by the program.

• Following this, the garbage collector sweeps through the

memory, deallocating all unmarked objects, thereby ensuring

efficient memory use and preventing leaks.

• This system plays a crucial role in maintaining Python's

memory efficiency and application performance.


Memory Optimization in Python
• Python offers a suite of tools and techniques for optimizing
memory

usage, which is particularly beneficial for applications

dealing with large data sets or requiring high efficiency.

• Generators and Iterators:

• Optimized Data Structures:

• The sys Module:


Generators and Iterators
• These are powerful tools in Python that generate items on the
fly

without needing to store the entire sequence in memory.

• This approach is memory-efficient, especially when processing


large

data streams or files.


Optimized Data Structures
• Python's standard library includes modules like array and collections,

• which offer memory-efficient alternatives to standard data structures.

• For instance, array module allows for the creation of compact arrays, while

collections includes specialized structures like deque and defaultdict that are

designed for lower memory consumption.


The sys Module
• This module provides access to some under-the-hood information

about the Python interpreter, including functions to query the

size of objects and the overall memory usage.

• This can be useful for identifying memory-intensive parts of the

code and optimizing them.


Memory Optimization in Python
• While Python's memory management is largely automatic,
leveraging

these optimization techniques can lead to more efficient

memory usage, especially in complex applications or those

handling large amounts of data.

• In such scenarios, developers might also consider advanced

strategies like memory pooling or object caching to further

enhance performance.
The Default Python Implementation
• Remember that Python itself is written in another language,
the

primary language used to implement python is C.

• CPython is the primary python implementation, as we say it


is the

default python implementation.


The Default Python Implementation
• To understand memory management in python fully, we should take a

• deeper look at how Python is implemented in the C programming language.

• It is quite amusing how a purely object-based language python is implemented

using C language, which does not have native support for object orientation.
C Memory Address
• When a variable is created in C, a memory address is assigned to the variable.

• The memory address is the location of where the variable is stored on the computer.

• When we assign a value to the variable, it is stored in this memory address.

• To access it, use the reference operator (&), and the result represents where the variable is stored:
C Memory Address

• int myAge = 43;

• printf("%p", &myAge); // Outputs


0x7ffe5367e044
Creating Pointers
• we can get the memory address of a variable with the reference

operator &:

• int myAge = 43; // an int variable

• printf("%d", myAge); // Outputs the value of myAge (43)

• printf("%p", &myAge); // Outputs the memory address of myAge


(0x7ffe5367e044)
Creating Pointers
• A pointer is a variable that stores the memory address of another

variable as its value.

• A pointer variable points to a data type (like int) of the same


type, and

is created with the * operator.


Creating Pointers
• int myAge = // An int
43; variable
• int* ptr = &myAge; // A pointer variable, with the name ptr, that stores the
address of

myAge

// Output the value of myAge (43)

• printf("%d\n", myAge);

// Output the memory address of myAge (0x7ffe5367e044)

• printf("%p\n", &myAge);

// Output the memory address of myAge with the pointer (0x7ffe5367e044)

• printf("%p\n", ptr);
Part III
Pre-requisite

09/14/2025 78
Classical
Algorithms
Algorithm :

A process or set of rules to be followed in calculations or


other problem-solving operations, especially by a computer.

The word algorithm comes from the 9th-century


mathematician
Muḥammad ibn Mūsā al-Khwārizmī, latinized as Algoritmi.

Program:

A series of coded software instructions to control the


operation
of a computer or other machine. 79
Classical
Algorithms
“A problem well-stated is half-solved.”

— Charles Kettering

“If I had an hour to solve a problem, I’d spend 55 minutes thinking

about the problem and five minutes thinking about solutions.”

—Albert Einstein

80
Classical
Algorithms

81
Classical
Algorithms
• Problem: A problem can be defined as a real-world problem or real-
world instance problem for which you need to develop a program
or set of instructions. An algorithm is a set of instructions.

• Algorithm: An algorithm is a step-by-step process designed for a


problem.

• Input: After designing an algorithm, the algorithm is given the


necessary and desired inputs.

• Processing unit: The input will be passed to the


processing unit, producing
the desired output.

• Output: The outcome or result of the program is referred to as the 82


Classical
Algorithms
Program development
steps

1. Problem Definition

2. Algorithm Design

3. Pseudo-Code

4. Actual Code

83
Classical
Algorithms
Program development steps

1.Problem Definition: Clearly articulate the


problem and its requirements.

2. Algorithm Design

3. Pseudo-Code

4. Actual Code

84
Classical
Algorithms
Program development steps

1.Problem Definition

2.Algorithm Design: Devise a step-by-step solution


to solve the problem.

3. Pseudo-Code

4. Actual Code

85
Classical
Algorithms
Program development steps

1.Problem Definition

2. Algorithm Design

3.Pseudo-Code: Represent the algorithm in a


high-level, language-agnostic format.

4. Actual Code

86
Classical
Algorithms
Program development steps

1.Problem Definition

2. Algorithm Design

3. Pseudo-Code

4.Actual Code: Translate the pseudo-code into


executable code.

87
Classical
Algorithms
• The choice of algorithm depends on the specific problem
and its constraints.

• Evaluating different approaches and benchmarking them


allows us to select the most suitable solution.

• When designing algorithms, break the problem into smaller,


manageable tasks. Simplifying the structure can make the
programming process more intuitive and scalable.

• Programming is not just about solving problems—it is about


finding the most elegant and efficient path to a solution.
88
•Input How do Algorithms Work?
•Processing
•Output
•Efficiency
•Optimization
•Implementati
on 89
How do
• Input : Algorithms takeAlgorithms
input data, whichWork?
can be in
various formats, such as numbers, text, or images.

• Processing

• Output

• Efficiency

• Optimization

• Implementation

90
• Input How do Algorithms Work?
• Processing :The algorithm processes the input data
through logical and mathematical operations,
manipulating and transforming it as needed.
• Output

• Efficiency

• Optimization

• Implementation
91
• Input How do Algorithms Work?
• Processing

• Output : After the processing, the algorithm produces an


output, which could be a result, a decision, or some
other meaningful information.

• Efficiency

• Optimization

• Implementation

92
• Input
How do Algorithms Work?
• Processing

• Output

• Efficiency: A key aspect of algorithms is their efficiency,


aiming to accomplish tasks quickly and with minimal
resources.

• Optimization

• Implementation

93
• Input How do Algorithms Work?
• Processing

• Output

• Efficiency

• Optimization: Algorithm designers constantly seek


ways to optimize their algorithms, making them
faster and more reliable.

• Implementation
94
• Input How do Algorithms Work?
• Processing

• Output

• Efficiency

• Optimization

• Implementation: Algorithms are implemented in various


programming languages, enabling computers to execute
them and produce desired outcomes.

95

You might also like