Skip to content

Commit

Permalink
Merge pull request #72 from cirKITers/noise
Browse files Browse the repository at this point in the history
Noise
  • Loading branch information
stroblme authored Jan 14, 2025
2 parents 7031096 + b38f4f2 commit 5a58be0
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 90 deletions.
47 changes: 45 additions & 2 deletions docs/ansaetze.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MyHardwareEfficient(Circuit):
return None

@staticmethod
def build(w: np.ndarray, n_qubits: int):
def build(w: np.ndarray, n_qubits: int, noise_params=None):
w_idx = 0
for q in range(n_qubits):
qml.RY(w[w_idx], wires=q)
Expand All @@ -50,4 +50,47 @@ model = Model(
)
```

Checkout page ["Usage"](usage.md) on how to proceed from here.
Checkout page ["Usage"](usage.md) on how to proceed from here.

You might have noticed, that the `build` method takes an additional input `noise_params`, which we did not used so far.
In general, all of the Ansatzes, that are implemented in this package allow this additional input which is a dictionary containing all the noise parameters of the circuit (here all with probability $0.0$):
```python
noise_params = {
"BitFlip": 0.0,
"PhaseFlip": 0.0,
"AmplitudeDamping": 0.0,
"PhaseDamping": 0.0,
"DepolarizingChannel": 0.0,
}
```

Providing this optional input will apply the corresponding noise to the model where the Bit Flip, Phase Flip and Depolarizing Channel are applied after each gate and the Amplitude and Phase Damping are applied at the end of the circuit.
To achieve this, we implement our own set of noisy gates, that build upon the Pennylane gates. To demonstrate this, let's extend our example above:
```python
from qml_essentials.ansaetze import Gates, Circuit

class MyNoisyHardwareEfficient(Circuit):
@staticmethod
def n_params_per_layer(n_qubits: int) -> int:
return n_qubits * 3

@staticmethod
def get_control_indices(n_qubits: int) -> Optional[np.ndarray]:
return None

@staticmethod
def build(w: np.ndarray, n_qubits: int, noise_params=None):
w_idx = 0
for q in range(n_qubits):
Gates.RY(w[w_idx], wires=q, noise_params=noise_params)
w_idx += 1
Gates.RZ(w[w_idx], wires=q, noise_params=noise_params)
w_idx += 1

if n_qubits > 1:
for q in range(n_qubits - 1):
Gates.CZ(wires=[q, q + 1], noise_params=noise_params)
```

As you can see, we slightly modified the example, by importing the `Gates` class from `ansaetze` and by adding the `noise_params` input to each of the gates.
When using a noisy circuit, make sure to run the model with the `density` execution type.
28 changes: 19 additions & 9 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ nav:
- setup.md
- usage.md
- Advanced:
- ansaetze.md
- coefficients.md
- entanglement.md
- expressibility.md
- ansaetze.md
- coefficients.md
- entanglement.md
- expressibility.md
- references.md
theme:
name: material
highlightjs: true
features:
- content.code.select
- content.code.copy
palette:
# Palette toggle for light mode
- media: "(prefers-color-scheme: light)"
Expand All @@ -36,14 +39,21 @@ markdown_extensions:
- markdown_include.include:
base_path: .
- toc:
permalink: "#"
baselevel: 1
separator: "_"
permalink: "#"
baselevel: 1
separator: "_"
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
extra:
social:
- icon: fontawesome/brands/github
link: https://github.com/cirKITers/qml-essentials
name: Github
name: Github
Loading

0 comments on commit 5a58be0

Please sign in to comment.