diff --git a/.gitignore b/.gitignore index e25ca00..93f9edb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,15 @@ +.idea .ipynb_checkpoints .DS_Store -.idea -notebooks/.ipynb_checkpoints -notebooks/multithreading.ipynb -SimCAD.egg-info __pycache__ Pipfile Pipfile.lock results -.mypy_cache \ No newline at end of file +.mypy_cache +*.csv +*.txt +simulations/.ipynb_checkpoints +dist/SimCAD-0.1.tar.gz + +build +SimCAD.egg-info \ No newline at end of file diff --git a/README.md b/README.md index 62bbf08..86ce782 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,50 @@ # SimCad **Warning**: -**Do not** publish this package / software to **any** software repository **except** one permited by BlockScience. +**Do not** publish this package / software to **any** software repository **except** one permitted by BlockScience. + +**Description:** + +SimCAD is a differential games based simulation software package for research, validation, and Computer \ +Aided Design of economic systems. An economic system is treated as a state based model and defined through a \ +set of endogenous and exogenous state variables which are updated through mechanisms and environmental \ +processes, respectively. Behavioral models, which may be deterministic or stochastic, provide the evolution of \ +the system within the action space of the mechanisms. Mathematical formulations of these economic games \ +treat agent utility as derived from state rather than direct from action, creating a rich dynamic modeling framework. + +Simulations may be run with a range of initial conditions and parameters for states, behaviors, mechanisms, \ +and environmental processes to understand and visualize network behavior under various conditions. Support for \ +A/B testing policies, monte carlo analysis and other common numerical methods is provided. **1. Install Dependencies:** ```bash pip install -r requirements.txt -pip install . +python3 setup.py sdist bdist_wheel ``` **2. Configure Simulation:** -Example: +Intructions: +`/Simulation.md` + +Examples: `/simulations/validation/*` **3. Import SimCAD & Run Simulation:** -Example: -`/simulations/sim_test.py` +Examples: `/simulations/sim_test.py` or `/simulations/test.ipynb` +`/simulations/sim_test.py`: ```python import pandas as pd from tabulate import tabulate -# The following imports NEED to be in the exact same order +# The following imports NEED to be in the exact order from SimCAD.engine import ExecutionMode, ExecutionContext, Executor -from simulations.validation import config_1, config_2 +from validation import config1, config2 from SimCAD import configs -# ToDo: pass ExecutionContext with execution method as ExecutionContext input - exec_mode = ExecutionMode() - print("Simulation Execution 1") print() first_config = [configs[0]] # from config1 @@ -39,7 +52,6 @@ single_proc_ctx = ExecutionContext(context=exec_mode.single_proc) run1 = Executor(exec_context=single_proc_ctx, configs=first_config) run1_raw_result, tensor_field = run1.main() result = pd.DataFrame(run1_raw_result) -# result.to_csv('~/Projects/DiffyQ-SimCAD/results/config4.csv', sep=',') print() print("Tensor Field:") print(tabulate(tensor_field, headers='keys', tablefmt='psql')) @@ -64,4 +76,4 @@ for raw_result, tensor_field in run2.main(): The above can be run in Jupyter. ```bash jupyter notebook -``` \ No newline at end of file +``` diff --git a/SimCAD/__init__.py b/SimCAD/__init__.py index 3f660d7..0b7fa28 100644 --- a/SimCAD/__init__.py +++ b/SimCAD/__init__.py @@ -1,2 +1,2 @@ +name = "SimCAD" configs = [] -# diff --git a/SimCAD/configuration/utils/__init__.py b/SimCAD/configuration/utils/__init__.py index 62c339a..53dad43 100644 --- a/SimCAD/configuration/utils/__init__.py +++ b/SimCAD/configuration/utils/__init__.py @@ -54,4 +54,4 @@ def exo_update_per_ts(ep): return f(step, sL, s, _input) else: return (y, s[y]) - return {es: ep_decorator(f, es) for es, f in ep.items()} \ No newline at end of file + return {es: ep_decorator(f, es) for es, f in ep.items()} diff --git a/SimCAD/engine/__init__.py b/SimCAD/engine/__init__.py index ba418f3..66a0773 100644 --- a/SimCAD/engine/__init__.py +++ b/SimCAD/engine/__init__.py @@ -43,7 +43,6 @@ class Executor: self.main = self.execute def execute(self): - config_proc = Processor() create_tensor_field = TensorFieldReport(config_proc).create_tensor_field @@ -73,4 +72,5 @@ class Executor: results = [] for result, mechanism, ep in list(zip(simulations, mechanisms, eps)): results.append((flatten(result), create_tensor_field(mechanism, ep))) + return results diff --git a/SimCAD/utils/__init__.py b/SimCAD/utils/__init__.py index 63d88c6..720ab6a 100644 --- a/SimCAD/utils/__init__.py +++ b/SimCAD/utils/__init__.py @@ -17,4 +17,4 @@ def key_filter(l, keyname): def rename(new_name, f): f.__name__ = new_name - return f \ No newline at end of file + return f diff --git a/dist/SimCAD-0.1-py3-none-any.whl b/dist/SimCAD-0.1-py3-none-any.whl new file mode 100644 index 0000000..10b79b5 Binary files /dev/null and b/dist/SimCAD-0.1-py3-none-any.whl differ diff --git a/licenses/AGREEMENT.txt b/licenses/AGREEMENT.txt new file mode 100644 index 0000000..b5d9242 --- /dev/null +++ b/licenses/AGREEMENT.txt @@ -0,0 +1,150 @@ +SOFTWARE LICENSE AGREEMENT + +This Software License Agreement (the “Agreement”) is entered into as of December __ 2018, (the “Effective Date”) between +Dapper Labs, Inc., a Canadian corporation having its principal place of business at 980-350 Howe Street, +Vancouver, BC V6Z 1N9 (“DLI”) and BlockScience, Inc., a California corporation with an address at 471 McAuley Street, +Oakland, CA 94609 (“BlockScience”). This Agreement includes the attached Exhibit A. + +WHEREAS, DLI and BlockScience are parties to that certain Professional Services Agreement dated March 23, 2018 (the +“PSA”), pursuant to which BlockScience performed and is currently performing professional services and other development +work for DLI; + +WHEREAS, as part of BlockScience’s performance under the PSA, BlockScience developed certain “behaviour archetypes” and +“configuration of the Null Model”, which the parties agree are “Work Product” under the PSA; + +WHEREAS, the parties agree that BlockScience’s proprietary SimCAD software tool is considered “Contractor Technology” +under the PSA; and + +WHEREAS, the parties wish to enter into this Agreement to clarify DLI’s rights to use the SimCAD software tool on a +going-forward basis. + +NOW, THEREFORE, for good and valuable consideration, the receipt and sufficiency of which is hereby acknowledged, DLI +and BlockScience agree as follows: + +1. DEFINITIONS + +(a) “Affiliate” means any entity that, directly or indirectly through one or more intermediaries, controls, is +controlled by, or is under common control with, DLI. + +(b) “Documentation” means any manuals, documentation and other supporting materials related to the Software. +Documentation is considered part of the related Software. + +(c) “Intellectual Property Rights” means patent rights (including patent applications and disclosures), copyrights, +trade marks, trade secrets, know-how and any other intellectual property rights recognized in any country or +jurisdiction in the world. + +(d) “Software” means the object and source code versions of BlockScience’s proprietary SimCAD software product more +fully described in Exhibit A. Software includes the applicable Documentation, as well as any Updates. + +(e) “Update” means any bug fix, error correction, patch, modification, enhancement, update, upgrade, replacement, +successor product, new version, new release, or derivative work of or to the Software. + +(f) “Zeus” means the decentralized synchronous computational network developed by DLI, as such name or reference may be +changed from time to time at DLI’s sole discretion. + +2. SOFTWARE LICENSE + +(a) License Grant. BlockScience hereby grants to DLI and its Affiliates a worldwide, non-exclusive, royalty-free, +irrevocable, perpetual license to (i) download, install, use, execute, access, copy, perform, and modify, the Software +in connection with the Zeus project; (ii) distribute and display the Software internally amongst DLI and its Affiliates, +its and their employees, contractors, and agents, subject to the use of reasonable efforts to maintain the confidential +status of the non-public aspects of the Software display; and (iii) create derivative works of the Software in +connection with the Zeus project, provided that any such derivative works may only be used in connection with the Zeus +project. For the sake of clarity, nothing in this Agreement (including, without limitation, this Section 2) will create +any liability to DLI for or restrict DLI’s ability to externally distribute python scripts containing the “input” +configuration files specific to the Zeus project, as well as the notebooks with the resulting “output” data from the +Software, all of which may be distributed, displayed, and shared publicly at DLI’s discretion. + +(b) Ownership; Limited Rights. As between the parties, BlockScience owns and retains all right, title and interest in +and to the Software, and all Intellectual Property Rights therein. DLI’s rights in the Software are limited to those +expressly granted in Section 2(a) and in the PSA. BlockScience reserves all rights and licenses in the Software not +expressly granted to DLI herein and in the PSA. + +(c) Delivery. BlockScience will deliver a copy of the Software and Documentation to DLI on the Effective Date. The +delivery may be made in electronic form, or via hardcopy medium (e.g., a CD). + +(d) Updates. BlockScience will deliver Updates to DLI as and when such Updates become available. The obligation to +deliver Updates will continue for as long as the PSA remains in force; upon termination or expiration of the PSA, +BlockScience’s obligation to provide Updates will automatically terminate. + +(e) Support. BlockScience will provide reasonable technical support for the Software, to help DLI manage any support +issues that arise. The obligation to provide support will continue for as long as the PSA remains in force; upon +termination or expiration of the PSA, BlockScience’s obligation to provide support will automatically terminate. + +3. NO FEES. + +There are no fees owed by DLI for the license granted or the Updates or support provided by BlockScience +pursuant to this Agreement. Each party will bear its own costs and expenses arising out of or relating to its +obligations, efforts and performance under this Agreement. + +4. LIMITED WARRANTY; DISCLAIMER + +(a) Limited Warranty. BlockScience represents and warrants as follows: (i) that it has the right to enter into this +Agreement, and to perform its obligations hereunder, without violating the terms of any other agreement; (ii) that the +Software, and any Updates, do not and will not infringe, violate, or misappropriate the Intellectual Property Rights of +any third party; (iii) that the Software and any Updates do not and will not contain any virus, malware, spyware, trojan +horse, or other malicious code; and (iv) that the Software and each Update will substantially conform to its +Documentation. + +(b) Disclaimer. EXCEPT AS OTHERWISE SET FORTH IN THIS AGREEMENT, BLOCKSCIENCE DISCLAIMS ALL OTHER WARRANTIES, EXPRESS OR +IMPLIED, RELATED TO THE SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR +PURPOSE. + +5. TERM & TERMINATION + +(a) Term. This Agreement begins on the Effective Date, and will continue in effect until one of us terminates it in +accordance with Section 5(b). + +(b) Termination for Breach. Either party may terminate this Agreement if the other party breaches any material term or +condition of this Agreement, and the breaching party fails to cure the breach within thirty (30) days of receiving +written notice of it. + +(c) Survival. Sections 2 through 7 will survive termination or expiration of this Agreement. + +6. INDEMNIFICATION. + +BlockScience will defend, indemnify, and hold DLI harmless from and against any claim, damage, loss, +liability, expense and cost (including, without limitation, reasonable attorneys’ fees) incurred by or brought against +DLI arising out of or related to: (i) any claim that the Software infringes or misappropriates the Intellectual Property +Rights of that third party; or (ii) BlockScience’s breach of its limited warranties in Section 4(a). + +7. GENERAL TERMS + +(a) Entire Agreement; Waiver. This Agreement is the entire understanding of the parties, and supersedes any and all +prior agreements or understandings between the parties as to its subject matter. It may be amended or modified, or +provisions waived, only in a writing signed by both parties. The waiver of a breach of any provision of this Agreement +will not operate or be interpreted as a waiver of any other or subsequent breach. + +(b) Acknowledgement. BlockScience acknowledges and agrees that the “behaviour archetypes” and “configuration of the Null +Model” referenced in the PSA are considered “Work Product” under the PSA. + +(c) Governing Law. This Agreement will be construed, interpreted and applies in accordance with the internal laws of +British Columbia, Canada (excluding its body of law controlling conflicts of law). Any legal action or proceeding +arising under or related to this Agreement will be brought exclusively in the federal or provincial courts located in +Vancouver, British Columbia, and the parties irrevocably consent to personal jurisdiction and venue there. + +(d) Severability. If any provision of this Agreement is held to be invalid or unenforceable for any reason, that +provision will be enforced to the maximum extent permitted by law, and the remaining provisions will continue in full +force and effect. + +(e) Miscellaneous. This Agreement may be executed in one or more counterparts, with the same effect as if the parties +had signed the same document. Each counterpart so executed will be deemed to be an original, and all such counterparts +will be construed together and will constitute one Agreement. The prevailing party in any action or legal proceeding +arising out of this Agreement will be entitled to recover from the other party all reasonable costs and expenses +incurred in connection with such action or proceeding, including reasonable attorneys’ fees and court costs. In the +event of a direct conflict between the terms of this Agreement and the PSA with respect to the DLI’s rights in and to +the Software, the terms of this Agreement will control. + +EXHIBIT A + +SOFTWARE + +Software Name: SimCAD tool + +Software Description: SimCAD is a Monte-Carlo based simulation software package for research, validation, and +Computer Aided Design of economic systems. An economic system is treated as a state based model and defined +through a set of endogenous and exogenous state variables which are updated through mechanisms and +environmental processes, respectively. Behavioral models, which may be deterministic or stochastic, provide the +evolution of the system within the action space of the mechanisms. Simulations can be run with a range of initial +conditions and parameters for states, behaviors, mechanisms, and environmental processes to understand and +visualize network behavior under various conditions. \ No newline at end of file diff --git a/licenses/LICENSE.txt b/licenses/LICENSE.txt new file mode 100644 index 0000000..04c5891 --- /dev/null +++ b/licenses/LICENSE.txt @@ -0,0 +1,119 @@ +TRIAL LICENSE AGREEMENT + +BACKGROUND + +Company has developed and intends to market and license a certain software product and service called ”SimCAD” which, +among other things, is a scientific engineering simulation tool (“Software”). Company wishes to provide access, on a +trial basis, to users of a “beta” version of the Software to test and provide feedback to Company. Licensee wishes to +participate in Company’s beta trial of the Software and to provide feedback to Company with respect to Licensee’s use +thereof. + +Accordingly, the parties hereby agree as follows: + +1. BETA PRODUCT. + +This Agreement applies to any pre­release version of the Software and any updates and changes thereto during the Term +(collectively, “Beta Product”). As an essential condition of this Agreement, Licensee understands and acknowledges that: +(a) Licensee is participating in a beta test of the Beta Product; (b) the Beta Product has not been field tested or +trialed; and (c) the Beta Product may not operate properly or be error free and may not perform all functions for +which it is intended or represented. + +2. FEEDBACK. + +As a condition of this Agreement, during the Term of this Agreement, Licensee agrees to provide Company with comments, +feedback, criticisms, and suggestions for changes to the Beta Product (“Feedback”), and to help Company identify errors +or malfunctions, and performance issues, in the operation of the Beta Product, as Company may reasonably request. All +rights to any Feedback or other intellectual property derived from Licensee’s use of or relating to the Beta Product, +as well any data collected from the use of the Beta Product, belong solely to Company and Licensee hereby irrevocably +assigns all such rights to Company. Company reserves the right to use all Feedback and data collected as a result of the +use of the Beta Product to advertise and promote the Company and the Software. + +3. LICENSE AND RESERVATION OF RIGHTS. + +3.1 Subject to the terms and conditions set forth in this Agreement, Company hereby grants Licensee, and Licensee +accepts, during the Term, a non­exclusive, royalty­free, revocable, non­transferable, limited license to access and use +the Beta Product for its internal, non­commercial use for evaluation purposes only, and to give permission to employees +of Licensee and employees of Licensee’s subsidiaries (“Permitted Users”) to use the Beta Product in accordance with the +foregoing. + +3.2 The Beta Product and the Software comprise the intellectual property of Company. All right, title and interest in +and to the Beta Product (and, more generally, in and to the Software), and to all Feedback and data arising from its +use, in whole or in part, and all patent, copyright, trade­marks, trade secret and all other intellectual and industrial +property rights therein and the structure, sequence and organization of same, and the media on which such material is +contained belong exclusively to Company. Licensee and its Permitted Users will not, directly or indirectly: reverse +engineer, decompile, disassemble or otherwise attempt to discover the source code, object code or underlying structure, +ideas, know­how or algorithms relevant to the Beta Product; modify, adapt, alter, edit, correct, translate, publish, +sell, transfer, assign, convey, rent, lease, loan, pledge, sublicense, distribute, export, enhance or create derivative +works based on the Beta Product; or remove, alter, cover or otherwise obscure any proprietary notices or labels +displayed on or within the Beta Product any documentation relating thereto. + +4. DISCLAIMER. + +4.1 COMPANY MAKES NO WARRANTIES, WHETHER EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, WITH RESPECT TO THE BETA PRODUCT, +INCLUDING, BUT NOT LIMITED TO, THE AVAILABILITY, QUALITY OR PERFORMANCE OF THE BETA PRODUCT. COMPANY SPECIFICALLY +DISCLAIMS ALL EXPRESS, STATUTORY AND IMPLIED WARRANTIES AND CONDITIONS, INCLUDING, WITHOUT LIMITATION (A) THE IMPLIED +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON­INFRINGEMENT, (B) ANY WARRANTIES AGAINST HIDDEN +OR LATENT DEFECTS, (C) AND ANY WARRANTIES AND CONDITIONS ARISING OUT OF COURSE OF DEALING OR USAGE OF TRADE AND (D) ANY +WARRANTY OR REPRESENTATION THAT THE BETA PRODUCT IS ERROR­FREE, VIRUS­FREE, SECURE, UNINTERRUPTED, OR FREE FROM +UNAUTHORIZED ACCESS (INCLUDING, BUT NOT LIMITED TO, THIRD PARTY HACKERS OR DENIAL OF SERVICE ATTACKS). THE BETA PRODUCT +IS SUPPLIED ON AN “AS IS”, “AS AVAILABLE” BASIS WITHOUT WARRANTY. + +4.2 NEITHER PARTY SHALL BE LIABLE FOR SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR INDIRECT DAMAGES OR LOSS +(INCLUDING DEATH AND PERSONAL INJURY), IRRESPECTIVE OF THEIR CAUSE, NOTWITHSTANDING THAT A PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH LOSS OR DAMAGE, NOR FOR ANY CLAIMS FOR SUCH LOSS OR DAMAGE INSTITUTED AGAINST A PARTY OR ITS +CUSTOMERS BY ANY THIRD PARTY. + +5. CONFIDENTIALITY + +5.1 All Confidential Information disclosed by either party shall be kept by the receiving party in strict confidence and +shall not be disclosed to any third party without the disclosing party’s express written consent. For purposes of this +Agreement, “Confidential Information” means all information regarding either party’s business which has been marked or +is otherwise communicated as being “proprietary” or “confidential” or which reasonably should be known by the receiving +party to be proprietary or confidential information. Without limiting the generality of the foregoing, Confidential +Information of Company includes non­public information regarding features, functionality and performance of the Beta +Product, including all Feedback and related data. Notwithstanding the foregoing, each party’s confidentiality +obligations hereunder shall not apply to information that: (a) is already known to the receiving party without a +pre­existing restriction as to disclosure; (b) is or becomes publicly available without fault of the receiving party; +(c) is rightfully obtained by the receiving party from a third party without restriction as to disclosure, or is +approved for release by written authorization of the disclosing party; (d) is developed independently by the receiving +party without use of the disclosing party’s Confidential Information; or (e) is required to be disclosed by law or +regulation, including, but not limited to, supplying such information or making such statements or disclosures relating +to this Agreement before any competent court, governmental agency or authority in response to a lawful requirement or +request from a court of governmental agency or authority, provided that the disclosing party shall give the other party +prompt notice of such request, to the extent practicable, so that the other party may seek (at its sole cost and +expense) an appropriate protective order or similar relief. + +5.2 In the event of a breach of Sections 2, 3 or this Section 5, the non­breaching party shall be entitled to seek +equitable relief to protect its interests, including, but not limited to, injunctive relief. In the event of expiration +or earlier termination of this Agreement, each party shall immediately return to the other party such other party’s +Confidential Information, or at such other party’s option, destroy any remaining Confidential Information and certify +that such destruction has taken place. + +6. FEES; EXPENSES. + +Neither party shall be entitled to any compensation in connection with this Agreement or its use or provision of the +Beta Product. Each party shall bear its own costs and expenses arising from this Agreement and its use or provision of +the Beta Product, as the case may be. + +7. TERM OF AGREEMENT. + +This Agreement shall begin on the Effective Date and shall continue until it has been terminated (such period, the +“Term”). Either party shall have the right to terminate this Agreement at any time on one (1) month written notice to +the other party, or in the case of a breach of this Agreement by Licensee or its Permitted Users, Company may terminate +this Agreement immediately on written notice to Licensee. Upon termination of this Agreement, all rights granted to +Licensee (and any Permitted User) under this Agreement will immediately terminate and Licensee (and all Permitted Users) +must immediately cease all use of the Beta Product at such time. Notwithstanding any termination of this Agreement, +Sections 2, 3.2, 4, 5, 6, this Section 7 and Section 8 shall survive and remain binding on the parties. + +8. MISCELLANEOUS. + +This Agreement shall be governed by and construed in accordance with the laws of the State of New York. All disputes +relating to this Agreement shall be resolved in the federal and state courts of New York County, New York and the +parties submit to the jurisdiction of such courts. This Agreement does not create any agency, partnership, or joint +venture relationship between Licensee and Company. This Agreement is the entire understanding of the parties with +respect to the subject matter hereof and supersedes any previous or contemporaneous communications, representations, +warranties, discussions, arrangements or commitments, whether oral or written with respect to such subject matter. This +Agreement cannot be amended except by a written amendment that expressly refers to this Agreement and is signed by an +authorized representative of each party. This Agreement may be executed in one or more counterparts, including via +facsimile or email (or any other electronic means such as “.pdf” or “.tiff” files), each of which shall be deemed an +original, and all of which shall constitute one and the same Agreement. \ No newline at end of file diff --git a/notebooks/test.ipynb b/notebooks/test.ipynb deleted file mode 100644 index 4814a4a..0000000 --- a/notebooks/test.ipynb +++ /dev/null @@ -1,78 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(\"Simulation Run 2: Pairwise Execution\")\n", - "print()\n", - "multi_proc_ctx = ExecutionContext(exec_mode.multi_proc)\n", - "run2 = Executor(multi_proc_ctx, configs)\n", - "run2_raw_results = run2.main()\n", - "for raw_result in run2_raw_results:\n", - " result = pd.DataFrame(raw_result)\n", - " print(tabulate(result, headers='keys', tablefmt='psql'))\n", - "print()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(\"Simulation Run 1\")\n", - "print()\n", - "single_config = [configs[0]]\n", - "single_proc_ctx = ExecutionContext(exec_mode.single_proc)\n", - "run1 = Executor(single_proc_ctx, single_config)\n", - "run1_raw_result = run1.main()\n", - "result = pd.DataFrame(run1_raw_result)\n", - "result" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import pandas as pd\n", - "from tabulate import tabulate\n", - "\n", - "from SimCAD.engine import ExecutionMode, ExecutionContext, Executor\n", - "from sandboxUX import config1, config2\n", - "from SimCAD import configs\n", - "\n", - "# ToDo: pass ExecutionContext with execution method as ExecutionContext input\n", - "\n", - "exec_mode = ExecutionMode()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/requirements.txt b/requirements.txt index a74daac..48a300b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ pathos -pipenv fn tabulate \ No newline at end of file diff --git a/setup.py b/setup.py index 369eacb..f27a6a4 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,23 @@ -from setuptools import setup +from setuptools import setup, find_packages + +long_description = "SimCAD is a differential games based simulation software package for research, validation, and \ + Computer Aided Design of economic systems. An economic system is treated as a state based model and defined through \ + a set of endogenous and exogenous state variables which are updated through mechanisms and environmental processes, \ + respectively. Behavioral models, which may be deterministic or stochastic, provide the evolution of the system \ + within the action space of the mechanisms. Mathematical formulations of these economic games treat agent utility as \ + derived from state rather than direct from action, creating a rich dynamic modeling framework. Simulations may be \ + run with a range of initial conditions and parameters for states, behaviors, mechanisms, and environmental \ + processes to understand and visualize network behavior under various conditions. Support for A/B testing policies, \ + monte carlo analysis and other common numerical methods is provided." setup(name='SimCAD', version='0.1', - description='Sim-Cad Enigne', + description="SimCAD: a differential games based simulation software package for research, validation, and \ + Computer Aided Design of economic systems", + long_description = long_description, url='https://github.com/BlockScience/DiffyQ-SimCAD', author='Joshua E. Jodesty', author_email='joshua@block.science', - # license='?????', - packages=['SimCAD'], - zip_safe=False) \ No newline at end of file + license='licenses', + packages=find_packages() #['SimCAD'] +) diff --git a/simulations/scrapbox/config7c.py b/simulations/scrapbox/config7c.py deleted file mode 100644 index 1374e1b..0000000 --- a/simulations/scrapbox/config7c.py +++ /dev/null @@ -1,494 +0,0 @@ -from decimal import Decimal -import numpy as np - -from SimCAD import Configuration, configs -from SimCAD.configuration import exo_update_per_ts, bound_norm_random, \ - ep_time_step - -seed = { - 'z': np.random.RandomState(1) - # 'a': np.random.RandomState(2), - # 'b': np.random.RandomState(3), - # 'c': np.random.RandomState(3) -} - -#Signals -# Pr_signal -#if s['P_Ext_Markets'] != 0: -#Pr_signal = s['Z']/s['P_Ext_Markets'] -#else Pr_signal = 0 -# if Pr_signal < s['Z']/s['Buy_Log']: -beta = Decimal('0.25') #agent response gain -beta_LT = Decimal('0.1') #LT agent response gain -alpha = Decimal('0.091') #21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1) -max_withdraw_factor = Decimal('0.9') -external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external - -# Stochastic process factors -correction_factor = Decimal('0.01') -volatility = Decimal('5.0') - - -# Buy_Log_signal = -# Z_signal = -# Price_signal = -# TDR_draw_signal = -# P_Ext_Markets_signal = - -# Behaviors per Mechanism - -# BEHAVIOR 1: EMH Trader -EMH_portion = Decimal('0.250') -EMH_Ext_Hold = Decimal('42000.0') - -def b1m1(step, sL, s): - # y = 'P_Ext_Markets' - # Psignal_ext = s['P_Ext_Markets'] / s['Z'] - # Psignal_int = s['Buy_Log'] / s['Z'] - # if Psignal_ext < Psignal_int: - # return beta*(Psignal_int - Psignal_ext) * s['Z'] # Deposited amount in TDR - # else: - # return 0 # Decimal(0.000001) - # return (y,x) - theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets']) - if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)): - return beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta)) - elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)): - return 0 - else: - return 0 - -def b1m2(step, sL, s): - theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets']) - if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)): - return 0 - elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)): - return beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta)) - else: - return 0 - -# BEHAVIOR 3: Herding - - -# BEHAVIOR 4: HODLers -HODL_belief = Decimal('10.0') -HODL_portion = Decimal('0.250') -HODL_Ext_Hold = Decimal('4200.0') - -def b4m2(step, sL, s): - theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets']) - if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)): - return beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta)) - elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)): - return 0 - else: - return 0 - - -# BEHAVIOR 2: Withdraw TDR and burn Zeus -# Selling Agent- Arbitrage on TDR ext v TDR int signals -# def b2m1(step, sL, s): -# Psignal_ext = s['P_Ext_Markets'] / s['Z'] -# Psignal_int = s['Buy_Log'] / s['Z'] -# if Psignal_ext > Psignal_int: -# # withdrawn amount in TDR, subject to TDR limit -# return - np.minimum(beta*(Psignal_ext - Psignal_int) * s['Z'],s['Buy_Log']*max_withdraw_factor) -# else: -# return 0 #- Decimal(0.000001) - # return 0 - -# BEHAVIOR 1: Deposit TDR and mint Zeus -# Buying Agent- Arbitrage on Price and Z signals -# def b1m2(step, sL, s): -# # Psignal_ext = s['P_Ext_Markets'] / s['Z'] -# # Psignal_int = s['Buy_Log'] / s['Z'] -# # if Psignal_ext > Psignal_int: -# # # withdrawn amount in TDR, subject to TDR limit -# # return - np.minimum(beta*(Psignal_ext - Psignal_int) * s['Z'],s['Buy_Log']*max_withdraw_factor) -# # else: -# # return 0 #- Decimal(0.000001) -# # -# # LT more valuable than ST = deposit TDR and mint Z -# Psignal_LT = s['Price'] / s['Z'] -# if Psignal_LT > 1: -# return beta_LT*(Psignal_LT - 1) * s['Z'] -# else: -# return 0 - -# Behavior will go here- b2m2, putting in mech 3: b1m3 for debugging -# def b2m2(step, sL, s): -# # Psignal_LT = s['Price'] / s['Z'] -# # if Psignal_LT > 1: -# test = np.arange(1,10) -# return test - -# Selling Agent- Arbitrage on Price and Z signals -# def b1m3(step, sL, s): -# Psignal_LT = s['Price'] / s['Z'] -# if Psignal_LT < 1: -# return - np.minimum(beta_LT*(Psignal_LT - 1) * s['Z'], s['Z']*max_withdraw_factor) -# else: -# return 0 - - -# def b2m3(step, sL, s): -# return 0 - -def dummy_behavior(step, sL, s): - return 0 -def s1_dummy(step, sL, s, _input): - y = 'Z' - x = s['Z'] - return (y, x) -def s2_dummy(step, sL, s, _input): - y = 'Price' - x = s['Price'] - return (y, x) -def s3_dummy(step, sL, s, _input): - y = 'Buy_Log' - x = s['Buy_Log'] - return (y, x) -def s4_dummy(step, sL, s, _input): - y = 'Sell_Log' - x = s['Sell_Log'] - return (y, x) -def s5_dummy(step, sL, s, _input): - y = 'Trans' - x = s['Trans'] - return (y, x) -def s6_dummy(step, sL, s, _input): - y = 'P_Ext_Markets' - x = s['P_Ext_Markets'] - return (y, x) -# Internal States per Mechanism -# Deposit TDR/Mint Zeus -# def s1m1(step, sL, s, _input): -# s['Z'] = s['Z'] + _input - - -# STATES - -# ZEUS Fixed Supply -def s1m1(step, sL, s, _input): - y = 'Z' - x = s['Z'] #+ _input # / Psignal_int - return (y, x) - -def s2m1(step, sL, s, _input): - y = 'Price' - x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000 - #x= alpha * s['Z'] + (1 - alpha)*s['Price'] - return (y, x) - -def s3m1(step, sL, s, _input): - y = 'Buy_Log' - x = _input # / Psignal_int - return (y, x) - -def s4m2(step, sL, s, _input): - y = 'Sell_Log' - x = _input # / Psignal_int - print('s4m2 ',type(_input)) - return (y, x) - -def s3m3(step, sL, s, _input): - y = 'Buy_Log' - x = s['Buy_Log'] + _input # / Psignal_int - return (y, x) - -# Price Update -def s2m3(step, sL, s, _input): - print('s2m3 ') - print(type(s['Sell_Log'])) - print(type(s['Z'])) - - y = 'Price' - x = s['Price'] + s['Buy_Log']/s['Z'] - s['Sell_Log']/s['Z'] - #+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int - return (y, x) - - - -def s6m1(step, sL, s, _input): - y = 'P_Ext_Markets' - x = s['P_Ext_Markets'] - _input - #x= alpha * s['Z'] + (1 - alpha)*s['Price'] - return (y, x) - -def s2m2(step, sL, s, _input): - y = 'Price' - x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000 - #x= alpha * s['Z'] + (1 - alpha)*s['Price'] - return (y, x) - -# def s1m1(step, sL, s, _input): -# Psignal_int = s['Buy_Log'] / s['Z'] -# y = 'Z' -# x = s['Z'] + _input / Psignal_int -# return (y, x) - -# def s2m1(step, sL, s, _input): -# y = 'Price' -# x= alpha * s['Z'] + (1 - alpha)*s['Price'] -# return (y, x) - -# def s3m1(step, sL, s, _input): -# y = 'Buy_Log' -# x = s['Buy_Log'] + _input # Input already in TDR * s['Z'] -# return (y, x) - -# # Withdraw TDR/Burn Zeus -# def s1m2(step, sL, s, _input): -# Psignal_int = s['Buy_Log'] / s['Z'] -# y = 'Z' -# x = s['Z'] #+ _input / Psignal_int -# return (y, x) - -# def s2m2(step, sL, s, _input): -# y = 'Price' -# x= alpha * s['Z'] + (1 - alpha)*s['Price'] -# return (y, x) - -# def s3m2(step, sL, s, _input): -# y = 'Buy_Log' -# x = s['Buy_Log'] + _input #* s['Z'] -# # y = 'Buy_Log' -# # x = s['Buy_Log'] + _input -# return (y, x) - -# def s1m3(step, sL, s, _input): -# Psignal_int = s['Buy_Log'] / s['Z'] -# y = 'Z' -# x = s['Z'] #+ _input / Psignal_int -# return (y, x) - -# def s2m3(step, sL, s, _input): -# y = 'Price' -# x= alpha * s['Z'] + (1 - alpha)*s['Price'] -# return (y, x) - -# def s3m3(step, sL, s, _input): -# y = 'Buy_Log' -# x = s['Buy_Log'] #+ _input #* s['Z'] -# # y = 'Buy_Log' -# # x = s['Buy_Log'] + _input -# return (y, x) - -# def s3m4(step, sL, s, _input): -# y = 'Buy_Log' -# x = s['Buy_Log']*(1-external_draw) + s['Sell_Log']*external_draw # _input #* s['Z'] -# # y = 'Buy_Log' -# # x = s['Buy_Log'] + _input -# return (y, x) - -# def s1m3(step, sL, s, _input): -# s['Z'] = s['Z'] + _input -# def s2m3(step, sL, s, _input): -# s['Price'] = s['Price'] + _input - -# Exogenous States -proc_one_coef_A = -125 -proc_one_coef_B = 125 -# def es3p1(step, sL, s, _input): -# s['s3'] = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B) -# def es4p2(step, sL, s, _input): -# s['P_Ext_Markets'] = s['P_Ext_Markets'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B) -# def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params -# s['timestamp'] = ep_time_step(s, s['timestamp'], seconds=1) -def es3p1(step, sL, s, _input): - y = 's3' - x = s['s3'] + 1 - return (y, x) -# def es4p2(step, sL, s, _input): -# y = 'P_Ext_Markets' -# # bound_norm_random defined in utils.py - -# #x = s['P_Ext_Markets'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B) -# expected_change = correction_factor*(s['P_Ext_Markets']-s['Buy_Log']) -# vol = np.random.randint(1,volatility) -# change = expected_change * vol -# # change_float = (np.random.normal(expected_change,volatility*expected_change) #Decimal('1.0') -# #change = Decimal.from_float(change_float) -# x = s['P_Ext_Markets'] + change - -# return (y, x) - -# A change in belief of actual price, passed onto behaviors to make action -def es4p2(step, sL, s, _input): - y = 'P_Ext_Markets' - x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B) - - return (y,x) - - -def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params - y = 'timestamp' - x = ep_time_step(s, s['timestamp'], seconds=1) - return (y, x) -#Environment States -# def stochastic(reference, seed, correction = 0.01): -# series = np.zeros(len(reference)) -# series[0] = reference[0] -# for i in range(1,len(reference)): -# expected_change = correction*(reference[i]-series[i-1]) -# normalized_expected_change = np.abs(expected_change)*(reference[i])/(reference[i-1]) -# seed_int = seed.randint(1,10) -# change = np.random.normal(expected_change,seed_int*normalized_expected_change) - -# series[i] = series[i-1]+change -# # avoid negative series returns -# if series[i] <= 0: -# series[i] = .01 -# #series[i] = series[i-1]+change - -# return [series,seed_int] -# ref3 = np.arange(1,1000)*.1 -# test = stochastic(ref3,seed['b']) - -# def env_a(ref3,seed['b']): -# return stochastic(ref3,seed['b']) -def env_a(x): - return 100 -def env_b(x): - return 21000000 -# def what_ever(x): -# return x + 1 - -# Genesis States -state_dict = { - 'Z': Decimal(21000000.0), - 'Price': Decimal(100.0), # Initialize = Z for EMA - 'Buy_Log': Decimal(0.0), - 'Sell_Log': Decimal(0.0), - 'Trans': Decimal(0.0), - 'P_Ext_Markets': Decimal(25000.0), - - # 's2': Decimal(0.0), - # 's3': Decimal(0.0), - # 's4': Decimal(0.0), - 'timestamp': '2018-10-01 15:16:24' -} - -# exogenous_states = { -# # "s3": es3p1, -# "P_Ext_Markets": es4p2, -# "timestamp": es5p2 -# } - -exogenous_states = exo_update_per_ts( - { - # "s3": es3p1, - "P_Ext_Markets": es4p2, - "timestamp": es5p2 - } -) - -env_processes = { - # "s3": env_proc('2018-10-01 15:16:25', env_a), -# "P_Ext_Markets": env_proc('2018-10-01 15:16:25', env_b) -} - -# test return vs. non-return functions as lambdas -# test fully defined functions -mechanisms = { - "m1": { - "behaviors": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, -# "b2": b2m1 - }, - "states": { - "Z": s1m1, - "Price": s2_dummy, - "Buy_Log": s3m1, - "Sell_Log":s4_dummy, - "Trans": s5_dummy, - "P_Ext_Markets": s6_dummy - } - }, - "m2": { - "behaviors": { - "b1": b1m2, - "b4": b4m2 - }, - "states": { - "Z": s1_dummy, - "Price": s2_dummy, - "Buy_Log": s3_dummy, - "Sell_Log":s4m2, - "Trans": s5_dummy, - "P_Ext_Markets": s6_dummy - } - }, - "m3": { - "behaviors": { -# "b1": b1m2, -# "b4": b4m2 - }, - "states": { - "Z": s1_dummy, - "Price": s2m3, - "Buy_Log": s3_dummy, - "Sell_Log":s4_dummy, - "Trans": s5_dummy, - "P_Ext_Markets": s6_dummy - } - }, -# "m3": { -# "behaviors": { -# "b1": b1m3, -# "b2": b2m3 -# }, -# "states": { -# "Z": s1m3, -# "Price": s2m3, -# "Buy_Log": s3m3, -# "Sell_Log": s4_dummy, -# "Trans": s5_dummy, -# "P_Ext_Markets": s6_dummy -# } -# }, -# "m4": { -# "behaviors": { -# "dummy": dummy_behavior -# }, -# "states": { -# "Z": s1_dummy, -# "Price": s2_dummy, -# "Buy_Log": s3m4, -# "Sell_Log": s4_dummy, -# "Trans": s5_dummy, -# "P_Ext_Markets": s6_dummy -# } -# }, - # "m3": { - # "behaviors": { - # "b1": b1m3, - # "b2": b2m3 - # }, - # "states": { - # "Z": s1m3, - # "Price": s2m3, - # } - # } - #treat environmental processes as a mechanism - "ep": { - "behaviors": { - "dummy": dummy_behavior - }, - "states": { - "Z": s1_dummy, - "Price": s2_dummy, - "Buy_Log": s3_dummy, - "Sell_Log": s4_dummy, - "Trans": s5_dummy, - "P_Ext_Markets": es4p2 - } - } -} - -sim_config = { - "N": 1, - "T": range(1000) -} - -configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms)) diff --git a/simulations/scrapbox/config8c.py b/simulations/scrapbox/config8c.py deleted file mode 100644 index 2eecf45..0000000 --- a/simulations/scrapbox/config8c.py +++ /dev/null @@ -1,443 +0,0 @@ -from decimal import Decimal -import numpy as np - -from SimCAD import Configuration, configs -from SimCAD.configuration import exo_update_per_ts, bound_norm_random, \ - ep_time_step - -# behavior_ops = [] -# behavior_ops = [foldr(dict_elemwise_sum())] - -seed = { - 'z': np.random.RandomState(1) - # 'a': np.random.RandomState(2), - # 'b': np.random.RandomState(3), - # 'c': np.random.RandomState(3) -} - -#Signals -# Pr_signal -#if s['P_Ext_Markets'] != 0: -#Pr_signal = s['Z']/s['P_Ext_Markets'] -#else Pr_signal = 0 -# if Pr_signal < s['Z']/s['Buy_Log']: -beta = Decimal('0.25') #agent response gain -beta_LT = Decimal('0.1') #LT agent response gain -alpha = Decimal('0.091') #21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1) -max_withdraw_factor = Decimal('0.9') -external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external - -# Stochastic process factors -correction_factor = Decimal('0.01') -volatility = Decimal('5.0') - - -# Buy_Log_signal = -# Z_signal = -# Price_signal = -# TDR_draw_signal = -# P_Ext_Markets_signal = - -# Behaviors per Mechanism - -# BEHAVIOR 1: EMH Trader -EMH_portion = Decimal('0.250') -EMH_Ext_Hold = Decimal('42000.0') - -def b1m1(step, sL, s): - print('b1m1') - # y = 'P_Ext_Markets' - # Psignal_ext = s['P_Ext_Markets'] / s['Z'] - # Psignal_int = s['Buy_Log'] / s['Z'] - # if Psignal_ext < Psignal_int: - # return beta*(Psignal_int - Psignal_ext) * s['Z'] # Deposited amount in TDR - # else: - # return 0 # Decimal(0.000001) - # return (y,x) - theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets']) - if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)): - buy = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta)) - return {'buy_order1': buy} - elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)): - return {'buy_order1': 0} - else: - return {'buy_order1': 0} - -def b1m2(step, sL, s): - print('b1m2') - theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets']) - if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)): - return {'sell_order1': 0} - elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)): - sell = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta)) - return {'sell_order1': sell} - else: - return {'sell_order1': 0} - -# BEHAVIOR 3: Herding - - -# BEHAVIOR 4: HODLers -HODL_belief = Decimal('10.0') -HODL_portion = Decimal('0.250') -HODL_Ext_Hold = Decimal('4200.0') - -def b4m2(step, sL, s): - print('b4m2') - theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets']) - if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)): - sell = beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta)) - return {'sell_order2': sell} - elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)): - return {'sell_order2': 0} - else: - return {'sell_order2': 0} - - -# BEHAVIOR 2: Withdraw TDR and burn Zeus -# Selling Agent- Arbitrage on TDR ext v TDR int signals -# def b2m1(step, sL, s): -# Psignal_ext = s['P_Ext_Markets'] / s['Z'] -# Psignal_int = s['Buy_Log'] / s['Z'] -# if Psignal_ext > Psignal_int: -# # withdrawn amount in TDR, subject to TDR limit -# return - np.minimum(beta*(Psignal_ext - Psignal_int) * s['Z'],s['Buy_Log']*max_withdraw_factor) -# else: -# return 0 #- Decimal(0.000001) - # return 0 - -# BEHAVIOR 1: Deposit TDR and mint Zeus -# Buying Agent- Arbitrage on Price and Z signals -# def b1m2(step, sL, s): -# # Psignal_ext = s['P_Ext_Markets'] / s['Z'] -# # Psignal_int = s['Buy_Log'] / s['Z'] -# # if Psignal_ext > Psignal_int: -# # # withdrawn amount in TDR, subject to TDR limit -# # return - np.minimum(beta*(Psignal_ext - Psignal_int) * s['Z'],s['Buy_Log']*max_withdraw_factor) -# # else: -# # return 0 #- Decimal(0.000001) -# # -# # LT more valuable than ST = deposit TDR and mint Z -# Psignal_LT = s['Price'] / s['Z'] -# if Psignal_LT > 1: -# return beta_LT*(Psignal_LT - 1) * s['Z'] -# else: -# return 0 - -# Behavior will go here- b2m2, putting in mech 3: b1m3 for debugging -# def b2m2(step, sL, s): -# # Psignal_LT = s['Price'] / s['Z'] -# # if Psignal_LT > 1: -# test = np.arange(1,10) -# return test - -# Selling Agent- Arbitrage on Price and Z signals -# def b1m3(step, sL, s): -# Psignal_LT = s['Price'] / s['Z'] -# if Psignal_LT < 1: -# return - np.minimum(beta_LT*(Psignal_LT - 1) * s['Z'], s['Z']*max_withdraw_factor) -# else: -# return 0 - - -# def b2m3(step, sL, s): -# return 0 - -# Internal States per Mechanism -# Deposit TDR/Mint Zeus -# def s1m1(step, sL, s, _input): -# s['Z'] = s['Z'] + _input - - -# STATES - -# ZEUS Fixed Supply -def s1m1(step, sL, s, _input): - y = 'Z' - x = s['Z'] #+ _input # / Psignal_int - return (y, x) - -def s2m1(step, sL, s, _input): - y = 'Price' - x = (s['P_Ext_Markets'] - _input['buy_order1']) /s['Z'] *10000 - #x= alpha * s['Z'] + (1 - alpha)*s['Price'] - return (y, x) - -def s3m1(step, sL, s, _input): - y = 'Buy_Log' - x = _input['buy_order1'] # / Psignal_int - return (y, x) - -def s4m2(step, sL, s, _input): - y = 'Sell_Log' - x = _input['sell_order1'] + _input['sell_order2'] # / Psignal_int - return (y, x) - -def s3m3(step, sL, s, _input): - y = 'Buy_Log' - x = s['Buy_Log'] + _input # / Psignal_int - return (y, x) - -# Price Update -def s2m3(step, sL, s, _input): - - y = 'Price' - #var1 = Decimal.from_float(s['Buy_Log']) - x = s['Price'] + s['Buy_Log'] * 1/s['Z'] - s['Sell_Log']/s['Z'] - #+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int - return (y, x) - - - -def s6m1(step, sL, s, _input): - y = 'P_Ext_Markets' - x = s['P_Ext_Markets'] - _input - #x= alpha * s['Z'] + (1 - alpha)*s['Price'] - return (y, x) - -def s2m2(step, sL, s, _input): - y = 'Price' - x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000 - #x= alpha * s['Z'] + (1 - alpha)*s['Price'] - return (y, x) - -# def s1m1(step, sL, s, _input): -# Psignal_int = s['Buy_Log'] / s['Z'] -# y = 'Z' -# x = s['Z'] + _input / Psignal_int -# return (y, x) - -# def s2m1(step, sL, s, _input): -# y = 'Price' -# x= alpha * s['Z'] + (1 - alpha)*s['Price'] -# return (y, x) - -# def s3m1(step, sL, s, _input): -# y = 'Buy_Log' -# x = s['Buy_Log'] + _input # Input already in TDR * s['Z'] -# return (y, x) - -# # Withdraw TDR/Burn Zeus -# def s1m2(step, sL, s, _input): -# Psignal_int = s['Buy_Log'] / s['Z'] -# y = 'Z' -# x = s['Z'] #+ _input / Psignal_int -# return (y, x) - -# def s2m2(step, sL, s, _input): -# y = 'Price' -# x= alpha * s['Z'] + (1 - alpha)*s['Price'] -# return (y, x) - -# def s3m2(step, sL, s, _input): -# y = 'Buy_Log' -# x = s['Buy_Log'] + _input #* s['Z'] -# # y = 'Buy_Log' -# # x = s['Buy_Log'] + _input -# return (y, x) - -# def s1m3(step, sL, s, _input): -# Psignal_int = s['Buy_Log'] / s['Z'] -# y = 'Z' -# x = s['Z'] #+ _input / Psignal_int -# return (y, x) - -# def s2m3(step, sL, s, _input): -# y = 'Price' -# x= alpha * s['Z'] + (1 - alpha)*s['Price'] -# return (y, x) - -# def s3m3(step, sL, s, _input): -# y = 'Buy_Log' -# x = s['Buy_Log'] #+ _input #* s['Z'] -# # y = 'Buy_Log' -# # x = s['Buy_Log'] + _input -# return (y, x) - -# def s3m4(step, sL, s, _input): -# y = 'Buy_Log' -# x = s['Buy_Log']*(1-external_draw) + s['Sell_Log']*external_draw # _input #* s['Z'] -# # y = 'Buy_Log' -# # x = s['Buy_Log'] + _input -# return (y, x) - -# def s1m3(step, sL, s, _input): -# s['Z'] = s['Z'] + _input -# def s2m3(step, sL, s, _input): -# s['Price'] = s['Price'] + _input - -# Exogenous States -proc_one_coef_A = -125 -proc_one_coef_B = 125 -# def es3p1(step, sL, s, _input): -# s['s3'] = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B) -# def es4p2(step, sL, s, _input): -# s['P_Ext_Markets'] = s['P_Ext_Markets'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B) -# def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params -# s['timestamp'] = ep_time_step(s, s['timestamp'], seconds=1) -def es3p1(step, sL, s, _input): - y = 's3' - x = s['s3'] + 1 - return (y, x) -# def es4p2(step, sL, s, _input): -# y = 'P_Ext_Markets' -# # bound_norm_random defined in utils.py - -# #x = s['P_Ext_Markets'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B) -# expected_change = correction_factor*(s['P_Ext_Markets']-s['Buy_Log']) -# vol = np.random.randint(1,volatility) -# change = expected_change * vol -# # change_float = (np.random.normal(expected_change,volatility*expected_change) #Decimal('1.0') -# #change = Decimal.from_float(change_float) -# x = s['P_Ext_Markets'] + change - -# return (y, x) - -# A change in belief of actual price, passed onto behaviors to make action -def es4p2(step, sL, s, _input): - y = 'P_Ext_Markets' - x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B) - - return (y,x) - - -def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params - y = 'timestamp' - x = ep_time_step(s, s['timestamp'], seconds=1) - return (y, x) -#Environment States -# def stochastic(reference, seed, correction = 0.01): -# series = np.zeros(len(reference)) -# series[0] = reference[0] -# for i in range(1,len(reference)): -# expected_change = correction*(reference[i]-series[i-1]) -# normalized_expected_change = np.abs(expected_change)*(reference[i])/(reference[i-1]) -# seed_int = seed.randint(1,10) -# change = np.random.normal(expected_change,seed_int*normalized_expected_change) - -# series[i] = series[i-1]+change -# # avoid negative series returns -# if series[i] <= 0: -# series[i] = .01 -# #series[i] = series[i-1]+change - -# return [series,seed_int] -# ref3 = np.arange(1,1000)*.1 -# test = stochastic(ref3,seed['b']) - -# def env_a(ref3,seed['b']): -# return stochastic(ref3,seed['b']) -def env_a(x): - return 100 -def env_b(x): - return 21000000 -# def what_ever(x): -# return x + 1 - -# Genesis States -state_dict = { - 'Z': Decimal(21000000.0), - 'Price': Decimal(100.0), # Initialize = Z for EMA - 'Buy_Log': Decimal(0.0), - 'Sell_Log': Decimal(0.0), - 'Trans': Decimal(0.0), - 'P_Ext_Markets': Decimal(25000.0), - - # 's2': Decimal(0.0), - # 's3': Decimal(0.0), - # 's4': Decimal(0.0), - 'timestamp': '2018-10-01 15:16:24' -} - -# exogenous_states = { -# # "s3": es3p1, -# "P_Ext_Markets": es4p2, -# "timestamp": es5p2 -# } - -exogenous_states = exo_update_per_ts( - { - # "s3": es3p1, - "P_Ext_Markets": es4p2, - "timestamp": es5p2 - } -) - -env_processes = { - # "s3": env_proc('2018-10-01 15:16:25', env_a), -# "P_Ext_Markets": env_proc('2018-10-01 15:16:25', env_b) -} - -# test return vs. non-return functions as lambdas -# test fully defined functions -mechanisms = { - "m1": { - "behaviors": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, -# "b2": b2m1 - }, - "states": { - "Z": s1m1, -# "Price": s2_dummy, - "Buy_Log": s3m1, - } - }, - "m2": { - "behaviors": { - "b1": b1m2, - "b4": b4m2 - }, - "states": { - "Sell_Log":s4m2, - } - }, - "m3": { - "behaviors": { - }, - "states": { - "Price": s2m3, - } - }, -# "m3": { -# "behaviors": { -# "b1": b1m3, -# "b2": b2m3 -# }, -# "states": { -# "Z": s1m3, -# "Price": s2m3, -# "Buy_Log": s3m3, -# } -# }, -# "m4": { -# "behaviors": { -# }, -# "states": { -# } -# }, - # "m3": { - # "behaviors": { - # "b1": b1m3, - # "b2": b2m3 - # }, - # "states": { - # "Z": s1m3, - # "Price": s2m3, - # } - # } - #treat environmental processes as a mechanism - "ep": { - "behaviors": { - }, - "states": { - "P_Ext_Markets": es4p2 - } - } -} - -sim_config = { - "N": 1, - "T": range(1000) -} - -configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms)) \ No newline at end of file diff --git a/simulations/sim_test.py b/simulations/sim_test.py index 9f96c49..3a18378 100644 --- a/simulations/sim_test.py +++ b/simulations/sim_test.py @@ -1,16 +1,13 @@ import pandas as pd from tabulate import tabulate -# The following imports NEED to be in the exact same order +# The following imports NEED to be in the exact order from SimCAD.engine import ExecutionMode, ExecutionContext, Executor -from simulations.validation import config1, config2 +from validation import config1, config2 from SimCAD import configs -# ToDo: pass ExecutionContext with execution method as ExecutionContext input - exec_mode = ExecutionMode() - print("Simulation Execution 1") print() first_config = [configs[0]] # from config1 @@ -18,7 +15,6 @@ single_proc_ctx = ExecutionContext(context=exec_mode.single_proc) run1 = Executor(exec_context=single_proc_ctx, configs=first_config) run1_raw_result, tensor_field = run1.main() result = pd.DataFrame(run1_raw_result) -# result.to_csv('~/Projects/DiffyQ-SimCAD/results/config.csv', sep=',') print() print("Tensor Field:") print(tabulate(tensor_field, headers='keys', tablefmt='psql')) @@ -37,4 +33,4 @@ for raw_result, tensor_field in run2.main(): print(tabulate(tensor_field, headers='keys', tablefmt='psql')) print("Output:") print(tabulate(result, headers='keys', tablefmt='psql')) - print() \ No newline at end of file + print() diff --git a/simulations/test.ipynb b/simulations/test.ipynb new file mode 100644 index 0000000..8f8415a --- /dev/null +++ b/simulations/test.ipynb @@ -0,0 +1,1900 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "from tabulate import tabulate\n", + "\n", + "# The following imports NEED to be in the exact order\n", + "from SimCAD.engine import ExecutionMode, ExecutionContext, Executor\n", + "from validation import config1, config2\n", + "from SimCAD import configs\n", + "\n", + "exec_mode = ExecutionMode()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Simulation Execution 1\n", + "\n", + "single_proc: []\n" + ] + } + ], + "source": [ + "print(\"Simulation Execution 1\")\n", + "print()\n", + "first_config = [configs[0]] # from config1\n", + "single_proc_ctx = ExecutionContext(context=exec_mode.single_proc)\n", + "run1 = Executor(exec_context=single_proc_ctx, configs=first_config)\n", + "run1_raw_result, raw_tensor_field = run1.main()\n", + "result = pd.DataFrame(run1_raw_result)\n", + "tensor_field = pd.DataFrame(raw_tensor_field)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tensor Field:\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
b1b2s1s2es1es2es3m
0<function b1m1 at 0x109f25d90><function b2m1 at 0x10a2fda60><function s1m1 at 0x10a2fdd08><function s2m1 at 0x10a2fdd90><function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...1
1<function b1m2 at 0x10a2fdae8><function b2m2 at 0x10a2fdb70><function s1m2 at 0x10a2fde18><function s2m2 at 0x10a2fdea0><function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...2
2<function b1m3 at 0x10a2fdbf8><function b2m3 at 0x10a2fdc80><function s1m3 at 0x10a2fdf28><function s2m3 at 0x10a308048><function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...3
\n", + "
" + ], + "text/plain": [ + " b1 b2 \\\n", + "0 \n", + "1 \n", + "2 \n", + "\n", + " s1 s2 \\\n", + "0 \n", + "1 \n", + "2 \n", + "\n", + " es1 \\\n", + "0 ._curried at 0x10a30... \n", + "1 ._curried at 0x10a30... \n", + "2 ._curried at 0x10a30... \n", + "\n", + " es2 \\\n", + "0 ._curried at 0x10a30... \n", + "1 ._curried at 0x10a30... \n", + "2 ._curried at 0x10a30... \n", + "\n", + " es3 m \n", + "0 ._curried at 0x10a30... 1 \n", + "1 ._curried at 0x10a30... 2 \n", + "2 ._curried at 0x10a30... 3 " + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "print(\"Tensor Field:\")\n", + "tensor_field" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Output:\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
mech_stepruns1s2s3s4time_steptimestamp
001001102018-10-01 15:16:24
1111451012018-10-01 15:16:25
221ab651012018-10-01 15:16:25
331[c, d][30, 300]51012018-10-01 15:16:25
41114510.4365098505119902050353175622018-10-01 15:16:26
521ab6510.4365098505119902050353175622018-10-01 15:16:26
631[c, d][30, 300]510.4365098505119902050353175622018-10-01 15:16:26
71114510.5372195281202876186024801332018-10-01 15:16:27
821ab6510.5372195281202876186024801332018-10-01 15:16:27
931[c, d][30, 300]510.5372195281202876186024801332018-10-01 15:16:27
10111458.57361635768008949978322321242018-10-01 15:16:28
1121ab658.57361635768008949978322321242018-10-01 15:16:28
1231[c, d][30, 300]58.57361635768008949978322321242018-10-01 15:16:28
13111458.33579435462959645300709321652018-10-01 15:16:29
1421ab658.33579435462959645300709321652018-10-01 15:16:29
1531[c, d][30, 300]58.33579435462959645300709321652018-10-01 15:16:29
1602001102018-10-01 15:16:24
17121451012018-10-01 15:16:25
1822ab651012018-10-01 15:16:25
1932[c, d][30, 300]51012018-10-01 15:16:25
20121459.91725851851753992249882685422018-10-01 15:16:26
2122ab659.91725851851753992249882685422018-10-01 15:16:26
2232[c, d][30, 300]59.91725851851753992249882685422018-10-01 15:16:26
23121459.29544573818278309896721217232018-10-01 15:16:27
2422ab659.29544573818278309896721217232018-10-01 15:16:27
2532[c, d][30, 300]59.29544573818278309896721217232018-10-01 15:16:27
26121459.25471479697655613481958888342018-10-01 15:16:28
2722ab659.25471479697655613481958888342018-10-01 15:16:28
2832[c, d][30, 300]59.25471479697655613481958888342018-10-01 15:16:28
29121458.81306312028134610425625981852018-10-01 15:16:29
3022ab658.81306312028134610425625981852018-10-01 15:16:29
3132[c, d][30, 300]58.81306312028134610425625981852018-10-01 15:16:29
\n", + "
" + ], + "text/plain": [ + " mech_step run s1 s2 s3 s4 \\\n", + "0 0 1 0 0 1 1 \n", + "1 1 1 1 4 5 10 \n", + "2 2 1 ab 6 5 10 \n", + "3 3 1 [c, d] [30, 300] 5 10 \n", + "4 1 1 1 4 5 10.43650985051199020503531756 \n", + "5 2 1 ab 6 5 10.43650985051199020503531756 \n", + "6 3 1 [c, d] [30, 300] 5 10.43650985051199020503531756 \n", + "7 1 1 1 4 5 10.53721952812028761860248013 \n", + "8 2 1 ab 6 5 10.53721952812028761860248013 \n", + "9 3 1 [c, d] [30, 300] 5 10.53721952812028761860248013 \n", + "10 1 1 1 4 5 8.573616357680089499783223212 \n", + "11 2 1 ab 6 5 8.573616357680089499783223212 \n", + "12 3 1 [c, d] [30, 300] 5 8.573616357680089499783223212 \n", + "13 1 1 1 4 5 8.335794354629596453007093216 \n", + "14 2 1 ab 6 5 8.335794354629596453007093216 \n", + "15 3 1 [c, d] [30, 300] 5 8.335794354629596453007093216 \n", + "16 0 2 0 0 1 1 \n", + "17 1 2 1 4 5 10 \n", + "18 2 2 ab 6 5 10 \n", + "19 3 2 [c, d] [30, 300] 5 10 \n", + "20 1 2 1 4 5 9.917258518517539922498826854 \n", + "21 2 2 ab 6 5 9.917258518517539922498826854 \n", + "22 3 2 [c, d] [30, 300] 5 9.917258518517539922498826854 \n", + "23 1 2 1 4 5 9.295445738182783098967212172 \n", + "24 2 2 ab 6 5 9.295445738182783098967212172 \n", + "25 3 2 [c, d] [30, 300] 5 9.295445738182783098967212172 \n", + "26 1 2 1 4 5 9.254714796976556134819588883 \n", + "27 2 2 ab 6 5 9.254714796976556134819588883 \n", + "28 3 2 [c, d] [30, 300] 5 9.254714796976556134819588883 \n", + "29 1 2 1 4 5 8.813063120281346104256259818 \n", + "30 2 2 ab 6 5 8.813063120281346104256259818 \n", + "31 3 2 [c, d] [30, 300] 5 8.813063120281346104256259818 \n", + "\n", + " time_step timestamp \n", + "0 0 2018-10-01 15:16:24 \n", + "1 1 2018-10-01 15:16:25 \n", + "2 1 2018-10-01 15:16:25 \n", + "3 1 2018-10-01 15:16:25 \n", + "4 2 2018-10-01 15:16:26 \n", + "5 2 2018-10-01 15:16:26 \n", + "6 2 2018-10-01 15:16:26 \n", + "7 3 2018-10-01 15:16:27 \n", + "8 3 2018-10-01 15:16:27 \n", + "9 3 2018-10-01 15:16:27 \n", + "10 4 2018-10-01 15:16:28 \n", + "11 4 2018-10-01 15:16:28 \n", + "12 4 2018-10-01 15:16:28 \n", + "13 5 2018-10-01 15:16:29 \n", + "14 5 2018-10-01 15:16:29 \n", + "15 5 2018-10-01 15:16:29 \n", + "16 0 2018-10-01 15:16:24 \n", + "17 1 2018-10-01 15:16:25 \n", + "18 1 2018-10-01 15:16:25 \n", + "19 1 2018-10-01 15:16:25 \n", + "20 2 2018-10-01 15:16:26 \n", + "21 2 2018-10-01 15:16:26 \n", + "22 2 2018-10-01 15:16:26 \n", + "23 3 2018-10-01 15:16:27 \n", + "24 3 2018-10-01 15:16:27 \n", + "25 3 2018-10-01 15:16:27 \n", + "26 4 2018-10-01 15:16:28 \n", + "27 4 2018-10-01 15:16:28 \n", + "28 4 2018-10-01 15:16:28 \n", + "29 5 2018-10-01 15:16:29 \n", + "30 5 2018-10-01 15:16:29 \n", + "31 5 2018-10-01 15:16:29 " + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "print(\"Output:\")\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Simulation Execution 2: Pairwise Execution\n", + "\n", + "multi_proc: [, ]\n" + ] + } + ], + "source": [ + "print(\"Simulation Execution 2: Pairwise Execution\")\n", + "print()\n", + "multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc)\n", + "run2 = Executor(exec_context=multi_proc_ctx, configs=configs)\n", + "results = []\n", + "tensor_fields = []\n", + "for raw_result, raw_tensor_field in run2.main():\n", + " results.append(pd.DataFrame(raw_result))\n", + " tensor_fields.append(pd.DataFrame(raw_tensor_field))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tensor Field A:\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
b1b2s1s2es1es2es3m
0<function b1m1 at 0x109f25d90><function b2m1 at 0x10a2fda60><function s1m1 at 0x10a2fdd08><function s2m1 at 0x10a2fdd90><function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...1
1<function b1m2 at 0x10a2fdae8><function b2m2 at 0x10a2fdb70><function s1m2 at 0x10a2fde18><function s2m2 at 0x10a2fdea0><function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...2
2<function b1m3 at 0x10a2fdbf8><function b2m3 at 0x10a2fdc80><function s1m3 at 0x10a2fdf28><function s2m3 at 0x10a308048><function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...3
\n", + "
" + ], + "text/plain": [ + " b1 b2 \\\n", + "0 \n", + "1 \n", + "2 \n", + "\n", + " s1 s2 \\\n", + "0 \n", + "1 \n", + "2 \n", + "\n", + " es1 \\\n", + "0 ._curried at 0x10a30... \n", + "1 ._curried at 0x10a30... \n", + "2 ._curried at 0x10a30... \n", + "\n", + " es2 \\\n", + "0 ._curried at 0x10a30... \n", + "1 ._curried at 0x10a30... \n", + "2 ._curried at 0x10a30... \n", + "\n", + " es3 m \n", + "0 ._curried at 0x10a30... 1 \n", + "1 ._curried at 0x10a30... 2 \n", + "2 ._curried at 0x10a30... 3 " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "print(\"Tensor Field A:\")\n", + "tensor_fields[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Output A:\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
mech_stepruns1s2s3s4time_steptimestamp
001001102018-10-01 15:16:24
1111451012018-10-01 15:16:25
221ab651012018-10-01 15:16:25
331[c, d][30, 300]51012018-10-01 15:16:25
41114510.8846223804995845263476894622018-10-01 15:16:26
521ab6510.8846223804995845263476894622018-10-01 15:16:26
631[c, d][30, 300]510.8846223804995845263476894622018-10-01 15:16:26
71114511.8439037891546010592859424032018-10-01 15:16:27
821ab6511.8439037891546010592859424032018-10-01 15:16:27
931[c, d][30, 300]511.8439037891546010592859424032018-10-01 15:16:27
101114513.8687056777981817566008678242018-10-01 15:16:28
1121ab6513.8687056777981817566008678242018-10-01 15:16:28
1231[c, d][30, 300]513.8687056777981817566008678242018-10-01 15:16:28
131114513.9380958635320972504792206852018-10-01 15:16:29
1421ab6513.9380958635320972504792206852018-10-01 15:16:29
1531[c, d][30, 300]513.9380958635320972504792206852018-10-01 15:16:29
1602001102018-10-01 15:16:24
17121451012018-10-01 15:16:25
1822ab651012018-10-01 15:16:25
1932[c, d][30, 300]51012018-10-01 15:16:25
20121459.45464005238046967249943008922018-10-01 15:16:26
2122ab659.45464005238046967249943008922018-10-01 15:16:26
2232[c, d][30, 300]59.45464005238046967249943008922018-10-01 15:16:26
23121457.99250141557961352525319763532018-10-01 15:16:27
2422ab657.99250141557961352525319763532018-10-01 15:16:27
2532[c, d][30, 300]57.99250141557961352525319763532018-10-01 15:16:27
26121458.77765872647237926847033398342018-10-01 15:16:28
2722ab658.77765872647237926847033398342018-10-01 15:16:28
2832[c, d][30, 300]58.77765872647237926847033398342018-10-01 15:16:28
29121457.81117913728395304481061202852018-10-01 15:16:29
3022ab657.81117913728395304481061202852018-10-01 15:16:29
3132[c, d][30, 300]57.81117913728395304481061202852018-10-01 15:16:29
\n", + "
" + ], + "text/plain": [ + " mech_step run s1 s2 s3 s4 \\\n", + "0 0 1 0 0 1 1 \n", + "1 1 1 1 4 5 10 \n", + "2 2 1 ab 6 5 10 \n", + "3 3 1 [c, d] [30, 300] 5 10 \n", + "4 1 1 1 4 5 10.88462238049958452634768946 \n", + "5 2 1 ab 6 5 10.88462238049958452634768946 \n", + "6 3 1 [c, d] [30, 300] 5 10.88462238049958452634768946 \n", + "7 1 1 1 4 5 11.84390378915460105928594240 \n", + "8 2 1 ab 6 5 11.84390378915460105928594240 \n", + "9 3 1 [c, d] [30, 300] 5 11.84390378915460105928594240 \n", + "10 1 1 1 4 5 13.86870567779818175660086782 \n", + "11 2 1 ab 6 5 13.86870567779818175660086782 \n", + "12 3 1 [c, d] [30, 300] 5 13.86870567779818175660086782 \n", + "13 1 1 1 4 5 13.93809586353209725047922068 \n", + "14 2 1 ab 6 5 13.93809586353209725047922068 \n", + "15 3 1 [c, d] [30, 300] 5 13.93809586353209725047922068 \n", + "16 0 2 0 0 1 1 \n", + "17 1 2 1 4 5 10 \n", + "18 2 2 ab 6 5 10 \n", + "19 3 2 [c, d] [30, 300] 5 10 \n", + "20 1 2 1 4 5 9.454640052380469672499430089 \n", + "21 2 2 ab 6 5 9.454640052380469672499430089 \n", + "22 3 2 [c, d] [30, 300] 5 9.454640052380469672499430089 \n", + "23 1 2 1 4 5 7.992501415579613525253197635 \n", + "24 2 2 ab 6 5 7.992501415579613525253197635 \n", + "25 3 2 [c, d] [30, 300] 5 7.992501415579613525253197635 \n", + "26 1 2 1 4 5 8.777658726472379268470333983 \n", + "27 2 2 ab 6 5 8.777658726472379268470333983 \n", + "28 3 2 [c, d] [30, 300] 5 8.777658726472379268470333983 \n", + "29 1 2 1 4 5 7.811179137283953044810612028 \n", + "30 2 2 ab 6 5 7.811179137283953044810612028 \n", + "31 3 2 [c, d] [30, 300] 5 7.811179137283953044810612028 \n", + "\n", + " time_step timestamp \n", + "0 0 2018-10-01 15:16:24 \n", + "1 1 2018-10-01 15:16:25 \n", + "2 1 2018-10-01 15:16:25 \n", + "3 1 2018-10-01 15:16:25 \n", + "4 2 2018-10-01 15:16:26 \n", + "5 2 2018-10-01 15:16:26 \n", + "6 2 2018-10-01 15:16:26 \n", + "7 3 2018-10-01 15:16:27 \n", + "8 3 2018-10-01 15:16:27 \n", + "9 3 2018-10-01 15:16:27 \n", + "10 4 2018-10-01 15:16:28 \n", + "11 4 2018-10-01 15:16:28 \n", + "12 4 2018-10-01 15:16:28 \n", + "13 5 2018-10-01 15:16:29 \n", + "14 5 2018-10-01 15:16:29 \n", + "15 5 2018-10-01 15:16:29 \n", + "16 0 2018-10-01 15:16:24 \n", + "17 1 2018-10-01 15:16:25 \n", + "18 1 2018-10-01 15:16:25 \n", + "19 1 2018-10-01 15:16:25 \n", + "20 2 2018-10-01 15:16:26 \n", + "21 2 2018-10-01 15:16:26 \n", + "22 2 2018-10-01 15:16:26 \n", + "23 3 2018-10-01 15:16:27 \n", + "24 3 2018-10-01 15:16:27 \n", + "25 3 2018-10-01 15:16:27 \n", + "26 4 2018-10-01 15:16:28 \n", + "27 4 2018-10-01 15:16:28 \n", + "28 4 2018-10-01 15:16:28 \n", + "29 5 2018-10-01 15:16:29 \n", + "30 5 2018-10-01 15:16:29 \n", + "31 5 2018-10-01 15:16:29 " + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "print(\"Output A:\")\n", + "results[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tensor Field B:\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
b1b2s1s2es1es2es3m
0<function b1m1 at 0x10a308488><bound method Identity.b_identity of <SimCAD.c...<function s1m1 at 0x10a308950><function Identity.state_identity.<locals>.<la...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...1
1<function b1m2 at 0x10a308730><bound method Identity.b_identity of <SimCAD.c...<function s1m2 at 0x10a308a60><function Identity.state_identity.<locals>.<la...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...2
2<function b1m3 at 0x10a308840><function b2m3 at 0x10a3088c8><function s1m3 at 0x10a308b70><function s2m3 at 0x10a308bf8><function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...<function curried.<locals>._curried at 0x10a30...3
\n", + "
" + ], + "text/plain": [ + " b1 \\\n", + "0 \n", + "1 \n", + "2 \n", + "\n", + " b2 \\\n", + "0 \n", + "\n", + " s1 \\\n", + "0 \n", + "1 \n", + "2 \n", + "\n", + " s2 \\\n", + "0 .. \n", + "\n", + " es1 \\\n", + "0 ._curried at 0x10a30... \n", + "1 ._curried at 0x10a30... \n", + "2 ._curried at 0x10a30... \n", + "\n", + " es2 \\\n", + "0 ._curried at 0x10a30... \n", + "1 ._curried at 0x10a30... \n", + "2 ._curried at 0x10a30... \n", + "\n", + " es3 m \n", + "0 ._curried at 0x10a30... 1 \n", + "1 ._curried at 0x10a30... 2 \n", + "2 ._curried at 0x10a30... 3 " + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "print(\"Tensor Field B:\")\n", + "tensor_fields[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Output B:\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
mech_stepruns1s2s3s4time_steptimestamp
001001102018-10-01 15:16:24
11110101012018-10-01 15:16:25
221a0101012018-10-01 15:16:25
331[c, d][30, 300]101012018-10-01 15:16:25
4111[30, 300]9.94373317277366997046783581010.4365098505119902050353175622018-10-01 15:16:26
521a[30, 300]9.94373317277366997046783581010.4365098505119902050353175622018-10-01 15:16:26
631[c, d][30, 300]9.94373317277366997046783581010.4365098505119902050353175622018-10-01 15:16:26
7111[30, 300]7.81955677476886926528452637110.5372195281202876186024801332018-10-01 15:16:27
821a[30, 300]7.81955677476886926528452637110.5372195281202876186024801332018-10-01 15:16:27
931[c, d][30, 300]7.81955677476886926528452637110.5372195281202876186024801332018-10-01 15:16:27
10111[30, 300]9.1021758460007533121249253318.57361635768008949978322321242018-10-01 15:16:28
1121a[30, 300]9.1021758460007533121249253318.57361635768008949978322321242018-10-01 15:16:28
1231[c, d][30, 300]9.1021758460007533121249253318.57361635768008949978322321242018-10-01 15:16:28
13111[30, 300]7.4697592395088619727980957658.33579435462959645300709321652018-10-01 15:16:29
1421a[30, 300]7.4697592395088619727980957658.33579435462959645300709321652018-10-01 15:16:29
1531[c, d][30, 300]7.4697592395088619727980957658.33579435462959645300709321652018-10-01 15:16:29
1602001102018-10-01 15:16:24
171210101012018-10-01 15:16:25
1822a0101012018-10-01 15:16:25
1932[c, d][30, 300]101012018-10-01 15:16:25
20121[30, 300]10.502881417158043131365730019.91725851851753992249882685422018-10-01 15:16:26
2122a[30, 300]10.502881417158043131365730019.91725851851753992249882685422018-10-01 15:16:26
2232[c, d][30, 300]10.502881417158043131365730019.91725851851753992249882685422018-10-01 15:16:26
23121[30, 300]9.1949701067745045497220664269.29544573818278309896721217232018-10-01 15:16:27
2422a[30, 300]9.1949701067745045497220664269.29544573818278309896721217232018-10-01 15:16:27
2532[c, d][30, 300]9.1949701067745045497220664269.29544573818278309896721217232018-10-01 15:16:27
26121[30, 300]8.2221862040910078929039996589.25471479697655613481958888342018-10-01 15:16:28
2722a[30, 300]8.2221862040910078929039996589.25471479697655613481958888342018-10-01 15:16:28
2832[c, d][30, 300]8.2221862040910078929039996589.25471479697655613481958888342018-10-01 15:16:28
29121[30, 300]7.4747832170044870609731757978.81306312028134610425625981852018-10-01 15:16:29
3022a[30, 300]7.4747832170044870609731757978.81306312028134610425625981852018-10-01 15:16:29
3132[c, d][30, 300]7.4747832170044870609731757978.81306312028134610425625981852018-10-01 15:16:29
\n", + "
" + ], + "text/plain": [ + " mech_step run s1 s2 s3 \\\n", + "0 0 1 0 0 1 \n", + "1 1 1 1 0 10 \n", + "2 2 1 a 0 10 \n", + "3 3 1 [c, d] [30, 300] 10 \n", + "4 1 1 1 [30, 300] 9.943733172773669970467835810 \n", + "5 2 1 a [30, 300] 9.943733172773669970467835810 \n", + "6 3 1 [c, d] [30, 300] 9.943733172773669970467835810 \n", + "7 1 1 1 [30, 300] 7.819556774768869265284526371 \n", + "8 2 1 a [30, 300] 7.819556774768869265284526371 \n", + "9 3 1 [c, d] [30, 300] 7.819556774768869265284526371 \n", + "10 1 1 1 [30, 300] 9.102175846000753312124925331 \n", + "11 2 1 a [30, 300] 9.102175846000753312124925331 \n", + "12 3 1 [c, d] [30, 300] 9.102175846000753312124925331 \n", + "13 1 1 1 [30, 300] 7.469759239508861972798095765 \n", + "14 2 1 a [30, 300] 7.469759239508861972798095765 \n", + "15 3 1 [c, d] [30, 300] 7.469759239508861972798095765 \n", + "16 0 2 0 0 1 \n", + "17 1 2 1 0 10 \n", + "18 2 2 a 0 10 \n", + "19 3 2 [c, d] [30, 300] 10 \n", + "20 1 2 1 [30, 300] 10.50288141715804313136573001 \n", + "21 2 2 a [30, 300] 10.50288141715804313136573001 \n", + "22 3 2 [c, d] [30, 300] 10.50288141715804313136573001 \n", + "23 1 2 1 [30, 300] 9.194970106774504549722066426 \n", + "24 2 2 a [30, 300] 9.194970106774504549722066426 \n", + "25 3 2 [c, d] [30, 300] 9.194970106774504549722066426 \n", + "26 1 2 1 [30, 300] 8.222186204091007892903999658 \n", + "27 2 2 a [30, 300] 8.222186204091007892903999658 \n", + "28 3 2 [c, d] [30, 300] 8.222186204091007892903999658 \n", + "29 1 2 1 [30, 300] 7.474783217004487060973175797 \n", + "30 2 2 a [30, 300] 7.474783217004487060973175797 \n", + "31 3 2 [c, d] [30, 300] 7.474783217004487060973175797 \n", + "\n", + " s4 time_step timestamp \n", + "0 1 0 2018-10-01 15:16:24 \n", + "1 10 1 2018-10-01 15:16:25 \n", + "2 10 1 2018-10-01 15:16:25 \n", + "3 10 1 2018-10-01 15:16:25 \n", + "4 10.43650985051199020503531756 2 2018-10-01 15:16:26 \n", + "5 10.43650985051199020503531756 2 2018-10-01 15:16:26 \n", + "6 10.43650985051199020503531756 2 2018-10-01 15:16:26 \n", + "7 10.53721952812028761860248013 3 2018-10-01 15:16:27 \n", + "8 10.53721952812028761860248013 3 2018-10-01 15:16:27 \n", + "9 10.53721952812028761860248013 3 2018-10-01 15:16:27 \n", + "10 8.573616357680089499783223212 4 2018-10-01 15:16:28 \n", + "11 8.573616357680089499783223212 4 2018-10-01 15:16:28 \n", + "12 8.573616357680089499783223212 4 2018-10-01 15:16:28 \n", + "13 8.335794354629596453007093216 5 2018-10-01 15:16:29 \n", + "14 8.335794354629596453007093216 5 2018-10-01 15:16:29 \n", + "15 8.335794354629596453007093216 5 2018-10-01 15:16:29 \n", + "16 1 0 2018-10-01 15:16:24 \n", + "17 10 1 2018-10-01 15:16:25 \n", + "18 10 1 2018-10-01 15:16:25 \n", + "19 10 1 2018-10-01 15:16:25 \n", + "20 9.917258518517539922498826854 2 2018-10-01 15:16:26 \n", + "21 9.917258518517539922498826854 2 2018-10-01 15:16:26 \n", + "22 9.917258518517539922498826854 2 2018-10-01 15:16:26 \n", + "23 9.295445738182783098967212172 3 2018-10-01 15:16:27 \n", + "24 9.295445738182783098967212172 3 2018-10-01 15:16:27 \n", + "25 9.295445738182783098967212172 3 2018-10-01 15:16:27 \n", + "26 9.254714796976556134819588883 4 2018-10-01 15:16:28 \n", + "27 9.254714796976556134819588883 4 2018-10-01 15:16:28 \n", + "28 9.254714796976556134819588883 4 2018-10-01 15:16:28 \n", + "29 8.813063120281346104256259818 5 2018-10-01 15:16:29 \n", + "30 8.813063120281346104256259818 5 2018-10-01 15:16:29 \n", + "31 8.813063120281346104256259818 5 2018-10-01 15:16:29 " + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "print(\"Output B:\")\n", + "results[1]" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/simulations/validation/config1.py b/simulations/validation/config1.py index 7bdd5ac..a016842 100644 --- a/simulations/validation/config1.py +++ b/simulations/validation/config1.py @@ -7,6 +7,7 @@ from SimCAD.configuration import Configuration from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \ ep_time_step + seed = { 'z': np.random.RandomState(1), 'a': np.random.RandomState(2), @@ -14,8 +15,8 @@ seed = { 'c': np.random.RandomState(3) } + # Behaviors per Mechanism -# Different return types per mechanism ?? *** No *** def b1m1(step, sL, s): return {'param1': 1} def b2m1(step, sL, s): @@ -31,15 +32,15 @@ def b1m3(step, sL, s): def b2m3(step, sL, s): return {'param1': ['d'], 'param2': np.array([20, 200])} -# deff not more than 2 + # Internal States per Mechanism def s1m1(step, sL, s, _input): y = 's1' - x = _input['param1'] #+ [Coef1 x 5] + x = _input['param1'] return (y, x) def s2m1(step, sL, s, _input): y = 's2' - x = _input['param2'] #+ [Coef2 x 5] + x = _input['param2'] return (y, x) def s1m2(step, sL, s, _input): @@ -60,6 +61,7 @@ def s2m3(step, sL, s, _input): x = _input['param2'] return (y, x) + # Exogenous States proc_one_coef_A = 0.7 proc_one_coef_B = 1.3 @@ -90,6 +92,7 @@ def env_b(x): # def what_ever(x): # return x + 1 + # Genesis States genesis_states = { 's1': Decimal(0.0), @@ -99,6 +102,7 @@ genesis_states = { 'timestamp': '2018-10-01 15:16:24' } + # remove `exo_update_per_ts` to update every ts exogenous_states = exo_update_per_ts( { @@ -108,33 +112,20 @@ exogenous_states = exo_update_per_ts( } ) -# ToDo: make env proc trigger field agnostic -# ToDo: input json into function renaming __name__ + env_processes = { "s3": env_a, "s4": proc_trigger('2018-10-01 15:16:25', env_b) } -# lambdas -# genesis Sites should always be there -# [1, 2] -# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ] - -# [1, 2] = {'b1': ['a'], 'b2', [1]} = -# behavior_ops = [ behavior_to_dict, print_fwd, sum_dict_values ] -# behavior_ops = [foldr(dict_elemwise_sum())] -# behavior_ops = [foldr(lambda a, b: a + b)] - -# need at least 1 behaviour and 1 state function for the 1st mech with behaviors -# mechanisms = {} mechanisms = { "m1": { "behaviors": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, + "b1": b1m1, "b2": b2m1 }, - "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value + "states": { "s1": s1m1, "s2": s2m1 } @@ -161,11 +152,13 @@ mechanisms = { } } + sim_config = { "N": 2, "T": range(5) } + configs.append( Configuration( sim_config=sim_config, @@ -175,4 +168,4 @@ configs.append( env_processes=env_processes, mechanisms=mechanisms ) -) \ No newline at end of file +) diff --git a/simulations/validation/config2.py b/simulations/validation/config2.py index 6b9469e..703dace 100644 --- a/simulations/validation/config2.py +++ b/simulations/validation/config2.py @@ -15,8 +15,8 @@ seed = { 'c': np.random.RandomState(3) } + # Behaviors per Mechanism -# Different return types per mechanism ?? *** No *** def b1m1(step, sL, s): return {'param1': 1} def b2m1(step, sL, s): @@ -27,7 +27,6 @@ def b1m2(step, sL, s): def b2m2(step, sL, s): return {'param1': 'b', 'param2': 4} - def b1m3(step, sL, s): return {'param1': ['c'], 'param2': np.array([10, 100])} def b2m3(step, sL, s): @@ -62,6 +61,7 @@ def s2m3(step, sL, s, _input): x = _input['param2'] return (y, x) + # Exogenous States proc_one_coef_A = 0.7 proc_one_coef_B = 1.3 @@ -92,6 +92,7 @@ def env_b(x): # def what_ever(x): # return x + 1 + # Genesis States genesis_states = { 's1': Decimal(0.0), @@ -101,8 +102,8 @@ genesis_states = { 'timestamp': '2018-10-01 15:16:24' } + # remove `exo_update_per_ts` to update every ts -# why `exo_update_per_ts` here instead of `env_processes` exogenous_states = exo_update_per_ts( { "s3": es3p1, @@ -111,32 +112,20 @@ exogenous_states = exo_update_per_ts( } ) -# make env proc trigger field agnostic + env_processes = { "s3": proc_trigger('2018-10-01 15:16:25', env_a), "s4": proc_trigger('2018-10-01 15:16:25', env_b) } -# lambdas -# genesis Sites should always be there -# [1, 2] -# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ] - -# [1, 2] = {'b1': ['a'], 'b2', [1]} = -# behavior_ops = [behavior_to_dict, print_fwd, sum_dict_values] -# behavior_ops = [foldr(dict_elemwise_sum())] -# behavior_ops = [] - -# need at least 1 behaviour and 1 state function for the 1st mech with behaviors -# mechanisms = {} mechanisms = { "m1": { "behaviors": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, + "b1": b1m1, # "b2": b2m1 }, - "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value + "states": { "s1": s1m1, # "s2": s2m1 } @@ -163,11 +152,13 @@ mechanisms = { } } + sim_config = { "N": 2, "T": range(5) } + configs.append( Configuration( sim_config=sim_config, @@ -177,4 +168,4 @@ configs.append( env_processes=env_processes, mechanisms=mechanisms ) -) \ No newline at end of file +)