How to use the pystan.stanc function in pystan

To help you get started, we’ve selected a few pystan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / yaps / tests / stan / test_stan2yaps.py View on Github external
def run_test(dir):
    pathlist = Path(dir).glob('*.stan')
    nb_test = 0
    nb_success = 0
    nb_bad = 0
    for p in pathlist:
        path = str(p)
        with open(path, 'r') as fin:
            code = fin.read()
            try:
                pystan.stanc(model_code=code)
                nb_test += 1
                try:
                    source = yaps.from_stan(code_file=path)
                    ast_ = yaps.from_string(source)
                    stan = yaps.to_stan(ast_)
                    pystan.stanc(model_code=stan)
                    nb_success += 1
                except (AttributeError, SyntaxError, TypeError, AssertionError, ValueError) as err:
                    print("FAILED\t", path, err)
                except RuntimeError:
                    nb_success += 1
            except (ValueError, RuntimeError):
                nb_bad += 1

    print("-------------------------")
    print("{}% of success ({}/{} valid Stan examples, {} bad examples ignored)".format(
github IBM / yaps / tests / stan / test_stan2yaps.py View on Github external
pathlist = Path(dir).glob('*.stan')
    nb_test = 0
    nb_success = 0
    nb_bad = 0
    for p in pathlist:
        path = str(p)
        with open(path, 'r') as fin:
            code = fin.read()
            try:
                pystan.stanc(model_code=code)
                nb_test += 1
                try:
                    source = yaps.from_stan(code_file=path)
                    ast_ = yaps.from_string(source)
                    stan = yaps.to_stan(ast_)
                    pystan.stanc(model_code=stan)
                    nb_success += 1
                except (AttributeError, SyntaxError, TypeError, AssertionError, ValueError) as err:
                    print("FAILED\t", path, err)
                except RuntimeError:
                    nb_success += 1
            except (ValueError, RuntimeError):
                nb_bad += 1

    print("-------------------------")
    print("{}% of success ({}/{} valid Stan examples, {} bad examples ignored)".format(
        round(nb_success/nb_test * 100, 2), nb_success, nb_test, nb_bad))
github IBM / yaps / tests / stan / test_stan2yaps.py View on Github external
def roundtrip(path):
    with open(path, 'r') as fin:
        code = fin.read()
        print(code)
        pystan.stanc(model_code=code)
    print('--------------------------------')
    source = yaps.from_stan(code_file=path)
    print(source)
    print('--------------------------------')
    ast_ = yaps.from_string(source)
    code = yaps.to_stan(ast_)
    print(code)
    print('--------------------------------')
    pystan.stanc(model_code=code)