Skip to content

Commit

Permalink
Add QC Primer
Browse files Browse the repository at this point in the history
  • Loading branch information
rawkintrevo committed Jan 21, 2025
1 parent a10bab4 commit 1dcc8e4
Show file tree
Hide file tree
Showing 15 changed files with 1,417 additions and 3 deletions.
1 change: 1 addition & 0 deletions website/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source "https://rubygems.org"
# Happy Jekylling!

gem "jekyll", "4.3.2"
gem 'jekyll-latex'

# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
Expand Down
1 change: 1 addition & 0 deletions website/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ baseurl: ""
markdown: kramdown
plugins:
- jekyll-feed
- jekyll-latex

# Exclude from processing.
# The following items will not be processed, by default. Create a custom list
Expand Down
21 changes: 20 additions & 1 deletion website/_includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,24 @@
<link rel="canonical" href="{{ page.url | replace:'index.html','' | absolute_url }}">
<link rel="alternate" type="application/rss+xml" title="{{ site.title | escape }}" href="{{'/feed.xml' | relative_url }}">


<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML">
MathJax.Hub.Config({
"HTML-CSS": {
availableFonts: ["TeX"],
},
tex2jax: {
inlineMath: [['$','$'],["\\(","\\)"]]},
displayMath: [ ['$$','$$'], ['\[','\]'] ],
TeX: {
extensions: ["AMSmath.js", "AMSsymbols.js", "color.js"],
equationNumbers: {
autoNumber: "AMS"
}
},
showProcessingMessages: false,
messageStyle: "none",
imageFont: null,
"AssistiveMML": { disabled: true }
});
</script>
</head>
12 changes: 12 additions & 0 deletions website/_includes/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
</div>
</li>

<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle"
href="" id="navbarDropdownMenuLink-qumat"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">Qumat</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item"
href="/quantum-computing-primer">Quantum Computing Primer</a>
<!-- TODO: Add More QuMat stuff here or refactor the whole thing-->
</div>
</li>
<!-- Documentation -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle"
Expand Down
2 changes: 0 additions & 2 deletions website/general/books-tutorials-and-talks.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
layout: default
title: Books Tutorials and Talks


---
# Intro

Expand Down
93 changes: 93 additions & 0 deletions website/quantum-computing-primer/01_introduction/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
layout: page
title: Introduction to Quantum Computing
---

# 1. Introduction to Quantum Computing

## 1.1 What is Quantum Computing?

Quantum computing is a revolutionary approach to computation that leverages the principles of quantum mechanics to process information in ways that classical computers cannot. Unlike classical computers, which use bits as the smallest unit of information (representing either a 0 or a 1), quantum computers use **qubits** (quantum bits). Qubits can exist in a **superposition** of states, meaning they can be both 0 and 1 simultaneously. This property allows quantum computers to perform many calculations at once, potentially solving certain problems much faster than classical computers.

### Key Concepts:
- **Qubits**: The fundamental unit of quantum information, which can be in a superposition of states.
- **Superposition**: A quantum phenomenon where a qubit can be in multiple states at once.
- **Entanglement**: A unique quantum property where qubits become interconnected, such that the state of one qubit is directly related to the state of another, even if they are separated by large distances.
- **Quantum Gates**: Operations that manipulate qubits, analogous to classical logic gates but with the ability to exploit quantum phenomena.

### Why Quantum Computing Matters:
Quantum computing has the potential to revolutionize fields such as cryptography, optimization, and material science. For example, quantum algorithms like **Shor's algorithm** can factorize large numbers exponentially faster than classical algorithms, posing a threat to current cryptographic systems. Similarly, **Grover's algorithm** can search unsorted databases quadratically faster than classical methods.

---

## 1.2 Why Quantum Computing?

Quantum computing is not just a theoretical concept; it has practical implications that could transform industries. Here are some reasons why quantum computing is gaining attention:

### 1. **Exponential Speedup for Certain Problems**:
- Quantum computers can solve certain problems exponentially faster than classical computers. For example, simulating quantum systems (e.g., molecules for drug discovery) is infeasible for classical computers but manageable for quantum computers.

### 2. **Breaking Classical Cryptography**:
- Quantum algorithms like Shor's algorithm can break widely used cryptographic schemes, such as RSA, by efficiently factorizing large numbers. This has spurred interest in **quantum-resistant cryptography**.

### 3. **Optimization**:
- Quantum computers can explore multiple solutions simultaneously, making them ideal for optimization problems in logistics, finance, and machine learning.

### 4. **Quantum Simulation**:
- Quantum computers can simulate quantum systems, enabling breakthroughs in chemistry, material science, and physics.

### 5. **Machine Learning**:
- Quantum machine learning algorithms promise to accelerate training and improve model performance for specific tasks.

---

## 1.3 Quantum Computing vs. Classical Computing

| Feature | Classical Computing | Quantum Computing |
|------------------------|-----------------------------------|----------------------------------|
| **Basic Unit** | Bit (0 or 1) | Qubit (superposition of 0 and 1)|
| **State Representation**| Deterministic | Probabilistic |
| **Operations** | Logic gates (AND, OR, NOT, etc.) | Quantum gates (X, Y, Z, H, etc.)|
| **Parallelism** | Limited by CPU cores | Exponential parallelism via superposition |
| **Error Correction** | Well-established | Still an active area of research|

---

## 1.4 Getting Started with Quantum Computing Using `qumat`

To begin your journey into quantum computing, you'll use the `qumat` library, which provides a simple and unified interface for working with quantum circuits across different backends (e.g., Amazon Braket, Cirq, Qiskit). Here's a quick example to get you started:

```python
from qumat import QuMat

# Initialize a quantum circuit with 1 qubit
backend_config = {'backend_name': 'qiskit', 'backend_options': {'simulator_type': 'qasm_simulator', 'shots': 1000}}
qc = QuMat(backend_config)
qc.create_empty_circuit(1)

# Apply a Hadamard gate to create a superposition
qc.apply_hadamard_gate(0)

# Execute the circuit and measure the result
result = qc.execute_circuit()
print(result)
```

In this example, we:

* Created a quantum circuit with 1 qubit.
* Applied a Hadamard gate to put the qubit into a superposition state.
* Measured the qubit to observe the probabilistic outcome.

This is just the beginning! In the next sections, you'll dive deeper into quantum gates, circuits, and algorithms using qumat.

---

## 1.5 Summary

* Quantum computing leverages quantum mechanics to process information in fundamentally new ways.
* Qubits, superposition, and entanglement are the building blocks of quantum computing.
* Quantum computing has the potential to solve problems that are intractable for classical computers.
* The `qumat` library provides a simple way to explore quantum computing concepts and algorithms.

In the next section, we'll set up your environment and explore the basics of quantum circuits using `qumat`.
84 changes: 84 additions & 0 deletions website/quantum-computing-primer/03_qubits/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
layout: page
title: Quantum Bits (Qubits)
---

# 3. Quantum Bits (Qubits)

## 3.1 Classical Bits vs. Qubits

In classical computing, the fundamental unit of information is the **bit**, which can exist in one of two states: `0` or `1`. Quantum computing, however, introduces the concept of a **qubit**, which can exist in a **superposition** of both states simultaneously. This means a qubit can be in a state that is a combination of `0` and `1`, represented as:

$$|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$$

where \(\alpha\) and \(\beta\) are complex numbers representing the probability amplitudes of the qubit being in the \(|0\rangle\) and \(|1\rangle\) states, respectively. The probabilities of measuring the qubit in either state are given by \(|\alpha|^2\) and \(|\beta|^2\), and they must satisfy the normalization condition:

$$|\alpha|^2 + |\beta|^2 = 1$$

## 3.2 Representing Qubits

Qubits can be visualized using the **Bloch sphere**, a geometric representation of the quantum state of a single qubit. The Bloch sphere is a unit sphere where the north and south poles represent the \(|0\rangle\) and \(|1\rangle\) states, respectively. Any point on the surface of the sphere represents a valid quantum state of the qubit.

The state of a qubit can also be described using a **state vector** in a two-dimensional complex vector space. For example, the state \(|0\rangle\) is represented as:

$$|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}$$

and the state \(|1\rangle\) is represented as:

$$|1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}$$

## 3.3 Creating Qubits with `qumat`

In `qumat`, qubits are created by initializing a quantum circuit with a specified number of qubits. The `create_empty_circuit` function is used to create a circuit with a given number of qubits. Here's an example of creating a quantum circuit with a single qubit:

```python
from qumat import QuMat

# Initialize the quantum circuit with a single qubit
backend_config = {
'backend_name': 'qiskit', # Choose the backend (e.g., 'qiskit', 'cirq', 'amazon_braket')
'backend_options': {
'simulator_type': 'qasm_simulator', # Type of simulator
'shots': 1000 # Number of shots (measurements)
}
}

qc = QuMat(backend_config)
qc.create_empty_circuit(1) # Create a circuit with 1 qubit
```

In this example, we initialize a quantum circuit with one qubit using the qiskit backend. The create_empty_circuit function sets up the circuit, and we can now apply quantum gates to manipulate the qubit.

### Example: Applying a Hadamard Gate

The Hadamard gate ((H)) is a fundamental quantum gate that puts a qubit into a superposition state. Applying the Hadamard gate to a qubit initially in the (|0\rangle) state results in the state:

$$H|0\rangle = \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)$$

Here's how you can apply a Hadamard gate to a qubit using qumat:

```python
# Apply the Hadamard gate to the first qubit (index 0)
qc.apply_hadamard_gate(0)

# Execute the circuit and get the measurement results
result = qc.execute_circuit()
print(result)
```

In this example, the Hadamard gate is applied to the qubit at index 0, and the circuit is executed to obtain the measurement results. The output will show the probabilities of measuring the qubit in the (|0\rangle) and (|1\rangle) states.

### Visualizing the Circuit

You can also visualize the quantum circuit using the draw method:

```python
# Draw the circuit
qc.draw()
```

This will print a textual representation of the circuit, showing the sequence of gates applied to the qubits.

---

This section introduced the concept of qubits, their representation, and how to create and manipulate them using the qumat library. In the next section, we will explore quantum gates in more detail and learn how to apply them to perform quantum operations.
136 changes: 136 additions & 0 deletions website/quantum-computing-primer/04_quantum_gates/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
layout: page
title: Quantum Gates
---

# 4. Quantum Gates

Quantum gates are the building blocks of quantum circuits, analogous to classical logic gates in classical computing. They manipulate qubits, enabling the creation of complex quantum algorithms. In this section, we will explore the different types of quantum gates and how to apply them using the `qumat` library.

## 4.1 Single-Qubit Gates

Single-qubit gates operate on a single qubit, changing its state. Some of the most common single-qubit gates include:

- **Pauli-X Gate**: Similar to the classical NOT gate, it flips the state of a qubit.
- **Pauli-Y Gate**: Introduces a phase flip and a bit flip.
- **Pauli-Z Gate**: Introduces a phase flip without changing the bit value.
- **Hadamard Gate**: Creates superposition by transforming the basis states.
- **Rotation Gates (Rx, Ry, Rz)**: Rotate the qubit state around the X, Y, or Z axis of the Bloch sphere.

### Example: Applying a Hadamard Gate
```python
from qumat import QuMat

# Initialize the quantum circuit with 1 qubit
backend_config = {'backend_name': 'qiskit', 'backend_options': {'simulator_type': 'qasm_simulator', 'shots': 1000}}
qc = QuMat(backend_config)
qc.create_empty_circuit(1)

# Apply the Hadamard gate to the first qubit
qc.apply_hadamard_gate(0)

# Execute the circuit and print the results
result = qc.execute_circuit()
print(result)
```

## 4.2 Multi-Qubit Gates

Multi-qubit gates operate on two or more qubits, enabling entanglement and more complex quantum operations. Some of the most common multi-qubit gates include:

- **CNOT Gate (Controlled-NOT)**: Flips the target qubit if the control qubit is in the state |1⟩.
- **Toffoli Gate (CCNOT)**: A controlled-controlled-NOT gate that flips the target qubit if both control qubits are in the state |1⟩.
- **SWAP Gate**: Exchanges the states of two qubits.

### Example: Applying a CNOT Gate
```python
# Initialize the quantum circuit with 2 qubits
qc.create_empty_circuit(2)

# Apply the Hadamard gate to the first qubit
qc.apply_hadamard_gate(0)

# Apply the CNOT gate with qubit 0 as control and qubit 1 as target
qc.apply_cnot_gate(0, 1)

# Execute the circuit and print the results
result = qc.execute_circuit()
print(result)
```

## 4.3 Applying Gates with `qumat`

The `qumat` library provides a simple and consistent interface for applying quantum gates. Below are some examples of how to apply different gates using `qumat`.

### Example: Applying Rotation Gates
```python
# Initialize the quantum circuit with 1 qubit
qc.create_empty_circuit(1)

# Apply an Rx gate with a rotation angle of π/2
qc.apply_rx_gate(0, 3.14159 / 2)

# Apply an Ry gate with a rotation angle of π/4
qc.apply_ry_gate(0, 3.14159 / 4)

# Apply an Rz gate with a rotation angle of π
qc.apply_rz_gate(0, 3.14159)

# Execute the circuit and print the results
result = qc.execute_circuit()
print(result)
```

### Example: Applying a Toffoli Gate
```python
# Initialize the quantum circuit with 3 qubits
qc.create_empty_circuit(3)

# Apply the Hadamard gate to the first two qubits
qc.apply_hadamard_gate(0)
qc.apply_hadamard_gate(1)

# Apply the Toffoli gate with qubits 0 and 1 as controls and qubit 2 as target
qc.apply_toffoli_gate(0, 1, 2)

# Execute the circuit and print the results
result = qc.execute_circuit()
print(result)
```

### Example: Applying a SWAP Gate
```python
# Initialize the quantum circuit with 2 qubits
qc.create_empty_circuit(2)

# Apply the Hadamard gate to the first qubit
qc.apply_hadamard_gate(0)

# Apply the SWAP gate to exchange the states of qubits 0 and 1
qc.apply_swap_gate(0, 1)

# Execute the circuit and print the results
result = qc.execute_circuit()
print(result)
```

## 4.4 Visualizing Quantum Circuits

Visualizing quantum circuits can help in understanding the flow of quantum operations. The `qumat` library provides a simple way to draw circuits.

### Example: Drawing a Quantum Circuit
```python
# Initialize the quantum circuit with 2 qubits
qc.create_empty_circuit(2)

# Apply a Hadamard gate to the first qubit
qc.apply_hadamard_gate(0)

# Apply a CNOT gate with qubit 0 as control and qubit 1 as target
qc.apply_cnot_gate(0, 1)

# Draw the circuit
qc.draw()
```

This section introduced the fundamental quantum gates and demonstrated how to apply them using the `qumat` library. In the next section, we will explore how to build more complex quantum circuits by combining these gates.
Loading

0 comments on commit 1dcc8e4

Please sign in to comment.