Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving simulations.py input options #111

Merged
merged 23 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

### New features since the last release

* The I/O of frontend `simulations.py` has been improved. The input has been simplified to an intuitive set of `code`, `code_args`, `noise`, and `noise_args`. As long as those combinations are valid, FlamingPy will run simulations and automatically set up the output file based on inputs. [#111](https://github.com/XanaduAI/flamingpy/pull/111) (backward incompatible)
* An example run will be
```
python flamingpy/simulations.py -code "SurfaceCode" -code_args "{'distance':3, 'ec':'primal', 'boundaries':'open'}" -noise "CVLayer" -noise_args "{'delta':0.09, 'p_swap':0.25}" -decoder "MWPM" -decoder_args "{'weight_opts':{'method':'blueprint', 'integer':False, 'multiplier':1, 'delta':0.09}}" -trials 100
```
which generates
```
code,distance,ec,boundaries,noise,delta,p_swap,decoder,weight_opts,errors,trials,current_time,simulation_time,mpi_size
SurfaceCode,3,primal,open,CVLayer,0.09,0.25,MWPM,{'method': 'blueprint', 'integer': False, 'multiplier': 1, 'delta': 0.09},10,100,00:15:50,0.370795,1
```
ilan-tz marked this conversation as resolved.
Show resolved Hide resolved

### Bug fixes

Expand All @@ -16,6 +26,8 @@

This release contains contributions from (in alphabetical order):

Nariman Saadatmand

See full commit details ...


Expand Down
2 changes: 1 addition & 1 deletion flamingpy/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"""Version number (major.minor.patch[label])"""


__version__ = "0.9.1b0"
__version__ = "0.9.1b0.dev0"
74 changes: 38 additions & 36 deletions flamingpy/decoders/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"""Decoding and recovery functions."""

# pylint: disable=import-outside-toplevel
# pylint: disable=import-outside-toplevel,too-many-statements

import sys
import numpy as np
Expand Down Expand Up @@ -55,42 +55,44 @@ def assign_weights(code, decoder, **kwargs):

# Blueprint weight assignment or weighted-union-find weight assignment
# dependent on the type of neighbours.
if weight_options.get("method") == "blueprint" and decoder == "MWPM":
for node in qubit_coords:
neighbors = G[node]
# Obtain the list and the number of p-squeezed states in the neighborhood of the node.
p_list = [G.nodes[v]["state"] for v in neighbors if G.nodes[v]["state"] == "p"]
p_count = len(p_list)
if p_count in (0, 1):
if weight_options.get("prob_precomputed"):
err_prob = G.nodes[node]["p_phase_cond"]
else:
delta_effective = (len(neighbors) + 1) * weight_options.get("delta")
hom_val = G.nodes[node]["hom_val_p"]
err_prob = Z_err_cond(delta_effective, hom_val)
# Allow for taking log of 0.
err_prob = min(err_prob, 0.5)
# TODO: Can I just choose an arbitrary small number?
if err_prob == 0:
err_prob = smallest_number
if weight_options.get("integer"):
multiplier = weight_options.get("multiplier")
weight = round(-multiplier * np.log(err_prob))
else:
weight = -np.log(err_prob)
G.nodes[node]["weight"] = weight
else:
# Dictionary of the form number of swapouts: error probability.
weight_dict = {2: 1 / 4, 3: 1 / 3, 4: 2 / 5}
err_prob = weight_dict[p_count]
if weight_options.get("integer"):
multiplier = weight_options.get("multiplier")
weight = round(-multiplier * np.log(err_prob))
if weight_options.get("method") == "blueprint":
if decoder == "MWPM":
for node in qubit_coords:
neighbors = G[node]
# Obtain the list and the number of p-squeezed states in
# the neighborhood of the node.
p_list = [G.nodes[v]["state"] for v in neighbors if G.nodes[v]["state"] == "p"]
p_count = len(p_list)
if p_count in (0, 1):
if weight_options.get("prob_precomputed"):
err_prob = G.nodes[node]["p_phase_cond"]
else:
delta_effective = (len(neighbors) + 1) * weight_options.get("delta")
hom_val = G.nodes[node]["hom_val_p"]
err_prob = Z_err_cond(delta_effective, hom_val)
# Allow for taking log of 0.
err_prob = min(err_prob, 0.5)
# TODO: Can I just choose an arbitrary small number?
if err_prob == 0:
err_prob = smallest_number
if weight_options.get("integer"):
multiplier = weight_options.get("multiplier")
weight = round(-multiplier * np.log(err_prob))
else:
weight = -np.log(err_prob)
G.nodes[node]["weight"] = weight
else:
weight = -np.log(err_prob)
G.nodes[node]["weight"] = weight
if decoder == "UF":
raise Exception("Incompatible decoder/weight options.")
# Dictionary of the form number of swapouts: error probability.
weight_dict = {2: 1 / 4, 3: 1 / 3, 4: 2 / 5}
err_prob = weight_dict[p_count]
if weight_options.get("integer"):
multiplier = weight_options.get("multiplier")
weight = round(-multiplier * np.log(err_prob))
else:
weight = -np.log(err_prob)
G.nodes[node]["weight"] = weight
elif decoder == "UF":
raise Exception("Incompatible decoder & weight options combination.")
# Naive weight assignment, unity weights.
elif weight_options.get("method") == "uniform":
if decoder == "UF":
Expand Down
Loading