-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add cli to python api with entry point. Fixes #45
- Loading branch information
1 parent
ca7d0f8
commit 44819d2
Showing
13 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
error(0.1) D0 L0 | ||
error(0.1) D0 D1 L1 | ||
error(0.1) D1 L2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
shot | ||
shot D0 | ||
shot D1 | ||
shot D0 D1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import sys | ||
|
||
import pymatching | ||
|
||
|
||
def cli_argv(): | ||
pymatching.cli(command_line_args=sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import os | ||
import sys | ||
from contextlib import contextmanager | ||
|
||
import pymatching | ||
from pymatching import cli | ||
from pymatching._cli_argv import cli_argv | ||
|
||
from .config import DATA_DIR | ||
|
||
|
||
@contextmanager | ||
def three_errors_data(): | ||
out_fn = os.path.join(DATA_DIR, "three_errors_predictions.dets") | ||
if os.path.isfile(out_fn): | ||
os.remove(out_fn) | ||
assert not os.path.exists(out_fn) | ||
args = [ | ||
"predict", | ||
"--dem", os.path.join(DATA_DIR, "three_errors.dem"), | ||
"--in", os.path.join(DATA_DIR, "three_errors.dets"), | ||
"--in_format", "dets", | ||
"--out", out_fn, | ||
"--out_format", "dets", | ||
] | ||
yield args | ||
assert os.path.isfile(out_fn) | ||
with open(out_fn) as f: | ||
assert f.read() == """shot | ||
shot L0 | ||
shot L2 | ||
shot L1 | ||
""" | ||
os.remove(out_fn) | ||
|
||
|
||
def test_cli(): | ||
with three_errors_data() as args: | ||
cli(command_line_args=args) | ||
|
||
|
||
def test_protected_cli(): | ||
with three_errors_data() as args: | ||
pymatching._cpp_pymatching.main(command_line_args=args) | ||
|
||
|
||
def test_cli_argv(): | ||
from unittest.mock import patch | ||
with three_errors_data() as args: | ||
with patch.object(sys, 'argv', ["cli"] + args): | ||
cli_argv() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pathlib | ||
import os | ||
|
||
THIS_DIR = pathlib.Path(__file__).parent.resolve() | ||
DATA_DIR = os.path.join(pathlib.Path(THIS_DIR).parent.absolute(), "data") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters