Repository: joergen7/cuneiform Branch: master Commit: 183cb5715cd5 Files: 10 Total size: 29.7 KB Directory structure: gitextract_01fqqi0n/ ├── .github/ │ └── workflows/ │ └── ci.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── docker-compose.yml ├── priv/ │ └── cf_script ├── rebar.config └── src/ ├── cuneiform.app.src └── cuneiform.erl ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/ci.yml ================================================ --- name: build on: push: branches: - master pull_request: branches: - master jobs: ci: name: Run checks and tests over ${{matrix.otp}} and ${{matrix.os}} runs-on: ${{matrix.os}} strategy: matrix: otp: ['25.0', '26.0', '27.0'] os: [ubuntu-latest] steps: - uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: otp-version: ${{matrix.otp}} rebar3-version: '3.24.0' - run: rebar3 compile - run: rebar3 xref - run: rebar3 efmt -c - run: rebar3 eunit - run: rebar3 dialyzer - run: rebar3 edoc ================================================ FILE: .gitignore ================================================ .eunit deps *.o *.beam *.plt erl_crash.dump ebin/*.beam rel/example_project .concrete/DEV_MODE .rebar *~ _build rebar.lock rebar3.crashdump doc/* !doc/overview.edoc .DS_Store ================================================ FILE: Dockerfile ================================================ # docker image build -t cfl:latest . # docker container run -it cfl:latest FROM alpine:3.17.2 LABEL maintainer="Jörgen Brandt " ENV BIN_PATH /usr/local/bin WORKDIR /tmp RUN apk add --update git erlang erlang-dev erlang-dialyzer RUN git clone https://github.com/erlang/rebar3.git && (cd rebar3 && ./bootstrap) && cp rebar3/rebar3 $BIN_PATH && rm -rf rebar3 RUN git clone https://github.com/joergen7/cuneiform.git && (cd cuneiform && rebar3 escriptize) && cp cuneiform/_build/default/bin/cfl $BIN_PATH && rm -rf cuneiform RUN git clone https://github.com/joergen7/cre.git && (cd cre && rebar3 escriptize) && cp cre/_build/default/bin/cre $BIN_PATH && rm -rf cre RUN git clone https://github.com/joergen7/cf_client.git && (cd cf_client && rebar3 escriptize) && cp cf_client/_build/default/bin/cfl_client $BIN_PATH && rm -rf cf_client RUN git clone https://github.com/joergen7/cf_worker.git && (cd cf_worker && rebar3 escriptize) && cp cf_worker/_build/default/bin/cfl_wrk $BIN_PATH && rm -rf cf_worker RUN git clone https://github.com/joergen7/effi.git && (cd effi && rebar3 escriptize) && cp effi/_build/default/bin/effi $BIN_PATH && rm -rf effi # foreign languages RUN apk add nodejs octave racket bash elixir gnuplot openjdk17 python3 R R-dev R-doc perl # Wal RUN apk add py3-pip cmake g++ python3-dev && pip install build && git clone https://github.com/ics-jku/wal.git && (cd wal && git checkout 1ffa6a3 && make install) && rm -rf wal RUN echo '$y$j9T$7rB03tCGBZHKyQPR/jata1$UF9ICbyarE/Vs3s2paRKnIA8mP6ayA0mlog/KSSPMvD' > /root/.erlang.cookie && chmod 400 /root/.erlang.cookie CMD ["sh"] ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2013 Jörgen Brandt Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ ![Cuneiform: Data analysis open and general](priv/cuneiform_title.jpg) [![hex.pm](https://img.shields.io/hexpm/v/cuneiform.svg?style=flat-square)](https://hex.pm/packages/cuneiform) Cuneiform is a large-scale data analysis functional programming language. It is *open* because it easily integrates foreign tools and libraries, e.g., Python libraries or command line tools. It is *general* because it has the expressive power of a functional programming language while using the independence of sub-expressions to automatically parallelize programs. Cuneiform uses distributed Erlang to scalably run in cluster and cloud environments. [cuneiform-lang.org](https://www.cuneiform-lang.org/) ## Usage ### Compiling Having rebar3 available on your system, compile the project by entering rebar3 escriptize ### Displaying Cuneiform Help Compiling the Cuneiform client using `rebar3 escriptize` creates an Erlang script file `_build/default/bin/cfl` which allows starting Cuneiform via the command line. To display a help text enter _build/default/bin/cfl --help This will show the command line synopsis, which looks like the following: Usage: cfl [-v] [-h] [-n ] [-w ] [-r ] [-d ] -v, --version Show cf_worker version. -h, --help Show command line options. -n, --n_wrk Number of worker processes to start. 0 means auto-detect available processors. -w, --wrk_dir Working directory in which workers store temporary files. -r, --repo_dir Repository directory for intermediate and output data. -d, --data_dir Data directory where input data is located. This script is self-contained and can be moved around to, e.g., `~/bin/cfl`. From here on we assume that the `cfl` script is accessible in your system path and that we can start it by just entering `cfl` instead of `_build/default/bin/cfl`. #### Starting an Interactive Shell You can start a shell and program Cuneiform interactively by starting it without any command line parameters like so: cfl This will open a shell giving the following initial output, along with a number of status messages: @@WB Cuneiform @@E_____ _g@@@@@WWWWWWL Type help for usage info g@@#*`3@B quit to exit shell @@P 3@B @N____ 3@B http://www.cuneiform-lang.org "W@@@WF3@B Jorgen Brandt 1> Note that starting Cuneiform like that will create a local instance of a Cuneiform that entails the scheduler service, a client service, and as many worker services as CPUs were detected on the host machine. To set up a distributed Cuneiform system, these services need to be started separately on multiple hosts as needed. #### Running a Cuneiform Script Alternatively, Cuneiform can be started by giving it a source file which will only output the final result of the computation. If your Cuneiform script is stored in `my_script.cfl` start it by entering cfl my_script.cfl ## Examples A collection of self-contained Cuneiform examples is available under [joergen7/cuneiform-examples](https://github.com/joergen7/cuneiform-examples). ### Variable assignment You can assign a value to a variable and retrieve a variable's content like so: let x : Str = "foo"; x; In the first line we assign the value `"foo"` to a variable named `x` declaring its type to be `Str`. In the last line we query the variable `x`. ### Booleans and Conditions We can branch execution based on conditions using conditional statements. Conditionals are expressions. let x : Str = if true then "bla" else "blub" end; x; The above command the conditional binding the string `"bla"` to the variable `x`. Then, we query the variable. ### Lists We can construct list literals by enumerating their elements in square brackets and declaring the type of the list elements. let xs : [Bool] = [true, false, true, true : Bool]; xs; Here, we define the list `xs` whose elements are of type `Bool` giving four Boolean values of which only the second is `false`. ### Records and Pattern Matching A record is a collection of fields that can be accessed via their labels. Literal records can be constructed like so: let r : = ; ( r|a ); We define a record `r` with two fields `a` and `b`, of types `Str` and `Bool` respectively. The field associated with `a` gets the value `"blub"` while the field associated with `b` gets the value `false`. In the last line we access the `a` field of the record `r`. Alternatively, we can access record fields via pattern matching: let = r; z; In the first line we associate the variable `z` with the field `a` of record `r`. In the second line we query the content of `z`. ### Native Function Definition Defining native functions in Cuneiform is done by giving the function name, its signature, and a body expression in curly braces: def identity( x : Str ) -> Str { x } identity( x = "bar" ); In the first line we define the function `identity` which consumes an argument `x` of type `Str` and produces a return value of type `Str`. In the second line, the body expression is just the argument `x`. In the last line we call the function binding the argument `x` to the value `"bar"`. ### Foreign Function Definition Defining foreign functions is done by giving the function name, its signature, the foreign language name, and the function body in mickey-mouse-eared curly braces. def greet( person : Str ) -> in Bash *{ out="Hello $person" }* greet( person = "Peter" ); The first line defines a foreign function `greet` taking one argument `person` of type `Str` and returning a tuple with a single field `out` of type `Str`. The foreign function body is given in Bash code. In the last line we call the foreign function, binding the argument `person` to the string value `"Peter"`. ### Iterating over Lists using For To perform an operation on each element of a list, one can iterate using for: let xs : [Bool] = [true, false, true, true : Bool]; for x : Bool <- xs do not x : Bool end; Here, we define a list of four Booleans and negate each element. ### Aggregating Lists using Fold We can aggregate over lists using fold: def add( a : Str, b : Str ) -> in Python *{ c = int( a )+int( b ) }* let xs : [Str] = [1, 2, 3 : Str]; let sum : Str = fold acc : Str = 0, x : Str <- xs do ( add( a = acc, b = x )|c ) end; sum; Here, we first define the function `add` which lets us add two numbers in Python and then the string list `xs` containing the numbers from one to three. We aggregate the sum of the numbers in `xs` and store it the result in the variable `sum`. Lastly, we query the `sum` variable. ## System Requirements - [Erlang](https://www.erlang.org) OTP 19.0 or higher - [Rebar3](https://www.rebar3.org) 3.0.0 or higher ## Resources - [cuneiform-lang.org](https://www.cuneiform-lang.org/). Official website of the Cuneiform programming language. - [joergen7/cuneiform-examples](https://github.com/joergen7/cuneiform-examples). Collection of small, self-contained Cuneiform code examples. - [joergen7/cre](https://github.com/joergen7/cre). A common runtime environment (CRE) for distributed workflow languages. - [joergen7/cf_client](https://github.com/joergen7/cf_client). A Cuneiform client implementation. - [joergen7/cf_worker](https://github.com/joergen7/cf_worker). A Cuneiform worker implementation. ## License [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0.html) ================================================ FILE: docker-compose.yml ================================================ services: cre: build: . command: cre networks: - cuneiform-net hostname: cre_host # the worker connects to cre@[hostname] cfl_wrk: build: . command: cfl_wrk -c cre@cre_host -w /tmp/_cuneiform/wrk -r /opt/_cuneiform/repo -d /opt/_cuneiform/data volumes: - type: volume source: repo-vol target: /opt/_cuneiform/repo - type: volume source: data-vol target: /opt/_cuneiform/data read_only: true networks: - cuneiform-net depends_on: - cre deploy: mode: replicated replicas: 2 # 2 replicas cpus: 4 # each with 4 cores makes 8 worker processes cfl_client: # the cfl_client process starts a Cuneiform shell and then immediately exits build: . command: cfl_client -c cre@cre_host networks: - cuneiform-net depends_on: - cre networks: cuneiform-net: volumes: repo-vol: data-vol: ================================================ FILE: priv/cf_script ================================================ #!/usr/bin/env bash # # cuneiform # # Copyright 2013 Jörgen Brandt # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # ------------------------------------------------------------------- set -eu -o pipefail SCRIPT=`mktemp` cat /dev/stdin > $SCRIPT cuneiform $@ $SCRIPT ================================================ FILE: rebar.config ================================================ {erl_opts, [debug_info]}. {deps, [{cf_client, {git, "https://github.com/joergen7/cf_client.git", {branch, "master"}}}, {cf_worker, {git, "https://github.com/joergen7/cf_worker.git", {branch, "master"}}}, {cre, {git, "https://github.com/joergen7/cre.git", {branch, "master"}}}, {lib_conf, {git, "https://github.com/joergen7/lib_conf.git", {branch, "master"}}}, {getopt, "1.0.3"}]}. {escript_incl_apps, [cf_client, cf_worker, cre, effi, gen_pnet, getopt, jsone, lib_combin, lib_conf]}. {escript_name, "cfl"}. {profiles, [{test, [{cover_enabled, true}]}]}. {dialyzer, [{warnings, [unmatched_returns, error_handling, underspecs]}, {plt_extra_apps, [cf_client, cf_worker, cre, getopt]}]}. {xref_checks, [undefined_function_calls, undefined_functions, locals_not_used, deprecated_function_calls, deprecated_functions]}. {project_plugins, [rebar3_efmt]}. ================================================ FILE: src/cuneiform.app.src ================================================ {application, cuneiform, [{description, "A functional workflow language for large-scale scientific data analysis."}, {vsn, "3.0.6"}, {registered, []}, {applications, [kernel, stdlib]}, {env, []}, {modules, [cuneiform]}, {maintainers, ["Jorgen Brandt"]}, {licenses, ["Apache 2.0"]}, {links, [{"GitHub", "https://github.com/joergen7/cuneiform/"}]}]}. ================================================ FILE: src/cuneiform.erl ================================================ %% -*- erlang -*- %% %% Cuneiform distributed programming language %% %% Copyright 2013 Jörgen Brandt %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. %% You may obtain a copy of the License at %% %% http://www.apache.org/licenses/LICENSE-2.0 %% %% Unless required by applicable law or agreed to in writing, software %% distributed under the License is distributed on an "AS IS" BASIS, %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %% See the License for the specific language governing permissions and %% limitations under the License. %% %% ------------------------------------------------------------------- %% @author Jörgen Brandt %% @version 3.0.6 %% @copyright 2013 %% %% %% %% %% %% @end %% ------------------------------------------------------------------- -module(cuneiform). -export([main/1]). -define(VSN, "3.0.6"). %%==================================================================== %% Escript main function %%==================================================================== main(Args) -> % TODO: neutralize all configurations try case getopt:parse(get_optspec_lst(), Args) of {error, R1} -> throw({error, R1}); {ok, {OptLst, NonOptLst}} -> % break if version needs to be displayed case lists:member(version, OptLst) of false -> ok; true -> throw(version) end, % break if help needs to be displayed case lists:member(help, OptLst) of false -> ok; true -> throw(help) end, % extract number of workers M1 = case lists:keyfind(n_wrk, 1, OptLst) of false -> #{n_wrk => <<"auto">>}; {n_wrk, N} when N > 0 -> #{n_wrk => N}; A -> throw({error, {invalid_arg, A}}) end, % extract working directory M2 = case lists:keyfind(wrk_dir, 1, OptLst) of false -> M1#{wrk_dir => <<"./_cuneiform/wrk">>}; {wrk_dir, W} -> M1#{wrk_dir => W} end, % extract repository directory M3 = case lists:keyfind(repo_dir, 1, OptLst) of false -> M2#{repo_dir => <<"./_cuneiform/repo">>}; {repo_dir, R} -> M2#{repo_dir => R} end, % extract data directory M4 = case lists:keyfind(data_dir, 1, OptLst) of false -> M3#{data_dir => <<".">>}; {data_dir, D} -> M3#{data_dir => D} end, % set flag maps ok = application:set_env(cf_client, flag_map, #{cre_node => <<"node">>}), ok = application:set_env(cf_worker, flag_map, M4#{cre_node => <<"node">>}), % start CRE application ok = cre:start(), % start worker application ok = cf_worker:start(), % start client application ok = cf_client:start(), case NonOptLst of [] -> throw(shell); [_ | _] -> throw({load, NonOptLst}) end end catch throw:version -> print_version(); throw:help -> print_help(); throw:shell -> print_version(), ok = cuneiform_shell:shell(cf_client); throw:{load, FileLst} -> F = fun(File) -> % collect reply list ReplyLst = case file:read_file(File) of {error, R3} -> io:format("we land here~n"), [{error, load, {File, R3}}]; {ok, B} -> S = binary_to_list(B), cuneiform_shell:shell_eval_oneshot(S) end, cuneiform_shell:process_reply_lst(ReplyLst, cf_client, silent) end, ok = lists:foreach(F, FileLst); throw:{error, Reason} -> ReplyLst = [{error, load, Reason}], cuneiform_shell:process_reply_lst(ReplyLst, cf_client, silent) end. %%==================================================================== %% Internal functions %%==================================================================== get_optspec_lst() -> [{version, $v, "version", undefined, "Show cf_worker version."}, {help, $h, "help", undefined, "Show command line options."}, {n_wrk, $n, "n_wrk", integer, "Number of worker processes to start. 0 means auto-detect available processors."}, {wrk_dir, $w, "wrk_dir", binary, "Working directory in which workers store temporary files."}, {repo_dir, $r, "repo_dir", binary, "Repository directory for intermediate and output data."}, {data_dir, $d, "data_dir", binary, "Data directory where input data is located."}]. print_help() -> getopt:usage(get_optspec_lst(), "cfl"). print_version() -> io:format("cuneiform ~s~n", [?VSN]).