Skip to content

Commit

Permalink
2189 remove unused folding functions (#2289)
Browse files Browse the repository at this point in the history
* Removed all instances of fold_from_left and fold_from_right in the zne.scaling subpackage and in tests

* Updating typo in .gitignore

* Formatting

* removed remaining instances of fold_gates_from_left and fold_gates_from_right in testing

* reverted accidentally modified .md notebook

* formatting

* Formatting for notebook md to myst

* Remove fold_method as parameter for test

* Update docstring to acurately reflect how folding indices are chosen (i.e. randomly)

* Uncomment fold_gates_from_left call, as using directives now

Co-authored-by: nate stemen <[email protected]>

* Replace note with note directive

Co-authored-by: nate stemen <[email protected]>

* Removing the id outputs

* Switching wording 'deprecated' to 'removed'

* Remove parameterization for tests with only one test case, remove unused arguments for fold_method

* Formatting

* Remove fold_gates_from_left from pennylane demo

* Previous commit msg was in error. This commit updates the pennylane example not to use fold_gates_from_left

* Change notes to warnings, uncomment fold_gates_from_left and right code

* Remove fold_gates_from_right from vqe-pennylane example, formatting

* remove folding_method as optional argument to _create_fold_mask

---------

Co-authored-by: nate stemen <[email protected]>
  • Loading branch information
jordandsullivan and natestemen authored Apr 25, 2024
1 parent 9e1cbb5 commit 42779ed
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 848 deletions.
133 changes: 34 additions & 99 deletions docs/source/examples/mitiq-paper/mitiq-paper-codeblocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ kernelspec:
name: python3
---

+++ {"id": "wjnIQWX8d5UY"}

# Mitiq paper codeblocks

Codeblocks from the main text of the [Mitiq whitepaper](https://quantum-journal.org/papers/q-2022-08-11-774/) {cite}`LaRose_2022_Quantum` published in [Quantum](https://quantum-journal.org/).

+++ {"id": "DRplhovffVfk"}

**Codeblock 1**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -31,11 +27,9 @@ outputId: 38c2ce43-463f-4ab8-e402-fbc1d5877ce3
# !pip install mitiq --quiet
```

+++ {"id": "Pghlsxv0fXA2"}

**Codeblock 2**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -44,19 +38,14 @@ outputId: b0419328-2fba-42eb-b27b-a8b20ed24f13
---
import mitiq
mitiq.about()
```

+++ {"id": "lK7iAVVShWu3"}

**Codeblock 4**

+++ {"id": "IXykFfZ6hYW7"}

> Note: The paper just shows the signature of an executor function, but here we explicitly define one to use in examples.
```{code-cell} ipython3
```{code-cell}
:id: PyPWG95HhYfj
import cirq
Expand All @@ -70,11 +59,9 @@ def executor(circuit: mitiq.QPROGRAM) -> float:
).final_density_matrix[0, 0].real
```

+++ {"id": "LxQh9Vehh_2Q"}

**Codeblock 5**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -90,15 +77,12 @@ zne_value = zne.execute_with_zne(circuit, executor)
print("ZNE value:", zne_value)
```

+++ {"id": "3Q2MyAxBiW0C"}

**Codeblock 6**

+++ {"id": "CqiFB4q0ib06"}

> Note: The paper shows pseudocode; here we show an example.
```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -114,15 +98,11 @@ zne_value = zne.execute_with_zne(
print("ZNE value:", zne_value)
```

+++ {"id": "VAGU7qZAjKzD"}

**Codeblock 7**

+++ {"id": "-jbnFbQkjN5J"}

> Note: The paper shows pseudocode; here we show an example.
```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -145,11 +125,9 @@ pec_value = pec.execute_with_pec(
print("\n\nPEC value:", pec_value)
```

+++ {"id": "UvTIzr0ZfYuI"}

**Codeblock 8**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -164,45 +142,36 @@ circ = cirq.Circuit(
print("Original circuit:", circ, sep="\n")
```

+++ {"id": "_5Q3P1DJfcar"}

**Codeblock 9**

```{code-cell} ipython3
---
colab:
base_uri: https://localhost:8080/
id: tSWVDcJIeuck
outputId: e9d0c874-8814-4da0-c54b-a6881d3e614a
---
```{warning}
The method `zne.scaling.fold_gates_from_left` has been removed as of v0.36.0.
```
```python
folded = zne.scaling.fold_gates_from_left(
circ, scale_factor=2
)
print("Folded circuit:", folded, sep="\n")
```

+++ {"id": "4ocoSlNIfnV0"}

**Codeblock 10**

```{code-cell} ipython3
---
colab:
base_uri: https://localhost:8080/
id: k8gLF_fPfneX
outputId: ac0ee6c0-4ad4-4524-dc3d-7c9a413fe2ba
---
```{warning}
The method `zne.scaling.fold_gates_from_right` has been removed as of v0.36.0.
```

```python
folded = zne.scaling.fold_gates_from_right(
circ, scale_factor=2
)
print("Folded circuit:", folded, sep="\n")
```

+++ {"id": "4vZ5JMpVfnyO"}

**Codeblock 11**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -213,15 +182,12 @@ folded = zne.scaling.fold_global(circ, scale_factor=3.)
print("Folded circuit:", folded, sep="\n")
```

+++ {"id": "97Jtd6hNk2cg"}

**Codeblock 12**

+++ {"id": "FYJbOqK3k3zT"}

> Note: The paper shows pseudocode; here we show an example.
```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -239,11 +205,9 @@ print("\nScaled circuit:", scaled, sep="\n")

**Codeblock 13**

+++

> Note: The paper shows pseudocode; here we show an example.
```{code-cell} ipython3
```{code-cell}
from functools import partial
from mitiq.zne.scaling import compute_parameter_variance, scale_parameters
Expand All @@ -263,11 +227,9 @@ zne_value = zne.execute_with_zne(
print("ZNE value via parameter noise scaling:", zne_value)
```

+++ {"id": "ye9I9WLNrGxU"}

**Codeblock 14**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -282,21 +244,17 @@ zne_value = zne.execute_with_zne(
print("ZNE value:", zne_value)
```

+++ {"id": "vm3EwufPfn_B"}

**Codeblock 15**

```{code-cell} ipython3
```{code-cell}
:id: AhnilvXffoF2
linear_factory = zne.inference.LinearFactory(scale_factors=[1.0, 2.0, 3.0])
```

+++ {"id": "3ubB9KrvfoLo"}

**Codeblock 16**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -311,11 +269,9 @@ zne_value = zne.execute_with_zne(
print("ZNE value:", zne_value)
```

+++ {"id": "doyAREdJfoWC"}

**Codeblock 17**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -332,11 +288,9 @@ zne_value = zne.execute_with_zne(
print("ZNE value:", zne_value)
```

+++ {"id": "zvIc-aLuGAut"}

**Codeblock 18**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -353,11 +307,9 @@ zne_value = zne.execute_with_zne(
print("ZNE value:", zne_value)
```

+++ {"id": "bbaOzdc-GLeM"}

**Codeblock 19**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand Down Expand Up @@ -387,11 +339,9 @@ zne_value = zne.execute_with_zne(
print("ZNE value:", zne_value)
```

+++ {"id": "t3o-Xc5rGLsR"}

**Codeblock 20**

```{code-cell} ipython3
```{code-cell}
:id: qqndfKFIGLy6
from mitiq import pec
Expand All @@ -408,11 +358,9 @@ noisy_z = pec.NoisyOperation(
)
```

+++ {"id": "J0rb6P6XGL42"}

**Codeblock 21 & 22**

```{code-cell} ipython3
```{code-cell}
:id: UsxGtCrAGL-h
h_rep = pec.OperationRepresentation(
Expand All @@ -422,21 +370,17 @@ h_rep = pec.OperationRepresentation(
)
```

+++ {"id": "D2NVsYKVGMJ-"}

**Codeblock 23**

```{code-cell} ipython3
```{code-cell}
:id: Civ6U2OSGMQV
noisy_op, sign, coeff = h_rep.sample()
```

+++ {"id": "F8Ryo8cGGMWu"}

**Codeblock 24**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -451,19 +395,16 @@ print("Sampled circuit:", sampled, sep="\n") # Run many times to see different

> Note: For a runnable code block in which PEC is applied to estimate an expectation value, see _Codeblock 7_.
+++ {"id": "RYh92EfKGMix"}

**Codeblock 25 & 26**

+++ {"id": "C6K0VzUCLkcw"}

See https://mitiq.readthedocs.io/en/stable/examples/cdr_api.html.

+++ {"id": "T73iRSXLGMud"}

**Codeblock 27**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -477,11 +418,9 @@ zne_value = mitigated_executor(circuit)
print("ZNE value:", zne_value)
```

+++ {"id": "042uqn-fMiYj"}

**Codeblock 28**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -499,11 +438,9 @@ zne_value = execute(circuit)
print("ZNE value:", zne_value)
```

+++ {"id": "P5HEyCXwMio8"}

**Codeblock 29**

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand All @@ -525,11 +462,9 @@ zne_then_pec_value = execute(circuit3)
print("ZNE then PEC value:", zne_then_pec_value) # Note this is not accurate (bad representation).
```

+++ {"id": "LQYPqUazMi3b"}

**Codeblock 30**

```{code-cell} ipython3
```{code-cell}
:id: dyk7Hj1nPB48
import qiskit
Expand All @@ -556,7 +491,7 @@ def execute(
return counts.get("00", 0.0) / shots
```

```{code-cell} ipython3
```{code-cell}
---
colab:
base_uri: https://localhost:8080/
Expand Down
Loading

0 comments on commit 42779ed

Please sign in to comment.