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

Add tests to the library #130

Merged
merged 133 commits into from
Mar 1, 2024
Merged

Add tests to the library #130

merged 133 commits into from
Mar 1, 2024

Conversation

nelimee
Copy link
Contributor

@nelimee nelimee commented Feb 8, 2024

This branch has been created from #100 because both #114 and #100 added/changed a lot of things and I did not want to write tests for things that will be removed soon.

There is no need to look at the changes here, the immense majority of the files changed are caused by #100 and #114 and will disappear from this PR once they are merged.

Should fix or at least help fixing #106

nelimee and others added 30 commits February 1, 2024 11:29
The origin is now an optional parameter at construction. The origin is
already provided after the instance construction whenever the "on"
method is called, it is now intercepted from that call.
If the "on" method is not called and the origin is needed, an exception
is raised.
The shape method of the TemplateOrchestrator class was not returning the
correct type (according to its subclass Template). This is now fixed in
this commit by returning an instance of Shape2D
The display_template function has a specialised path for
TemplateOrchestrator instances. This path can now be used for any
Template instance.
The TemplateOrchestrator.instanciate method was not behaving like the
Template.instanciate method, requiering a 0 plaquette at the beginning
of the provided plaquette indices.
This commit fixes that by adding the 0 plaquette under-the-hood
and not exposing it to the public API anymore. In particular, the 0
plaquette in no more accounted for in the expected_plaquettes_number
method.
The generate_circuit function was only accepting TemplateOrchestrator
instances according to the typing information. This is no longer true
thanks to the Template hierarchy rework: any valid instance of Template
should be supported by the generate_circuit function.
The TemplateStack class is able to represent Template instances stacked
on top of each other.
The BaseLayer __init__ method was annoted to only accept
TemplateOrchestrator instances. Thanks to the API unification made in
QCHackers#108, the function should be able to accept any Template.
This commit simply adds the XXFromXXXXPlaquette and ZZFromZZZZPlaquette
classes to the plaquette library imports.
This commit introduces a new notebook showcasing the use of the layer
mecanism to perform a qubit movement.
It is still a WIP: an issue with template scaling is currently blocking
further improvements.
See QCHackers#80 (comment)
for a quick view about why the if statement needs to be here.
@nelimee nelimee self-assigned this Feb 28, 2024
The two warnings silenced are
1. in a test, where typing is less important,
2. in a context where the return type does not encode correctly the
  pre-conditions: cirq.CircuitOperation.repetitions is typed in cirq to
  be an integer, but might be encoded as a sympy expression, that should
  be evalf() to be used. evalf() returning a "number" (may be float or
  complex as well), its type annotation is too generic. In this
  specific case, the type should be fine as long as the user/cirq
  enforce the type annotation of cirq.
@nelimee
Copy link
Contributor Author

nelimee commented Feb 28, 2024

The current state of this PR is:

  • tqec.generation.circuit is covered (per pytest-cov output) but the tests are not good enough.
  • tqec.plaquette is not tested.
  • tqec.noise_models is not tested.
  • tqec.template.composed is not tested.
  • the other parts of the library should be adequately tested.

@nelimee nelimee linked an issue Feb 29, 2024 that may be closed by this pull request
Calling any method that ends up calling
ComposedTemplate._compute_ul_absolute_position on a
ComposedTemplate instance without any template was crashing.
This commit fixes the crash.
@nelimee
Copy link
Contributor Author

nelimee commented Mar 1, 2024

The current state of this PR is:

* `tqec.generation.circuit` is covered (per `pytest-cov` output) but the tests are not good enough.

* `tqec.plaquette` is not tested.

* `tqec.noise_models` is not tested.

* `tqec.template.composed` is not tested.

* the other parts of the library should be adequately tested.

A few updates (note that the modules have been moved around since the last message #163):

  • tqec.circuit.circuit is not tested enough yet, but some meaningful tests are present.
  • testing tqec.plaquette would highly benefit from using stim.Tableau and stim.PauliString to check the effect of plaquettes on a stabilised state. This will likely come in a future PR, so I think we can call it a day on that part and wait for more code.
  • tqec.noise_models is a pain to implement tests for.
  • tqec.template.composed has a few tests, better than nothing, but insufficient.

Because I feel like it will take forever to implement the missing tests, I would prefer to merge that PR now and implement the missing tests incrementally, in follow-up PRs.

@nelimee nelimee marked this pull request as ready for review March 1, 2024 09:44
Copy link
Contributor

@inmzhang inmzhang left a comment

Choose a reason for hiding this comment

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

Great work! We can merge this pr for now and add more tests in the future.

@nelimee nelimee merged commit a3ef9db into QCHackers:main Mar 1, 2024
5 checks passed
@nelimee nelimee deleted the unit_testing branch March 1, 2024 13:47
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) ci/cd Testing, review, release 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.

Implement more tests
2 participants