# How a quantum computer solves a problem

> A process map exported from forks.world (https://forks.world). Author: Brian. Source: https://forks.world/p/cmv0kpy0s000tjv06htzxmg9y
> It describes who does what, in what order, and with which technology. Read the plain-language sections first; the JSON at the end is the exact, complete data.

## Summary

- 13 steps across 2 layers
- Persona: You
- Technology / systems: Qubits, Quantum gates, Measurement, A classical computer

## Pain points

Where this process hurts, worst first:

- **Adjust the circuit or use error correction** (How a quantum computer solves a problem; painful): Qubits are fragile: noise and errors are the main obstacle

## How to read this file

- A process is made of **layers**. The main layer is the top level; any step of kind `subprocess` opens a detail layer with its own lanes and steps.
- **Lanes** are either persona (people/roles) or technology (systems). Each step belongs to one lane; `using` lists tools a person uses for that step.
- Step kinds: `start`, `task`, `decision` (its arrows carry the answer as a label), `subprocess`, `end`.

## How a quantum computer solves a problem

Lanes:
- You: person / role (id `you`)
- Qubits: technology / system (id `qubit`)
- Quantum gates: technology / system (id `gates`)
- Measurement: technology / system (id `measure`)
- A classical computer: technology / system (id `classical`)

Steps, in the order they run:

1. **Frame a problem for a quantum computer** [start; You; id `q1`]
   - then Prepare qubits in superposition: both 0 and 1
2. **Prepare qubits in superposition: both 0 and 1** [task; Qubits; id `q2`]
   - then Entangle them so they share a fate
3. **Entangle them so they share a fate** [task; Quantum gates; id `q3`]
   - then Apply gates so wrong answers cancel and right ones reinforce
4. **Apply gates so wrong answers cancel and right ones reinforce** [subprocess; Quantum gates; id `q4`], opens the detail layer "Interference"
   - then Measure: the qubits collapse to 0s and 1s
5. **Measure: the qubits collapse to 0s and 1s** [task; Measurement; id `q5`]
   - then Repeat many times and collect the results
6. **Repeat many times and collect the results** [task; A classical computer; id `q6`]
   - then Is one answer clearly the most common?
7. **Is one answer clearly the most common?** [decision; A classical computer; id `q7`]
   - if "Yes" go to That is the answer; if "No" go to Adjust the circuit or use error correction
8. **That is the answer** [end; You; id `q8`]
9. **Adjust the circuit or use error correction** [task; Quantum gates; id `q7a`] ⚠ PAIN POINT (painful): Qubits are fragile: noise and errors are the main obstacle
   - then Apply gates so wrong answers cancel and right ones reinforce

```mermaid
flowchart LR
  subgraph l_you["You"]
    n_q1(["Frame a problem for a quantum computer"])
    n_q8(["That is the answer"])
  end
  subgraph l_qubit["Qubits"]
    n_q2["Prepare qubits in superposition: both 0 and 1"]
  end
  subgraph l_gates["Quantum gates"]
    n_q3["Entangle them so they share a fate"]
    n_q4[["Apply gates so wrong answers cancel and right ones reinforce"]]
    n_q7a["Adjust the circuit or use error correction"]
  end
  subgraph l_measure["Measurement"]
    n_q5["Measure: the qubits collapse to 0s and 1s"]
  end
  subgraph l_classical["A classical computer"]
    n_q6["Repeat many times and collect the results"]
    n_q7{"Is one answer clearly the most common?"}
  end
  n_q1 --> n_q2
  n_q2 --> n_q3
  n_q3 --> n_q4
  n_q4 --> n_q5
  n_q5 --> n_q6
  n_q6 --> n_q7
  n_q7 -->|"Yes"| n_q8
  n_q7 -->|"No"| n_q7a
  n_q7a --> n_q4
```

### Interference (detail of step "Apply gates so wrong answers cancel and right ones reinforce")

Lanes:
- Quantum gates: technology / system (id `gates`)

Steps, in the order they run:

1. **Every possible answer has an amplitude** [start; Quantum gates; id `i1`]
   - then Amplitudes can be positive or negative
2. **Amplitudes can be positive or negative** [task; Quantum gates; id `i2`]
   - then Wrong answers get opposite signs and cancel
3. **Wrong answers get opposite signs and cancel** [task; Quantum gates; id `i3`]
   - then Right answers add up
4. **Right answers add up** [end; Quantum gates; id `i4`]

```mermaid
flowchart LR
  subgraph l_gates["Quantum gates"]
    n_i1(["Every possible answer has an amplitude"])
    n_i2["Amplitudes can be positive or negative"]
    n_i3["Wrong answers get opposite signs and cancel"]
    n_i4(["Right answers add up"])
  end
  n_i1 --> n_i2
  n_i2 --> n_i3
  n_i3 --> n_i4
```

## Full data (JSON)

```json
{
  "title": "How a quantum computer solves a problem",
  "maps": {
    "m_root": {
      "id": "m_root",
      "lanes": [
        {
          "id": "you",
          "name": "You",
          "type": "person"
        },
        {
          "id": "qubit",
          "name": "Qubits",
          "type": "system"
        },
        {
          "id": "gates",
          "name": "Quantum gates",
          "type": "system"
        },
        {
          "id": "measure",
          "name": "Measurement",
          "type": "system"
        },
        {
          "id": "classical",
          "name": "A classical computer",
          "type": "system"
        }
      ],
      "steps": [
        {
          "id": "q1",
          "kind": "start",
          "lane": "you",
          "next": [
            {
              "to": "q2"
            }
          ],
          "uses": [],
          "label": "Frame a problem for a quantum computer"
        },
        {
          "id": "q2",
          "kind": "task",
          "lane": "qubit",
          "next": [
            {
              "to": "q3"
            }
          ],
          "uses": [],
          "label": "Prepare qubits in superposition: both 0 and 1"
        },
        {
          "id": "q3",
          "kind": "task",
          "lane": "gates",
          "next": [
            {
              "to": "q4"
            }
          ],
          "uses": [],
          "label": "Entangle them so they share a fate"
        },
        {
          "id": "q4",
          "kind": "subprocess",
          "lane": "gates",
          "next": [
            {
              "to": "q5"
            }
          ],
          "uses": [],
          "child": "m_interf",
          "label": "Apply gates so wrong answers cancel and right ones reinforce"
        },
        {
          "id": "q5",
          "kind": "task",
          "lane": "measure",
          "next": [
            {
              "to": "q6"
            }
          ],
          "uses": [],
          "label": "Measure: the qubits collapse to 0s and 1s"
        },
        {
          "id": "q6",
          "kind": "task",
          "lane": "classical",
          "next": [
            {
              "to": "q7"
            }
          ],
          "uses": [],
          "label": "Repeat many times and collect the results"
        },
        {
          "id": "q7",
          "kind": "decision",
          "lane": "classical",
          "next": [
            {
              "to": "q8",
              "label": "Yes"
            },
            {
              "to": "q7a",
              "label": "No"
            }
          ],
          "uses": [],
          "label": "Is one answer clearly the most common?"
        },
        {
          "id": "q7a",
          "kind": "task",
          "lane": "gates",
          "next": [
            {
              "to": "q4"
            }
          ],
          "pain": {
            "note": "Qubits are fragile: noise and errors are the main obstacle",
            "level": 2
          },
          "uses": [],
          "label": "Adjust the circuit or use error correction"
        },
        {
          "id": "q8",
          "kind": "end",
          "lane": "you",
          "next": [],
          "uses": [],
          "label": "That is the answer"
        }
      ],
      "title": "How a quantum computer solves a problem",
      "parent": null
    },
    "m_interf": {
      "id": "m_interf",
      "lanes": [
        {
          "id": "gates",
          "name": "Quantum gates",
          "type": "system"
        }
      ],
      "steps": [
        {
          "id": "i1",
          "kind": "start",
          "lane": "gates",
          "next": [
            {
              "to": "i2"
            }
          ],
          "uses": [],
          "label": "Every possible answer has an amplitude"
        },
        {
          "id": "i2",
          "kind": "task",
          "lane": "gates",
          "next": [
            {
              "to": "i3"
            }
          ],
          "uses": [],
          "label": "Amplitudes can be positive or negative"
        },
        {
          "id": "i3",
          "kind": "task",
          "lane": "gates",
          "next": [
            {
              "to": "i4"
            }
          ],
          "uses": [],
          "label": "Wrong answers get opposite signs and cancel"
        },
        {
          "id": "i4",
          "kind": "end",
          "lane": "gates",
          "next": [],
          "uses": [],
          "label": "Right answers add up"
        }
      ],
      "title": "Interference",
      "parent": {
        "map": "m_root",
        "step": "q4"
      }
    }
  }
}
```
