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

[CLI] Add example command to CLI #1010

Merged
merged 24 commits into from
May 22, 2020
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
85bb386
Bugfix: shutil not imported for command:convert.
rexwangcc May 17, 2020
071edd9
Merge branch 'master' of https://github.com/taichi-dev/taichi into ad…
rexwangcc May 17, 2020
2038b1e
Minor improvement to dev_install docs.
rexwangcc May 17, 2020
9edb5f0
Document some hacks for dev_install under Ubuntu.
rexwangcc May 17, 2020
84b9647
The naive way to implement this.
rexwangcc May 18, 2020
fc7afe8
Include the examples folder in Python build.
rexwangcc May 18, 2020
ed8bc91
Nice, macOS could use Homebrew.
rexwangcc May 18, 2020
1787d60
Error out when invalid example name is given.
rexwangcc May 18, 2020
0575229
[skip ci] enforce code format
taichi-gardener May 18, 2020
7f207c0
Revert changes to docs for correctness and simplicity.
rexwangcc May 18, 2020
a7c1c85
Resolve merge conflict with the gardener.
rexwangcc May 18, 2020
94a4da8
Switch off os.system and use importlib.
rexwangcc May 18, 2020
daa7876
Remove redundant comments.
rexwangcc May 18, 2020
b7a5e0b
Travis CI failed. Please retry.
rexwangcc May 19, 2020
860b085
Resolve merge conflict.
rexwangcc May 19, 2020
61d0720
[skip ci] enforce code format
taichi-gardener May 19, 2020
08eae82
Travis CI failed. Please retry.
rexwangcc May 19, 2020
e4fe241
Merge branch 'add-example-to-cli' of github.com:rexwangcc/taichi into…
rexwangcc May 19, 2020
99b3b9b
In case the user forgets to specify anything. we SHOULD really switch…
rexwangcc May 20, 2020
d566618
[skip ci] i must be sleepy.
rexwangcc May 20, 2020
417a105
How about factor them out.
rexwangcc May 21, 2020
28c4417
One more thing to make it runnable from anywhere.
rexwangcc May 21, 2020
6cba5b8
Alright lint.
rexwangcc May 21, 2020
e4131f2
add taichi.examples to package
yuanming-hu May 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[skip ci] enforce code format
  • Loading branch information
taichi-gardener committed May 18, 2020
commit 05752295765dc6d5caaae983b840ac571b0a4b98
6 changes: 3 additions & 3 deletions docs/dev_install.rst
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ Installing Depedencies
* (**If on macOS**) You could rely on `Homebrew <https://brew.sh/>`_ to install LLVM with clang for you.
rexwangcc marked this conversation as resolved.
Show resolved Hide resolved
``brew install llvm@8`` will only install llvm and clang 8 for you, but since macOS usually has pre-installed
clang, Homebrew won't link it automatically. You could run ``brew --prefix llvm@8`` to check the location of
installation and usually you will need to add lines similar to the following to your shell profile (~/.bashrc or
installation and usually you will need to add lines similar to the following to your shell profile (~/.bashrc or
~/.zshrc):

.. code-block:: bash
@@ -39,7 +39,7 @@ Installing Depedencies
export CC=clang
export CXX=clang++

After restarting your shell, you could then use ``clang --version`` to verify you are using the
After restarting your shell, you could then use ``clang --version`` to verify you are using the
right version of clang (8.0.1).

* (If on other Linux distributions) Please build clang 8.0.1 from scratch:
@@ -106,7 +106,7 @@ Setting up Taichi for development
# remember to use the correct path based on your clang installation
export CC=/usr/bin/clang-8
export CXX=/usr/bin/clang++-8

* You may also have to install some extra packages on Linux, based on the specific errors
you get, you may need to run something like: ``sudo apt install libxcursor-dev libxinerama-dev libxrandr-dev``.

28 changes: 20 additions & 8 deletions python/taichi/main.py
Original file line number Diff line number Diff line change
@@ -77,13 +77,19 @@ def run_example(name: str):
import taichi as ti
from pathlib import Path

root_dir = ti.package_root() if ti.is_release() else ti.get_repo_directory()
root_dir = ti.package_root() if ti.is_release() else ti.get_repo_directory(
)
examples_dir = Path(root_dir) / 'examples'
all_examples = examples_dir.rglob('*.py')
all_example_names = {str(f.resolve()).split("/")[-1].split(".")[0] for f in all_examples}
all_example_names = {
str(f.resolve()).split("/")[-1].split(".")[0]
for f in all_examples
}

if not name in all_example_names:
sys.exit(f"Sorry, {name} is not an available example name!\nAvailable examples names: {all_example_names}")
sys.exit(
f"Sorry, {name} is not an available example name!\nAvailable examples names: {all_example_names}"
)
os.system(f"python3 {examples_dir / f'{name}.py'}")


@@ -101,8 +107,10 @@ def display_benchmark_regression(xd, yd, args):
def parse_dat(file):
dict = {}
for line in open(file).readlines():
try: a, b = line.strip().split(':')
except: continue
try:
a, b = line.strip().split(':')
except:
continue
dict[a.strip()] = int(float(b))
return dict

@@ -127,7 +135,8 @@ def plot_in_gui(scatter):
gui = ti.GUI('Regression Test', (640, 480), 0x001122)
print('[Hint] press SPACE to go for next display')
for key, data in scatter.items():
data = np.array([((i + 0.5)/len(data), x/2) for i, x in enumerate(data)])
data = np.array([((i + 0.5) / len(data), x / 2)
for i, x in enumerate(data)])
while not gui.get_event((ti.GUI.PRESS, ti.GUI.SPACE)):
gui.core.title = key
gui.line((0, 0.5), (1, 0.5), 1.8, 0x66ccff)
@@ -176,7 +185,9 @@ def make_argument_parser():
'--verbose',
action='store_true',
help='Run with verbose outputs')
parser.add_argument('-r', '--rerun', help='Rerun failed tests for given times')
parser.add_argument('-r',
'--rerun',
help='Rerun failed tests for given times')
parser.add_argument('-t',
'--threads',
help='Number of threads for parallel testing')
@@ -257,7 +268,8 @@ def main(debug=False):
" ti doc |-> Build documentation\n"
" ti release |-> Make source code release\n"
" ti debug [script.py] |-> Debug script\n"
" ti example [name] |-> Run an example by name\n")
" ti example [name] |-> Run an example by name\n"
)
return 0

t = time.time()