Skip to content

Implement fixed boundary convention#562

Merged
nelimee merged 199 commits intomainfrom
feat/fixed_parity
Jul 4, 2025
Merged

Implement fixed boundary convention#562
nelimee merged 199 commits intomainfrom
feat/fixed_parity

Conversation

@nelimee
Copy link
Copy Markdown
Contributor

@nelimee nelimee commented Apr 8, 2025

This PR implements the CubeBuilder and PipeBuilder interfaces for the fixed parity convention.

TODO list:

  • Fix duplicate detectors because UP and DOWN extended plaquettes have a shared syndrome qubit.
  • Fix missing detector in move rotation.
  • Plaquette.project_on_data_qubit_indices does the opposite of what the documentation says it does. It is only used in ExtendedPlaquette, so should not be too much of a hassle to fix.
  • Address all comments from code review,
  • Try to address Fix extended stablizer measurement implementation #578 by changing schedules

@nelimee nelimee added enhancement New feature or request, may not be in the task flow backend Issue pertaining to the Python backend (tqec package) labels Apr 8, 2025
@nelimee nelimee self-assigned this Apr 8, 2025
@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Apr 11, 2025

At the moment:

  • mypy is failing, and this looks like a false positive.
  • I initially thought that only the extended plaquettes should be alternated, but all layers in the same timeslice as the spatial junction should be. That is a global change that can be done in multiple ways, and I am not sure what is the best one.

Everything else should be implemented. It seems like there are still scheduling issues somewhere, but there should be only a few left as I already corrected quite a few.

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 3, 2025

Building the docs is also too slow, is it performing circuit generation for all gallery examples for all different error rates and ks?

It is performing circuit generation and simulation. In theory, the cache should allow that CI job to run in ~7 minutes, but it has been written thinking that we could update a cache. It turns out that is not the case (see the Update a cache section).

I will try the code provided as example in the above section, but that might lead to a lot of caches that end up being unused. Let's try it out.

Once the CI issue is resolved, do you think this PR is ready to be merged?

Yes :)

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 3, 2025

So now in theory:

  • a new cache is created at each workflow run,
  • if at least one cache with a key matching docs_database_and_stim_results_cache.* exists, the newer matching cache is used to pre-populate the new cache,
  • there should not be issues with sharing cache between different branches.

I will see if there is a solution to automatically delete cache entries when merging the PR.

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 3, 2025

@purva-thakre could you double check the last changes made to CI?

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 3, 2025

I re-ran the doc job to see if the cache works.

@purva-thakre
Copy link
Copy Markdown
Collaborator

@nelimee I see a new cache was added 3 hours ago. This PR is using the new cache. Maybe when Yiming noticed the docs build took longer, it was because the cache was being added.

image

Now, the time taken by the docs build is approximately the same on main and this PR.

Main This PR
image image

path: docs/_examples_database/
key: docs_database_and_stim_results_cache
# See https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
key: docs_database_and_stim_results_cache-${{ github.run_id }}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@nelimee we don't want to create a cache for every run, right?

image

Copy link
Copy Markdown
Collaborator

@purva-thakre purva-thakre Jul 3, 2025

Choose a reason for hiding this comment

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

a new cache is created at each workflow run,

This is going to increase the docs build time for the first time for each run.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ideally, we would like to avoid having one cache per run... In practice, that seems hard. I plan to add a job to delete caches from a PR when the PR is closed to "solve" that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

a new cache is created at each workflow run,

This is going to increase the docs build time for the first time for each run.

No, explanations in my comment below.

@purva-thakre
Copy link
Copy Markdown
Collaborator

but it has been written thinking that we could update a cache

My idea behind this was if we need to update a cache, we could manually delete the cache and let the first run add a new cache. Subsequent runs shouldn't take as long.

key: docs_database_and_stim_results_cache-${{ github.run_id }}
enableCrossOsArchive: true
restore-keys: |
docs_database_and_stim_results_cache
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I do no think this line is working. This is supposed to restore the run specific cache to this key. The workflow goes through the steps as expected but the cache with this key is not restored at all. The original cache was used/restored 4 hours ago.

image

https://github.com/tqec/tqec/actions/runs/16055758756/job/45324517877?pr=562#step:5:23

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it is working. What this does is, when the cache misses (which should be everytime because we have a new cache at each workflow), it creates a new cache and pre-populate it with the content of the earliest cache that starts with the entries in restore-keys. So here, the workflow will always:

  • cache miss, so create a new cache,
  • find a previous cache that starts with docs_database_and_stim_results_cache and pre-populate the new cache with the content of that old cache,
  • perform documentation generation, potentially updating the new cache at the end.

The original cache in main should be used only once, at the first workflow run of each PR. Then, the cache created by the first successful workflow run will be used as a base for the next one, which will in turn be used as a base for the next one, ...

That's the only solution I found.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok. I think I need some time to look over the new CI changes. I won't be able to over the next few days, it's a long holiday weekend in the US.

Feel free to merge the PR, I can make another PR if I think your changes require some additional tweaks.

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 3, 2025

but it has been written thinking that we could update a cache

My idea behind this was if we need to update a cache, we could manually delete the cache and let the first run add a new cache. Subsequent runs shouldn't take as long.

Yes, except if the cache is on the main branch and is shared by several branches.

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 4, 2025

@inmzhang I think this can be merged. I'll try if I have the time to do a final re-review and full-test to check one last time, but I think the implementation should be pretty robust.

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 4, 2025

I re-run the complete set of tests, searched for unaddressed TODOs in the code (found one in src/tqec/_cli/subcommands/dae2circuits.py but that is not part of this PR), I re-ran mypy and I added a comment on compile_test.py to write explicitly that some tests will fail for k == 3 and link to the explanation.

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 4, 2025

Merging as soon as CI completes with expected timings and no errors

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 4, 2025

Cache seems to not be working as expected. Will try to fix that later.

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 4, 2025

Cache seems to not be working as expected. Will try to fix that later.

That was due (I think) to the original cache docs_database_and_stim_results_cache on main that was systematically restored instead of the last cache entry on this branch. That could have been solved by changing the restore-keys entry, but because cache key changed anyway I simply deleted the cache on main, because it will be outdated at the next merge.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 4, 2025

Code Coverage

Package Line Rate Complexity Health
src.tqec 100% 0
src.tqec.circuit 95% 0
src.tqec.circuit.schedule 99% 0
src.tqec.compile 91% 0
src.tqec.compile.blocks 95% 0
src.tqec.compile.blocks.layers 92% 0
src.tqec.compile.blocks.layers.atomic 96% 0
src.tqec.compile.blocks.layers.composed 98% 0
src.tqec.compile.detectors 91% 0
src.tqec.compile.observables 96% 0
src.tqec.compile.specs 85% 0
src.tqec.compile.specs.library 97% 0
src.tqec.compile.specs.library.generators 96% 0
src.tqec.compile.tree 77% 0
src.tqec.compile.tree.annotators 81% 0
src.tqec.computation 93% 0
src.tqec.gallery 100% 0
src.tqec.interop 87% 0
src.tqec.interop.collada 92% 0
src.tqec.interop.pyzx 81% 0
src.tqec.interop.pyzx.synthesis 91% 0
src.tqec.plaquette 85% 0
src.tqec.plaquette.compilation 100% 0
src.tqec.plaquette.compilation.passes 92% 0
src.tqec.plaquette.compilation.passes.transformer 98% 0
src.tqec.plaquette.rpng 80% 0
src.tqec.plaquette.rpng.translators 97% 0
src.tqec.post_processing 82% 0
src.tqec.post_processing.utils 96% 0
src.tqec.templates 92% 0
src.tqec.utils 93% 0
Summary 92% (7355 / 8017) 0

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 4, 2025

Let's see how the cache cleanup behaves. At the moment:
image

@nelimee nelimee merged commit 419bf37 into main Jul 4, 2025
6 checks passed
@nelimee nelimee deleted the feat/fixed_parity branch July 4, 2025 09:34
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 4, 2025

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 4, 2025

That seems to have worked flawlessly, the 3 caches created in this branch were deleted in less than 10 seconds of CI time.

@nelimee
Copy link
Copy Markdown
Contributor Author

nelimee commented Jul 4, 2025

I forgot to bump the detector database version number, not sure it was needed though, just adding the comment to think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Issue pertaining to the Python backend (tqec package) enhancement New feature or request, may not be in the task flow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants