Tekoa: A Domain-Specific Language for Defining Opus Variables The variable concept in Opus Problems with defining Opus variables in Python Tekoa examples.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Object-Oriented Programming
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
Evaluating the future: forecasting urban development using the urbansim land use model in el paso, tx. Quinn P. Korbulic.
Reasons to study concepts of PL
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
COMP205 Comparative Programming Languages Part 1: Introduction to programming languages Lecture 3: Managing and reducing complexity, program processing.
Environments and Evaluation
Object-oriented Programming Concepts
Lec 15 LU, Part 1: Basics and simple LU models (ch6.1 & 2 (A), ch (C1) Get a general idea of urban planning theories (from rading p (A)
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Software Process and Product Metrics
Data Structures and Programming.  John Edgar2.
Computer Science 101 Introduction to Programming.
1 CSC 221: Computer Programming I Fall 2004 course overview  what did we set out to learn?  what did you actually learn?  where do you go from here?
A First Program Using C#
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
Computer Science 101 Introduction to Programming.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
CountryData Technologies for Data Exchange SDMX Information Model: An Introduction.
Assessing Quality for Integration Based Data M. Denk, W. Grossmann Institute for Scientific Computing.
Objectives - 11  We will work with processing Arrays.  Objectives:  Describe the concept of an array and its benefits.  Define the terms index, traverse,
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Cohesion and Coupling CS 4311
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
UrbanSim: Informing Public Deliberation about Land Use and Transportation Decisions using Urban Simulations Alan Borning Dept of Computer Science & Engineering.
Evaluating Transportation Impacts of Forecast Demographic Scenarios Using Population Synthesis and Data Simulation Joshua Auld Kouros Mohammadian Taha.
CS 153: Concepts of Compiler Design August 26 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Evaluating Python as an Introductory Programming Language A. Thomas and H.L. Liang UNISA.
Computer Systems & Architecture Lesson 4 8. Reconstructing Software Architectures.
Graphene So what’s the most efficient way to spam all your Facebook friends? Team Adith Tekur (System Architect/Tester) Neha Rastogi (System Integrator)
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Class Diagrams. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are for visualizing, specifying and documenting.
Chapter 1 Introduction Major Data Structures in Compiler
OPERATING SYSTEMS CS 3530 Summer 2014 Systems and Models Chapter 03.
00/XXXX 1 Data Processing in PRISM Introduction. COCO (CDMS Overloaded for CF Objects) What is it. Why is COCO written in Python. Implementation Data Operations.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Exploring Microsimulation Methodologies for the Estimation of Household Attributes Dimitris Ballas, Graham Clarke, and Ian Turton School of Geography University.
Residential Patterns In MEDC’s IB SL. Location Clear pattern of residential location. Highest residential cities are associated with inner-city areas.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Copyright © Curt Hill Other Trees Applications of the Tree Structure.
Chapter – 8 Software Tools.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
PYTHON FOR HIGH PERFORMANCE COMPUTING. OUTLINE  Compiling for performance  Native ways for performance  Generator  Examples.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
OPERATING SYSTEMS CS 3502 Fall 2017
Roberta Roth, Alan Dennis, and Barbara Haley Wixom
A Simple Syntax-Directed Translator
CS 153: Concepts of Compiler Design August 29 Class Meeting
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Chapter 12 User Interface Design
CMPE 152: Compiler Design August 23 Class Meeting
Review CSE116 2/21/2019 B.Ramamurthy.
Residential Patterns In MEDC’s
CMPE 152: Compiler Design January 29 Class Meeting
Introduction to Computer Science
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Functions, Procedures, and Abstraction
UML  UML stands for Unified Modeling Language. It is a standard which is mainly used for creating object- oriented, meaningful documentation models for.
CMPE 152: Compiler Design August 27 Class Meeting
Presentation transcript:

Tekoa: A Domain-Specific Language for Defining Opus Variables The variable concept in Opus Problems with defining Opus variables in Python Tekoa examples Syntax Status and Plans for Further Work User discussion & wish list

The Variable Concept in Opus A model variable (or just variable) is an attribute of actors or geographies used in a model. Variables are properties of datasets, e.g. a gridcell dataset or a parcel dataset Examples: –Population density –Land cost –Travel time to city center Two kinds: –Primary attribute –Derived attribute Not the same as “variable” as used in programming languages

Implementing Variables Opus implements a model variable as a subclass of the Python class Variable Uses lazy evaluation Methods –dependencies() –compute() This has worked very well from the point of view of accessing and computing variables However, defining a new variable (even a simple one) requires writing a new Python class, ideally including a unit test

Variables in Python vs. Tekoa % definition of zone.average_income in Python from opus_core.variables.variable import Variable class average_income(Variable): def dependencies(self): return ["household.income", "zone.zone_id”, "urbansim_parcel.household.zone_id”] def compute(self, dataset_pool): households = dataset_pool.get_dataset("household”) return self.get_dataset().aggregate_dataset_over_ids( households, "mean", "income") % *** code for unit tests omitted *** ______________________________________________ % Tekoa definition average_income = zone.aggregate(household.income, function=mean)

Tekoa - Aggregation through multiple geographies % employment in the ‘large_area’ geography employment=large_area.aggregate (urbansim_parcel.building.number_of_jobs, intermediates=[parcel, zone, faz]) Explanation: number_of_jobs is an attribute of building. We then aggregate this up to the parcel level, then the zone level, then the faz level, and finally the large_area level, to find the employment in the large_area. The ‘employment=’ part gives an alias for the expression, so that it displays nicely in the resulting indicator.

Tekoa - More Complex Example % definition of parcel.is_pre_1940 % is the average building age for a parcel % older than 1940? is_pre_1940 = parcel.aggregate (building.year_built * numpy.ma.masked_where( urbansim_parcel.building.has_valid_year_built==0, 1), function=mean) < 1940

Syntax Syntax is a subset of Python An expression can be: –The name of a variable –A function or operator applied to other expressions All of the numpy functions and operators are available, e.g. exp, sqrt, +, -, ==, < numpy-style array and matrix operations — for example, 1.2*household.income scales all the elements of the array of incomes Aggregation –Intermediates argument -- list of intermediate datasets –Function - can be sum, mean, median, min, max Disaggregation also supported

Interaction Sets and Expressions InteractionDataset is a subclass of Dataset, which stores its data as a 2-d array For example, for household location choice we are interested in the interaction between household income and cost per residential unit The expression ln(household.income) * zone.average_housing_cost) returns an n  m array where n is the number of households and m is the number of zones

Implementation When a new Tekoa expression is encountered, the system: –parses it (using the Python parser) –analyzes the expression for dependencies on other variables and special methods (e.g. aggregate, disaggregate) –compiles a new Python class that defines the variable, including a dependencies() and a compute() method –Recursively compiles a new variable when aggregating/disaggretating an expression Consequence: efficiency of expressions is the same as for the old-style definitions The system maintains a cache of expressions that have already been compiled, so that if the same expression is encountered again the previously-compiled class is just returned

More Examples and Documentation For lots of examples, see the aliases.py for various datasets in the urbansim_parcel package, e.g. –urbansim_parcel/buildings/aliases.py –urbansim_parcel/job/aliases.py –… The language is described in Section 6.4 of the Opus/Urbansim User Manual Also see: Alan Borning, Hana Sevcikova, and Paul Waddell, “A Domain-Specific Language for Urban Simulation Variables”, to appear, International Conference on Digital Government Research, Montreal, Canada, May 2008.

Tekoa Status and Future Work Benefits: –significantly reduced code size (factor of 7 for urbansim gridcell vs urbansim parcel) –increased modeler productivity Additional features to implement: –Parameterized expressions. For example is_pre_1940 should really be is_pre(1940) –Better error detection and messages –Tutorial & advanced techniques Replace old variable definitions in the code base for gridcell model system with expressions (big job) Integration of expressions with GUI User discussion & wish list?