Code Monkey home page Code Monkey logo

rlc's Introduction

RLC

Try it!

At the moment we provide binaries only for linux x64 and windows x64.

# file.rl

act play() -> Game:
    frm score = 0.0
    act win(Bool do_it)
    if do_it:
        score = 1.0
pip install rl_language
rlc-fix-ray
rlc-learn file.rl -o net # ctrl+c to interrupt after a while
rlc-probs file.rl net

It will to learn pass true to win to maximize score, as reported by the second command.

---------- 0 : p0 ------------
{resume_index: 1, score: 0.000000}
--------- probs --------------
0: win {do_it: true}  98.9385 %
1: win {do_it: false}  1.0615 %
------------------------------
{resume_index: -1, score: 1.000000}

Read a tutorial explaining how to play black jack here Language reference and stdlib documentation here.

RLC Logo

ReLiC, the rlc dragon

RL and RLC

The RuleBook Compiler (RLC) is an MLIR-based compiler for a domain-specific language aimed at simplifying the complexity of developing multiagent simulations at all stages of development.

The elevator pitch description of the RL is:

A language that turns a easy-to-write procedural description of a simulation into a easy-to-use and easy-to-reuse efficient library.

Read the project rationale here Read the language rationale here Read how we analyzed a off the shelf game here Read a tutorial explaining how to play black jack here

At the moment RLC is a proof of concept, and is released to gather feedback on the features of the language. Until version 1.0 syntax and semantics may change at any point.

Before version 1.0 we want for users to be able to produce:

  • a compiled library implementing such simulation (DONE)
  • a serialization and deserialization mechanism both in textual and binary format (DONE)
  • a fuzzer able to find bugs in the simulation (DONE)
  • machine learning algorithms able to analyze the simulation. (development started)
  • a simple network protocol able to run the simulation remotely (not yet started)

Example: tic tac toe


# declares the equivalent of a struct called Board.
# It contains the tic tac toe slots and the current player turn
# Methods omitted for brevity
cls Board:
	Int[9] slots
	Bool playerTurn

act play() -> TicTacToe:
	# allocates and initializes a board of type Board
	let board : Board
	while !full(board):

		# declares a suspension point of the simulation,
		# an action called mark that requires two ints to be performed.
		act mark(Int x, Int y) {
		# declares contraints about which inputs are valid
			x < 3,
			x >= 0,
			y < 3,
			y >= 0,
			board.get(x, y) == 0
		}

		# marks the board at the position provided
		board.set(x, y)

		# if the current player has three marks in a line
		# return
		if board.three_in_a_line():
			return

		board.change_current_player()


fun main() -> Int:
	# creates a new game
	let game = play()
	game.mark(0, 0)
	# X _ _
	# _ _ _
	# _ _ _
	game.mark(1, 0)
	# X O _
	# _ _ _
	# _ _ _
	game.mark(1, 1)
	# X O _
	# _ X _
	# _ _ _
	game.mark(2, 0)
	# X O O
	# _ X _
	# _ _ _
	game.mark(2, 2)
	# X O O
	# _ X _
	# _ _ X

	# returns 1 because player 1 indeed
	# had three marks in a line
	return int(game.board.three_in_a_line())

Dependencies

Base:

  • cpp17 compiler
  • python
  • CMake

Extra dependecies used by the setup script:

  • Bash
  • Ninja
  • virtualenv
  • lld

License

We wish for RLC to be usable by all as a compiler, for both commercial and non-commercial purposes, so it is released under apache license.

Installation for developers

We provide a setup script that downloads the rlc repository and a setup script that will download and compile LLVM as well as RLC. As long as the dependencies written before are met you should just be able to run the following commands and everything should work. Installing and building llvm debug will take ~100 gigabytes of hard drive space and will require a large amount of time and RAM. This is only required when building from sources, pypi packages are much less than 1gb on each operating system.

Hard drive space can be reclaimed by deleting LLVM build directory after it has been fully built.

Download the setup.sh file in the root of the repository and then run:

chmod +x setup.sh
source ./setup.sh # clones RLC repo and initialize virtualenvs and submodules
python rlc/build.py # clones LLVM, builds it and builds RLC

on mac and windows replace the last line with

python rlc/build.py --no-use-lld

If that script terminates successfully, you are fully set up to start working on RLC.

What do if run out of space or memory

Instead of the previous command python, you can run. This will only build the release LLVM version and save a great deal of space.

python rlc/build.py --no-debug-llvm

Using a custom LLVM

python rlc/build.py --llvm-dir <PATH-TO-LLVM-INSTALL> [--rlc-shared]

You need to use the flag --rlc-shared if you have built a shared LLVM.

environment.sh

If you are using the default installation script (setup.sh) we provide a .sh file that configures your environment variable so that you can use python and rlc without installing anything in your actual machine. When you open a shell to start working on RLC run the following command.

If you use some editor such as code or clion, start it from that shell.

source environment.sh

To check if everything works correctly run the following command.

python python/solve.py ./tool/rlc/test/tic_tac_toe.rl

If it does not crashes, then you are good to go.

If you use some whacky shell of your own or you did not followed the default setup, you are on your own.

Contacts

Discord Twitter Youtube

How to contribute for developers

  • fork this project.
  • push your branches to your fork
  • open a pull request for the branch relevant to your project

The intent of this workflow is so that reviewrs can use the review feature of github pull requests to have persistent comment threads.

Roadmap

machine learning

  • improve ray performances
  • figure out how to not duplicate the state at every action and thus allow true self play [Blocked by rai]

language

  • better debug support
  • inline initializers

standard lib

  • dictionary library

rlc's People

Contributors

cemcebeci avatar david-j-b avatar drblallo avatar eltociear avatar franos-cm avatar mantixpolimi avatar massimofioravanti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rlc's Issues

Unexpected behavior with multiple `ctx` arguments of type Entity.

Trying to compile the following file

ent EntOne:
    Int field_one

ent EntTwo:
    Int field_two

act play(ctx EntOne one, ctx EntTwo two) -> Play:
    act subact() {0 < one.field_one}

fun main() -> Int:
    return 0

I receive the error

test.rl:8:26: error: no known member field_one in struct EntTwo
    act subact() {0 < one.field_one}
                         ^

I believe this only happens when both of the arguments are marked ctx and only in the ActionStatement precondition.

Potential memory leak with `Vector` members of entities

Running the fuzzer emitted for the following action:

import fuzzer.cpp_functions
import fuzzer.utils
import collections.vector

ent Entity:
    Vector<Int> member

fun has_loop():
    let i = 0
    while i < 10:
        let e : Entity
        i = i + 1

act play() -> Play:
    has_loop()
    act subact()

Finds a memory leak, with the message

Direct leak of 320 byte(s) in 10 object(s) allocated from:
    #0 0x4fb52f in malloc /home/ccebeci/rlc/rlc-infrastructure/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0x53bc8a in rl_m_init__VectorTint64_tT_r_void (/home/ccebeci/rlc/rlc-infrastructure/rlc-debug/leaktest+0x53bc8a)
    #2 0x53b301 in rl_m_init__Entity (/home/ccebeci/rlc/rlc-infrastructure/rlc-debug/leaktest+0x53b301)
    #3 0x53c3d4 in rl_m__play_impl__Play_Play_shadow memory_leak.rl
    #4 0x53bfc8 in rl_fuzzer_fuzz_action_function_ (/home/ccebeci/rlc/rlc-infrastructure/rlc-debug/leaktest+0x53bfc8)
    #5 0x7f2af555446b in LLVMFuzzerTestOneInput /home/ccebeci/rlc/rlc-infrastructure/rlc/lib/fuzzer/src/fuzz_target.cpp:99:5
    #6 0x449513 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /home/ccebeci/rlc/rlc-infrastructure/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:614:13
    #7 0x44a800 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::vector<fuzzer::SizedFile, std::allocator<fuzzer::SizedFile>>&) /home/ccebeci/rlc/rlc-infrastructure/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:807:3
    #8 0x44aed2 in fuzzer::Fuzzer::Loop(std::vector<fuzzer::SizedFile, std::allocator<fuzzer::SizedFile>>&) /home/ccebeci/rlc/rlc-infrastructure/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:867:3
    #9 0x438e86 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /home/ccebeci/rlc/rlc-infrastructure/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:914:6
    #10 0x462ff2 in main /home/ccebeci/rlc/rlc-infrastructure/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
    #11 0x7f2af531dd8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: c289da5071a3399de893d2af81d6a30c62646e1e)

Memory leak on actions with `Vector` members

Actions with vector members seem to cause memory leaks.
Here is a minimal failing test

# RUN: rlc %s -o %t -i %stdlib --sanitize -g
# RUN: %t

import collections.vector

act has_member() -> HM:
    frm member: Vector<Int>  

fun main() -> Int:
    let hm = has_member()
    return 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.