Code Monkey home page Code Monkey logo

geo-model-builder's Introduction

GeoModelBuilder

The Geometry Model Builder (GMB) is a tool for generating olympiad-level geometry diagrams. The GMB takes Geometry Model-Building Language programs as input. For an overview of the GMBL, please refer to our arXiv paper (or the slightly shorter version published in the CADE 28 proceedings) or run this program as a local web server and read the tutorial.

Example: Example

Quick Start

The GMB can be run either as a locally-hosted web server or a command line tool.

Web Server

Requred once: cd geo-model-builder && pip3 install -r requirements.txt

Required for each terminal session: cd src/ && FLASK_APP=server.py

To run server: flask run

Command Line Tool

cd geo-model-builder/src && python3 builder_cli.py --problem INPUT_FILE

Parameters

The command line version accepts the following parameteters...

  • problem: Input GMBL file (required)
  • n_models: The number of diagrams to generate for the GMBL file (maximum of 10).
  • n_tries: The maximum number of tries to generate n_models. For example, if n_models = 2 and n_tries = 2 but GMB fails once, only 1 diagram will be returned.
  • n_inits: The number of initializations to sample
  • min_dist: The minimum distance between points
  • plot_freq: The frequency (in number of steps) of plotting the current model during optimization
  • losses_freq: The frequency (in number of steps) of printing a summary of loss values
  • loss_freq: The frequency (in number of steps) of printing the cumulative loss value
  • verbosity: A coarser-grained control of plotting and loss printing

...as well as the following parameters for Tensorflow optimization:

  • learning_rate: Initial learning rate
  • decay_rate: Decay rate
  • eps: Epsilon value for stopping criteria
  • n_iterations: Maximum number of iterations for gradient descent

geo-model-builder's People

Contributors

mirefek avatar rkruegs123 avatar

Stargazers

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

Watchers

 avatar  avatar

geo-model-builder's Issues

error when there's multiple polygons

Hi thanks for the very useful tool and general language!

I was trying for examples like the following that includes multiple polygons.

['( param ( A B C D ) polygon )', '( assert ( cong A B B C ) )', '( assert ( cong B
 C C D ) )', '( assert ( cong C D D A ) )', '( assert ( cong A C B D ) )', '( asser
t ( perp ( line A B ) ( line B C ) ) )', '( assert ( perp ( line A D ) ( line D C )
 ) )', '( assert ( perp ( line A C ) ( line B D ) ) )', '( assert ( para ( line A D
 ) ( line B C ) ) )', '( assert ( para ( line A B ) ( line C D ) ) )', '( param ( E
 F G H ) polygon )', '( assert ( cong H F E G ) )']   

And I got errors assuming the polygons are the same when they are in fact not:

INPUT INSTRUCTIONS:                                                                
sample (A B C D) polygon ()                                                        
assert (cong A B B C)                                                              
assert (cong B C C D)                                                              
assert (cong C D D A)                                                              
assert (cong A C B D)                                                              
assert (perp (connecting A B) (connecting B C))                                    
assert (perp (connecting A D) (connecting D C))                                    
assert (perp (connecting A C) (connecting B D))                                    
assert (para (connecting A D) (connecting B C))                                    
assert (para (connecting A B) (connecting C D))                                    
sample (E F G H) polygon ()                                                        
assert (cong H F E G)                                                              
Processing instructions...:  83%|███████████████   | 10/12 [00:00<00:00, 26.06it/s]

the most relevant traceback:

tf_prefix=outp, encode_fig=encode_fig, plot_path=az_path2img)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/shengli/code/shengli/geo-model-builder/src/gbml_verifier.py", line 7
9, in build_aux
    solver.preprocess()
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 72, i
n preprocess
    self.process_instruction(i)
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 83, i
n process_instruction
    self.sample(i)
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 373, 
in sample
    elif s_method == "polygon": self.sample_polygon(i.points)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 390, 
in sample_polygon
    angle_zs = [self.mkvar(name=f"polygon_angle_zs_{i}", lo=-2.0, hi=2.0) for i in 
range(len(ps))]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 390, 
in <listcomp>
    angle_zs = [self.mkvar(name=f"polygon_angle_zs_{i}", lo=-2.0, hi=2.0) for i in 
range(len(ps))]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/shengli/code/shengli/geo-model-builder/src/tf_optimizer.py", line 48
, in mkvar
    return tf.compat.v1.get_variable(name=name, shape=shape, dtype=tf.float64, init
ializer=init, trainable=trainable)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/shengli/.pyenv/versions/3.11.5/lib/python3.11/site-packages/tensorfl
ow/python/ops/variable_scope.py", line 1617, in get_variable
    return get_variable_scope().get_variable(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/shengli/.pyenv/versions/3.11.5/lib/python3.11/site-packages/tensorfl
ow/python/ops/variable_scope.py", line 1327, in get_variable
    return var_store.get_variable(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/shengli/.pyenv/versions/3.11.5/lib/python3.11/site-packages/tensorfl
ow/python/ops/variable_scope.py", line 583, in get_variable
    return _true_getter(
           ^^^^^^^^^^^^^
  File "/Users/shengli/.pyenv/versions/3.11.5/lib/python3.11/site-packages/tensorfl
ow/python/ops/variable_scope.py", line 536, in _true_getter
    return self._get_single_variable(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/shengli/.pyenv/versions/3.11.5/lib/python3.11/site-packages/tensorfl
ow/python/ops/variable_scope.py", line 899, in _get_single_variable
    raise ValueError("%s Originally defined at:\n\n%s" %
ValueError: Variable polygon_angle_zs_0 already exists, disallowed. Did you mean to
 set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

  File "/Users/shengli/code/shengli/geo-model-builder/src/tf_optimizer.py", line 48
, in mkvar
    return tf.compat.v1.get_variable(name=name, shape=shape, dtype=tf.float64, init
ializer=init, trainable=trainable)
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 390, 
in <listcomp>
    angle_zs = [self.mkvar(name=f"polygon_angle_zs_{i}", lo=-2.0, hi=2.0) for i in 
range(len(ps))]
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 390, 
in sample_polygon
    angle_zs = [self.mkvar(name=f"polygon_angle_zs_{i}", lo=-2.0, hi=2.0) for i in 
range(len(ps))]
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 373, 
in sample
    elif s_method == "polygon": self.sample_polygon(i.points)
  File "/Users/shengli/code/shengli/geo-model-builder/src/optimizer.py", line 83, i
n process_instruction
    self.sample(i)

does anyone know how to resolve this issue?
thanks a bunch!

I am getting a diagram that does not fit the description

I had a go at your tool and wanted to draw the diagram corresponding to the following problem:

(param A point)
(param B point)
(param C point)
(param D point)
(assert (= (uangle A B D) (uangle C B D)))
(assert (perp (line A D) (line A B)))
(assert (perp (line C D) (line B C)))
(eval (cong A D C D))

I am asserting that angles ABD and CBD are congruent; yet in the diagram I get, they are not.

The following shows the problem in question and how the diagram should look like, in addition to the diagram generated by your tool. Any thoughts?

2022-08-25 15_26_33

The following is the log in the terminal:

INPUT INSTRUCTIONS:
parameterize A coords
parameterize B coords
parameterize C coords
parameterize D coords
assert (eq-n (uangle A B D) (uangle C B D))
assert (perp (connecting A D) (connecting A B))
assert (perp (connecting C D) (connecting B C))
eval (cong A D C D)
Processing instructions...: 100%|█████████████████| 8/8 [00:00<00:00, 17.83it/s]
Sampling initializations...: 100%|██████████████| 10/10 [00:03<00:00,  2.59it/s]
[     0]   0.534536110252 ||   0.100000
======== Print losses ==========
-- Losses --
  eq-n_(uangle A B D)_(uangle C B D)                 0.4126300652
  perp_(connecting A D)_(connecting A B)             0.1212556369
  perp_(connecting C D)_(connecting B C)             0.0005037448
  points                                             0.0000001994
  distinct                                           0.0001464638
-- Goals --
  cong_A_D_C_D                                       0.2331401778
-- NDGs --
================================

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.