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

Improving simulations.py input options #111

merged 23 commits into from
Aug 3, 2022

Conversation

nariman87
Copy link
Contributor

@nariman87 nariman87 commented Jul 28, 2022

Context for changes

  • New features:
    • 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 error corrections and automatically set up the output file based on inputs.
      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
      

Example usage and tests

Users can now insert only a code (with any imaginable args), a noise (with any imaginable args), and a decoder (with any imaginable args). As mentioned as long as those combinations are valid FlamingPy will run error corrections and automatically set up the output file based on inputs.

As in

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':{}}" -trials 100

Gives

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,{},10,100,00:15:50,0.370795,1

Performance results justifying changes

  • Not Applicable

Workflow actions and tests

test_simulations.py has been updated to support the new I/O format.

Expected benefits and drawbacks

Expected benefits:

  • More intuitive and technically sound input and output for simulations.py. The user no longer need to manually adjust the script for every newly supported code, noise, and decoder, plus any desired argument can be now inserted.

Related Github issues

  • Not Applicable

Checklist and integration statements

  • My Python and C++ codes follow this project's coding and commenting styles as indicated by existing files. Precisely, the changes conform to given black, docformatter and pylint configurations.
  • I have performed a self-review of these changes, checked my code (including for codefactor compliance), and corrected misspellings to the best of my capacity. I have synced this branch with others as required.
  • I have added context for corresponding changes in documentation and README.md as needed.
  • I have added new workflow CI tests for corresponding changes, ensuring codecoverage is 95% or better, and these pass locally for me.
  • I have updated CHANGELOG.md following the template. I recognize that the developers may revisit CHANGELOG.md and the versioning, and create a Special Release including my changes.

@nariman87
Copy link
Contributor Author

@ilan-tz, please check above to see if this was what we wanted here. If so, I can finalize this to be merged.

@codecov
Copy link

codecov bot commented Jul 28, 2022

Codecov Report

Merging #111 (f5b5742) into main (028dc74) will decrease coverage by 0.14%.
The diff coverage is 94.44%.

@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
- Coverage   96.19%   96.05%   -0.15%     
==========================================
  Files          36       36              
  Lines        2209     2206       -3     
==========================================
- Hits         2125     2119       -6     
- Misses         84       87       +3     
Impacted Files Coverage Δ
flamingpy/decoders/decoder.py 97.45% <92.85%> (-1.69%) ⬇️
flamingpy/simulations.py 98.75% <96.00%> (-1.25%) ⬇️
flamingpy/_version.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 028dc74...f5b5742. Read the comment docs.

@nariman87 nariman87 self-assigned this Jul 29, 2022
@nariman87 nariman87 added the breaking feature A new feature that is not backward compatible label Jul 29, 2022
@nariman87 nariman87 marked this pull request as draft July 29, 2022 14:27
@nariman87 nariman87 marked this pull request as ready for review August 2, 2022 12:31
nariman87 and others added 3 commits August 2, 2022 22:46
Fix when exception is raised on incompatible decoder / weight options combination
Copy link
Collaborator

@ilan-tz ilan-tz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! This will automate the simulations file for future additions to codes, decoders, and noise models, which will make the process scalable.

I made a few small comments and suggestions. One of these is to do away completely with the str_dict, so we don't have to update this as well when we make additions to the above. I have also made a small commit with a change to decoder.py that fixes when an Exception is raised for some incompatible decoder/weight option combinations.

flamingpy/simulations.py Outdated Show resolved Hide resolved
Comment on lines 188 to 189
for value in decoder_args.values():
file.write("%s," % (value))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small bug here. Every entry of weight_opts is placed in a separate column of the output file, which causes the rest of the entries to be shifted to the right relative to the heading, whereas they are supposed to be placed in just one column.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks, fixed by adding double quotes to that field.

flamingpy/simulations.py Show resolved Hide resolved
flamingpy/simulations.py Outdated Show resolved Hide resolved
flamingpy/simulations.py Outdated Show resolved Hide resolved
flamingpy/simulations.py Outdated Show resolved Hide resolved
flamingpy/simulations.py Outdated Show resolved Hide resolved
flamingpy/simulations.py Outdated Show resolved Hide resolved
flamingpy/simulations.py Outdated Show resolved Hide resolved
flamingpy/simulations.py Outdated Show resolved Hide resolved
nariman87 and others added 10 commits August 3, 2022 14:57
Co-authored-by: ilan-tz <57886357+ilan-tz@users.noreply.github.com>
Co-authored-by: ilan-tz <57886357+ilan-tz@users.noreply.github.com>
Co-authored-by: ilan-tz <57886357+ilan-tz@users.noreply.github.com>
Co-authored-by: ilan-tz <57886357+ilan-tz@users.noreply.github.com>
Co-authored-by: ilan-tz <57886357+ilan-tz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking feature A new feature that is not backward compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants