Skip to content

Commit bd8b307

Browse files
authored
Fix remaining issues for v1.9 (#277)
- Fix doctests not being run by continuous integration - Add a `doctest_proper.py` script for running doctests and actually including values added at import time - Fix the doctest failures accumulated due to the fact that they weren't even being checked - Rewrite `generate_api_reference.py` to have output more like the generated `stim.pyi` stubs file - Add `stim.TableauSimulator.{h_xz,cx,zcx,zcy,zcz}` gate alias methods - Add `stim.TableauSimulator.{c_xyz,c_zyx}` gate methods - Add `stim.TableauSimulator.num_qubits` Fixes #275
1 parent eb3e224 commit bd8b307

23 files changed

+7310
-5530
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ jobs:
282282
- run: pip install pybind11==2.9.2 && python setup.py install # Workaround for https://github.com/pypa/setuptools/issues/230
283283
- run: pip install pytest
284284
- run: pytest src
285-
- run: python -c "import stim; import doctest; assert doctest.testmod(stim).failed == 0"
285+
- run: ./doctest_proper.py --module stim
286286
test_stimcirq:
287287
runs-on: ubuntu-latest
288288
steps:
@@ -296,7 +296,7 @@ jobs:
296296
- run: pip install -e glue/cirq
297297
- run: pip install pytest
298298
- run: pytest glue/cirq
299-
- run: python -c "import stimcirq; import doctest; assert doctest.testmod(stimcirq).failed == 0"
299+
- run: ./doctest_proper.py --module stimcirq --import cirq sympy
300300
test_sinter:
301301
runs-on: ubuntu-latest
302302
steps:
@@ -310,7 +310,7 @@ jobs:
310310
- run: pip install -e glue/sample
311311
- run: pip install pytest
312312
- run: pytest glue/sample
313-
- run: python -c "import sinter; import doctest; assert doctest.testmod(sinter).failed == 0"
313+
- run: ./doctest_proper.py --module sinter
314314
test_stimzx:
315315
runs-on: ubuntu-latest
316316
steps:
@@ -324,7 +324,7 @@ jobs:
324324
- run: pip install -e glue/zx
325325
- run: pip install pytest
326326
- run: pytest glue/zx
327-
- run: python -c "import stimzx; import doctest; assert doctest.testmod(stimzx).failed == 0"
327+
- run: ./doctest_proper.py --module stimzx
328328
test_stimjs:
329329
runs-on: ubuntu-latest
330330
steps:

doc/developer_documentation.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ These notes generally assume you are on a Linux system.
4040
- [autoformating code](#autoformat)
4141
- [with clang-format](#autoformat.clang-format)
4242

43-
# <a name="compatibility></a>Compatibility guarantees across versions
43+
# <a name="compatibility"></a>Compatibility guarantees across versions
4444

4545
A *bug* is bad behavior that wasn't intended. For example, the program crashing instead of returning empty results when sampling from an empty circuit would be a bug.
4646

@@ -410,49 +410,52 @@ See [creating a python dev environment](#venv) for instructions on creating a
410410
python virtual environment with your changes to stim installed.
411411

412412
Unit tests are run using `pytest`.
413-
Examples in docstrings are tested using `doctest`.
413+
Examples in docstrings are tested using the `doctest_proper` script at the repo root,
414+
which uses python's [`doctest`](https://docs.python.org/3/library/doctest.html) module
415+
but ensures values added to a module at import time are also tested (instead of requiring
416+
them to be [manually listed in a `__test__` property](https://docs.python.org/3/library/doctest.html#which-docstrings-are-examined)).
414417

415418
To test everything:
416419

417420
```bash
418421
# from the repository root in a virtualenv with development wheels installed:
419422
pytest src glue
420-
python -c "import stim; import doctest; assert doctest.testmod(stim).failed == 0"
421-
python -c "import stimcirq; import doctest; assert doctest.testmod(stimcirq).failed == 0"
422-
python -c "import sinter; import doctest; assert doctest.testmod(sinter).failed == 0"
423-
python -c "import stimzx; import doctest; assert doctest.testmod(stimzx).failed == 0"
423+
./doctest_proper.py --module stim
424+
./doctest_proper.py --module stimcirq --import cirq sympy
425+
./doctest_proper.py --module sinter
426+
./doctest_proper.py --module stimzx
424427
```
425428

426429
Test only `stim`:
427430

428431
```bash
429432
# from the repository root in a virtualenv with development wheels installed:
430433
pytest src
431-
python -c "import stim; import doctest; assert doctest.testmod(stim).failed == 0"
434+
./doctest_proper.py --module stim
432435
```
433436

434437
Test only `stimcirq`:
435438

436439
```bash
437440
# from the repository root in a virtualenv with development wheels installed:
438441
pytest glue/cirq
439-
python -c "import stimcirq; import doctest; assert doctest.testmod(sitmcirq).failed == 0"
442+
./doctest_proper.py --module stimcirq --import cirq sympy
440443
```
441444

442445
Test only `sinter`:
443446

444447
```bash
445448
# from the repository root in a virtualenv with development wheels installed:
446449
pytest glue/sample
447-
python -c "import sinter; import doctest; assert doctest.testmod(sinter).failed == 0"
450+
./doctest_proper.py --module sinter
448451
```
449452

450453
Test only `stimzx`:
451454

452455
```bash
453456
# from the repository root in a virtualenv with development wheels installed:
454457
pytest glue/zx
455-
python -c "import stimzx; import doctest; assert doctest.testmod(stimzx).failed == 0"
458+
./doctest_proper.py --module stimzx
456459
```
457460

458461

0 commit comments

Comments
 (0)