├── docs ├── _static │ └── img │ │ ├── ade-l.png │ │ └── schematic.png ├── api │ ├── server.rst │ ├── client.rst │ └── index.rst ├── tutorials │ ├── basic_communication.rst │ └── common_source.rst ├── contributing.rst ├── usage.rst ├── about.rst ├── Makefile ├── installation.rst ├── index.rst └── conf.py ├── .pylintrc ├── example ├── socad_cadence │ ├── script │ │ ├── vars.ocn │ │ ├── loadSimulator.ocn │ │ └── run.ocn │ ├── run_server.sh │ ├── start_cadence.sh │ ├── util.py │ ├── cadence.il │ ├── cadence.py │ └── server.py ├── util.py └── socad_example.py ├── socad ├── __init__.py ├── client.py └── server.py ├── .gitignore ├── setup.py ├── README.md └── LICENSE /docs/_static/img/ade-l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdmfernandes/socad/HEAD/docs/_static/img/ade-l.png -------------------------------------------------------------------------------- /docs/_static/img/schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdmfernandes/socad/HEAD/docs/_static/img/schematic.png -------------------------------------------------------------------------------- /docs/api/server.rst: -------------------------------------------------------------------------------- 1 | Server 2 | ====== 3 | 4 | .. automodule:: socad.server 5 | 6 | .. autoclass:: Server 7 | :members: -------------------------------------------------------------------------------- /docs/api/client.rst: -------------------------------------------------------------------------------- 1 | Client 2 | ====== 3 | 4 | .. automodule:: socad.client 5 | 6 | .. autoclass:: Client 7 | :members: 8 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [BASIC] 2 | # Good variable names which should always be accepted, separated by a comma 3 | good-names=i,j,k,ex,x,y,f,db,s,e,cp,p,si -------------------------------------------------------------------------------- /example/socad_cadence/script/vars.ocn: -------------------------------------------------------------------------------- 1 | desVar( "IB" 100u ) 2 | desVar( "L" 0.28 ) 3 | desVar( "VBIAS" 500m ) 4 | desVar( "W1" 2 ) 5 | desVar( "W2" 6 ) -------------------------------------------------------------------------------- /docs/tutorials/basic_communication.rst: -------------------------------------------------------------------------------- 1 | .. _basic_communication: 2 | 3 | Basic communication between SOCAD and Cadence Virtuoso 4 | ====================================================== 5 | 6 | TODO! -------------------------------------------------------------------------------- /docs/api/index.rst: -------------------------------------------------------------------------------- 1 | .. _library_reference: 2 | 3 | Library Reference 4 | ================= 5 | 6 | Description of the modules, classes and functions contained within SOCAD. 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | client 12 | server 13 | 14 | 15 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | Access the project repository on **Github** at https://github.com/mdmfernandes/socad. 5 | 6 | 1. Fork it! 7 | 2. Create your feature branch: ``git checkout -b my-new-feature`` 8 | 3. Commit your changes: ``git commit -am 'Add some feature'`` 9 | 4. Push to the branch: ``git push origin my-new-feature`` 10 | 5. Submit a pull request :D -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | Usage 2 | ===== 3 | 4 | Import the *Client* or the *Server* to your program using: 5 | 6 | .. code-block:: python 7 | 8 | from socad import Client 9 | from socad import Server 10 | 11 | 12 | The available functions of each class are available in the project `library reference `_. 13 | 14 | The code is provided with a basic example that allows to run circuit simulations in Cadence Virtuoso from the **SOCAD client**. A tutorial of the example can be found `here `_. 15 | -------------------------------------------------------------------------------- /docs/about.rst: -------------------------------------------------------------------------------- 1 | About SOCAD 2 | =========== 3 | 4 | Main Contributors 5 | ----------------- 6 | 7 | * **Miguel Fernandes** - *Initial work* - `mdmfernandes (GitHub) `_ 8 | 9 | Versioning 10 | ---------- 11 | 12 | We use `SemVer `_ for versioning. For the versions available, see the `releases on the project repository `_. 13 | 14 | License 15 | ------- 16 | 17 | This project is licensed under the GPLv3 License - see the project `LICENSE `_ file for details. 18 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = SOCAD 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /example/socad_cadence/script/loadSimulator.ocn: -------------------------------------------------------------------------------- 1 | ; Set up the number notation, precision, etc, of the results 2 | setup(?numberNotation 'engineering) 3 | 4 | ; Simulator and design folders 5 | simulator( 'spectre ) 6 | design("CADENCE_WORKSPACE/simulation/COMMON_SOURCE/spectre/schematic/netlist/netlist") 7 | resultsDir("CADENCE_WORKSPACE/simulation/COMMON_SOURCE/spectre/schematic" ) 8 | modelFile( 9 | '("CADENCE_WORKSPACE/nominal/spectre/nominalwrapper.scs" "") 10 | ) 11 | definitionFile( 12 | "models.scs" 13 | ) 14 | 15 | ; Analysis to perform 16 | analysis('ac ?start "10k" ?stop "1G" ) 17 | analysis('dc ?saveOppoint t ) 18 | envOption( 19 | 'analysisOrder list("dc" "ac") 20 | ) 21 | 22 | ; Other settings 23 | temp( 27 ) 24 | -------------------------------------------------------------------------------- /example/socad_cadence/script/run.ocn: -------------------------------------------------------------------------------- 1 | run() ; run a simulation 2 | 3 | ; Output file 4 | out_file = getShellEnvVar("SOCAD_RESULT_FILE") 5 | outf = outfile(out_file "w") 6 | 7 | ; Simulation results 8 | GAIN = ymax(mag(v("/out" ?result "ac"))) 9 | REG1 = pv("M1.m1" "region" ?result "dcOpInfo") 10 | REG2 = pv("M2.m1" "region" ?result "dcOpInfo") 11 | GBW = (gainBwProd(mag(v("/out" ?result "ac"))) || 0.0) 12 | POWER = (- pv("V0" "pwr" ?result "dcOpInfo")) 13 | 14 | ; Save results to file 15 | fprintf( outf "%s\t%g\n", "GAIN", GAIN) 16 | fprintf( outf "%s\t%d\n", "REG1", REG1) 17 | fprintf( outf "%s\t%d\n", "REG2", REG2) 18 | fprintf( outf "%s\t%g\n", "GBW", GBW) 19 | fprintf( outf "%s\t%e\n", "POWER", POWER) 20 | 21 | close(outf) ; Close the file 22 | -------------------------------------------------------------------------------- /socad/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of SOCAD 2 | # Copyright (C) 2018 Miguel Fernandes 3 | # 4 | # SOCAD is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # SOCAD is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | """SOCAD root package""" 17 | 18 | from .client import Client 19 | from .server import Server 20 | 21 | __all__ = ['Client', 'Server'] 22 | -------------------------------------------------------------------------------- /example/socad_cadence/run_server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # This file is part of SOCAD 3 | # Copyright (C) 2018 Miguel Fernandes 4 | # 5 | # SOCAD is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # SOCAD is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | cadence_py="cadence.py" 19 | 20 | cmd="python $cadence_py" 21 | 22 | # replace the shell with a given program (executing it, not as new process) 23 | exec $cmd 24 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | Requirements 5 | ------------ 6 | 7 | Both **client** and **server** are written in Python 3.6. However, both modules are compatible with Python 2.7 and the **server** was also tested in Python 2.6. 8 | 9 | Install with *pip* 10 | ------------------ 11 | 12 | Although the project is not in PyPI, you can install it using *pip*. Go to the project folder and run: 13 | 14 | .. code-block:: shell 15 | 16 | pip install . 17 | 18 | 19 | **NOTE:** run ``pip install socad`` from the project directory doesn't work because pip will look for the package on PyPi. 20 | 21 | Build from source 22 | ----------------- 23 | 24 | Go to the project folder and run: 25 | 26 | .. code-block:: shell 27 | 28 | python setup.py install 29 | 30 | 31 | Use as local module 32 | ------------------- 33 | 34 | For the provided example, if the Cadence machine does not allow to install the **socad** package from the methods above, the module is loaded from ``examples/socad_cadence/server.py``. 35 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. SOCAD documentation master file, created by 2 | sphinx-quickstart on Sat Oct 13 15:44:08 2018. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | SOCAD documentation 7 | =================== 8 | 9 | SOCAD connects Cadence Virtuoso to a Python client. The communication between both processes is made through a server, using the following mechanisms: 10 | 11 | * **Cadence<->Server**: Inter-process communication (IPC). The server is invoked by Cadence and waits for a client communication. 12 | * **Client<->Server**: Python sockets (more info `here `_). Both processes can be run on the same machine or on different machines, according to the socket type chosen by the user. TCP sockets are used by default. 13 | 14 | By using this library it is possible to control the Cadence environment from an external program. 15 | 16 | This project code is available on **Github** at https://github.com/mdmfernandes/socad. 17 | 18 | * :doc:`installation` 19 | * :doc:`usage` 20 | * :doc:`api/index` 21 | * **Tutorials** 22 | * :doc:`tutorials/basic_communication` 23 | * :doc:`tutorials/common_source` 24 | * :doc:`contributing` 25 | * :doc:`about` 26 | 27 | .. toctree:: 28 | :hidden: 29 | 30 | installation 31 | usage 32 | api/index 33 | tutorials/basic_communication 34 | tutorials/common_source 35 | contributing 36 | about -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | # sphinx 107 | _build/ 108 | 109 | TODO_LIST 110 | 111 | .vscode 112 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # This file is part of SOCAD 3 | # Copyright (C) 2018 Miguel Fernandes 4 | # 5 | # SOCAD is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # SOCAD is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | """Python setup.""" 18 | 19 | from setuptools import setup, find_packages 20 | 21 | with open("README.md", "r") as fh: 22 | long_description = fh.read() 23 | 24 | setup( 25 | name='SOCAD', 26 | version='0.1.0', 27 | description='Connect Cadence Virtuoso to a Python client using TCP sockets.', 28 | long_description=long_description, 29 | long_description_content_type='text/markdown', 30 | author='Miguel Fernandes', 31 | author_email='me@mdmfernandes.com', 32 | url='https://github.com/mdmfernandes/socad', 33 | packages=find_packages(exclude=['example']), 34 | keywords=[ 35 | 'socket communications', 'cadence virtuoso' 36 | ], 37 | platforms=['any'], 38 | license='GPLv3', 39 | classifiers=[ 40 | 'Environment :: Console', 41 | 'Intended Audience :: Science/Research', 42 | 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 43 | 'Operating System :: OS Independent', 44 | 'Programming Language :: Python :: 3.6', 45 | 'Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)' 46 | ], 47 | python_requires='>=3.6', 48 | #install_requires=[] 49 | ) 50 | -------------------------------------------------------------------------------- /example/socad_cadence/start_cadence.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # This file is part of SOCAD 3 | # Copyright (C) 2018 Miguel Fernandes 4 | # 5 | # SOCAD is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # SOCAD is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # Project name 19 | export SOCAD_PROJECT_NAME="project_example" 20 | # Project work space 21 | SOCAD_WORK_SPACE="/home/example/project_ws" 22 | 23 | ## Server info 24 | # Client Address 25 | export SOCAD_CLIENT_ADDR="localhost" 26 | # Client Port 27 | export SOCAD_CLIENT_PORT="4000" 28 | 29 | 30 | ############################################# 31 | # Do not change the code below! # 32 | ############################################# 33 | # Define Paths 34 | export SOCAD_ROOT_DIR="$SOCAD_WORK_SPACE/$SOCAD_PROJECT_NAME" 35 | export SOCAD_SCRIPT_DIR="$SOCAD_ROOT_DIR/script" 36 | 37 | # Create the root dir, if it doesn't exist 38 | if [ ! -d "$SOCAD_ROOT_DIR" ]; then 39 | echo 40 | echo "[INFO] Creating $SOCAD_ROOT_DIR ..." 41 | mkdir $SOCAD_ROOT_DIR 42 | cp -r script/ $SOCAD_ROOT_DIR # Copy the script folder to the project folder 43 | else 44 | echo 45 | echo "[INFO] The directory $SOCAD_ROOT_DIR already exists." 46 | fi 47 | 48 | # Create the results file in the project root directory 49 | touch "$SOCAD_ROOT_DIR/sim_res" 50 | 51 | # Print license 52 | echo 53 | echo "SOCAD Copyright (C) 2018 Miguel Fernandes" 54 | echo "This program comes with ABSOLUTELY NO WARRANTY." 55 | echo "This is free software, and you are welcome to redistribute it under the terms" 56 | echo "of the GNU General Public License as published by the Free Software Foundation," 57 | echo "either version 3 of the License, or (at your option) any later version." 58 | echo "For more information, see " 59 | echo 60 | echo "**********************************************************************" 61 | echo "* Starting Cadence *" 62 | echo "**********************************************************************" 63 | 64 | # Code to run Cadence and the script cadence.il 65 | virtuoso -nograph -restore cadence.il 66 | -------------------------------------------------------------------------------- /example/util.py: -------------------------------------------------------------------------------- 1 | # This file is part of SOCAD 2 | # Copyright (C) 2018 Miguel Fernandes 3 | # 4 | # SOCAD is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # SOCAD is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | """Helpers.""" 17 | 18 | import math 19 | 20 | 21 | def print_menu(): 22 | """Print the program menu and checks for a valid input. 23 | 24 | Returns: 25 | selection {int} -- selected option 26 | """ 27 | menu = {} 28 | menu['1'] = "Load simulator" 29 | menu['2'] = "Update variables and run a simulation" 30 | menu['0'] = "Exit." 31 | 32 | selection = -1 33 | 34 | options = menu.keys() 35 | 36 | print("\n############### SOCAD EXAMPLE ###############") 37 | 38 | for entry in options: 39 | print(f"{entry} - {menu[entry]}") 40 | 41 | while True: 42 | try: 43 | selection = int(input("\n-> Please Select: ")) 44 | 45 | # Check for valid input 46 | if selection >= 0 and selection < len(menu): 47 | break 48 | 49 | except ValueError: # if selection is NaN 50 | pass 51 | 52 | print(f"Invalid option. It must be a number between 0 and {len(menu) - 1}") 53 | 54 | return selection 55 | 56 | 57 | def eng_string(x, sig_figs=3, si=True): 58 | """Returns the input value formatted in a simplified engineering 59 | format, i.e. using an exponent that is a multiple of 3. 60 | 61 | Copied from: link 63 | 64 | Arguments: 65 | x {float|int} -- Value to format 66 | 67 | Keyword Arguments: 68 | sig_figs {int} -- number of significant digits (default: 3) 69 | si {bool} -- use SI suffix for exponent, e.g. k instead of e3, 70 | n instead of e-9 etc. (default: True) 71 | 72 | Returns: 73 | str -- the formatted value 74 | """ 75 | 76 | x = float(x) 77 | sign = '' 78 | if x < 0: 79 | x = -x 80 | sign = '-' 81 | if x == 0: 82 | exp = 0 83 | exp3 = 0 84 | x_3 = 0 85 | else: 86 | exp = int(math.floor(math.log10(x))) 87 | exp3 = exp - (exp % 3) 88 | x_3 = x / (10**exp3) 89 | x_3 = round(x_3, -int(math.floor(math.log10(x_3)) - (sig_figs - 1))) 90 | if x_3 == int(x_3): # prevent from displaying .0 91 | x_3 = int(x_3) 92 | 93 | if si and exp3 >= -24 and exp3 <= 24 and exp3 != 0: 94 | exp3_text = 'yzafpnum kMGTPEZY' [exp3 // 3 + 8] 95 | elif exp3 == 0: 96 | exp3_text = '' 97 | else: 98 | exp3_text = 'e%s' % exp3 99 | 100 | return ('%s%s%s') % (sign, x_3, exp3_text) 101 | -------------------------------------------------------------------------------- /example/socad_cadence/util.py: -------------------------------------------------------------------------------- 1 | # This file is part of SOCAD 2 | # Copyright (C) 2018 Miguel Fernandes 3 | # 4 | # SOCAD is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # SOCAD is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | """Helpers to handle data.""" 17 | 18 | import re 19 | from functools import reduce 20 | 21 | 22 | def get_vars_from_file(fname): 23 | """Get circuit variables from file and store in a dictionary. 24 | 25 | Arguments: 26 | fname {str} -- file path 27 | 28 | Returns: 29 | variables {dict} -- circuit variables 30 | """ 31 | variables = {} 32 | 33 | # Dictionary with metric prefixes 34 | prefix_dict = { 35 | 'f': 'e-15', 36 | 'p': 'e-12', 37 | 'n': 'e-9', 38 | 'u': 'e-6', 39 | 'm': 'e-3', 40 | 'k': 'e3', 41 | 'K': 'e3', # Kilo can be 'k' or 'K' in Cadence 42 | 'M': 'e6', 43 | 'G': 'e9', 44 | 'T': 'e12' 45 | } 46 | 47 | pattern = r'desVar\(\s*\"(?P\w+)\"\s*(?P\S+)\s*\)' 48 | 49 | with open(fname, 'r') as f: 50 | content = f.read() 51 | 52 | for match in re.finditer(pattern, content): 53 | try: # try to convert value to float 54 | value = float(match.group('value')) 55 | except ValueError: 56 | # If fails, replace the prefixes by the respective exponents 57 | value = float(reduce((lambda a, kv: a.replace(*kv)), prefix_dict.items(), 58 | match.group('value'))) 59 | 60 | # Save to dict 61 | variables[match.group('param')] = value 62 | 63 | return variables 64 | 65 | 66 | def store_vars_in_file(variables, fname): 67 | """Store circuit variables in a file. 68 | 69 | Arguments: 70 | var {dict} -- dictionary with the circuit variables 71 | fname {str} -- file name 72 | """ 73 | with open(fname, 'w') as f: 74 | # Iterate over the dictionary and save variables to file 75 | for key, val in variables.items(): 76 | f.write("desVar(\t \"{0}\" {1}\t)\n".format(key, val)) 77 | 78 | 79 | def get_results_from_file(fname): 80 | """Get simulation results from file and store in a dictionary. 81 | 82 | Arguments: 83 | fname {str} -- file path 84 | n_sims {int} -- number of simulations runing in parallel 85 | 86 | Returns: 87 | results_list {list} -- simulation results in a list of dictionaries 88 | """ 89 | results = {} 90 | 91 | pattern = r'\s*(?P\S+)\s+(?P\S+)' 92 | 93 | with open(fname, 'r') as f: 94 | content = f.read() 95 | 96 | for match in re.finditer(pattern, content): 97 | # Save to dict 98 | results[match.group('param')] = float(match.group('value')) 99 | 100 | return results 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SOCAD 2 | 3 | Client: [![Python -V client](https://img.shields.io/badge/python-3.6%2B-blue.svg)](https://www.python.org/downloads/release/python-360/) 4 | Server: [![Python -V server](https://img.shields.io/badge/python-2.6%2B-blue.svg)](https://www.python.org/downloads/release/python-260/) [![Documentation Status](https://readthedocs.org/projects/socad/badge/?version=latest)](https://socad.readthedocs.io/en/latest/?badge=latest) 5 | [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://github.com/mdmfernandes/socad/blob/master/LICENSE) 6 | 7 | ## This project is no longer maintained, as I no longer have access to Cadence Virtuoso. If you are interested in contributing and have any questions, feel free to contact me. 8 | 9 | **SOCAD** connects Cadence Virtuoso to a Python client. The communication between both processes is made through a server, using the following mechanisms: 10 | 11 | * **Cadence<->Server**: Inter-process communication (IPC). The server is invoked by Cadence and waits for a client communication. 12 | * **Client<->Server**: Sockets (more info [here](https://docs.python.org/3/library/socket.html)). Both processes can be run on the same machine or on different machines, according to the socket type chosen by the user. TCP sockets are used by default. 13 | 14 | By using this library it is possible to control the Cadence environment from an external program. 15 | 16 | ## Installation 17 | 18 | The installation needs to be performed both in the **client** and the **server**. We recommend you to use *pip* to install SOCAD in your system. 19 | 20 | ### Install with *pip* 21 | 22 | Although the project is not in PyPI, you can install it using *pip*. Go to the project folder and run: 23 | 24 | ```shell 25 | pip install . 26 | ``` 27 | 28 | **NOTE:** run `pip install socad` from the project directory doesn't work because pip will look for the package on PyPi. 29 | 30 | ### Build from source 31 | 32 | Go to the project folder and run: 33 | 34 | ```shell 35 | python setup.py install 36 | ``` 37 | 38 | ### Use as local module 39 | 40 | If the Cadence machine does not allow to install the **socad** package from the methods above, the module is loaded from `examples/socad_cadence/server.py`. 41 | 42 | ## Usage 43 | 44 | Import the *Client* or the *Server* to your program using: 45 | 46 | ```python 47 | from socad import Client 48 | from socad import Server 49 | ``` 50 | 51 | The available functions of each class are available in the project [library reference](https://socad.readthedocs.io/en/latest/api/index.html). 52 | 53 | A complete demonstration of the program usage can be found in the example below. 54 | 55 | ## Example 56 | 57 | The provided example runs simulations in Cadence Virtuoso from a client in a different machine (connected through *ssh*), by executing OCEAN scripts provided by the user. 58 | 59 | For more a step by step guide of the example, check [this tutorial](https://socad.readthedocs.io/en/latest/tutorials/common_source.html). 60 | 61 | ## Versioning 62 | 63 | We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [releases on the project repository](https://github.com/mdmfernandes/socad/releases/). 64 | 65 | ## Main Contributors 66 | 67 | * **Miguel Fernandes** - *Initial work* - [mdmfernandes](https://github.com/mdmfernandes) 68 | 69 | ## Contributing 70 | 71 | 1. Fork it! 72 | 2. Create your feature branch: `git checkout -b my-new-feature` 73 | 3. Commit your changes: `git commit -am 'Add some feature'` 74 | 4. Push to the branch: `git push origin my-new-feature` 75 | 5. Submit a pull request :D 76 | 77 | ## License 78 | 79 | This project is licensed under the GPLv3 License - see the project [LICENSE](https://github.com/mdmfernandes/socad/blob/master/LICENSE) file for details. 80 | -------------------------------------------------------------------------------- /example/socad_cadence/cadence.il: -------------------------------------------------------------------------------- 1 | ; This file is part of SOCAD 2 | ; Copyright (C) 2018 Miguel Fernandes 3 | ; 4 | ; SOCAD is free software: you can redistribute it and/or modify 5 | ; it under the terms of the GNU General Public License as published by 6 | ; the Free Software Foundation, either version 3 of the License, or 7 | ; (at your option) any later version. 8 | ; 9 | ; SOCAD is distributed in the hope that it will be useful, 10 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ; GNU General Public License for more details. 13 | 14 | ; You should have received a copy of the GNU General Public License 15 | ; along with this program. If not, see . 16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 17 | ;; Simulation related functions ;; 18 | ;; - Load the simulator ;; 19 | ;; - Update design variables ;; 20 | ;; - Run a simulation from ADE ;; 21 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 22 | 23 | ;; Load the simulator by running the provided file. 24 | ;; 25 | ;; @param {string} loadFile - name of file to load the simulator from 26 | ;; 27 | procedure( loadSimulator(loadFile) 28 | 29 | print("[INFO] Loading the simulator") 30 | ; Load the simulator 31 | load(loadFile) 32 | 33 | ; Send the function status to the server 34 | msg = "loadSimulator_OK" 35 | ) 36 | 37 | ;; Update the circuit design variables and run a simulation. 38 | ;; 39 | ;; @param {string} runFile - name of file to run the simulation from 40 | ;; @param {string} varFile - name of file with the circuit design variables 41 | ;; @param {string} resultFile - name of file to store the simulation results 42 | ;; 43 | procedure( updateAndRun(runFile varFile resultFile) 44 | 45 | ; Load the circuit variables 46 | load(varFile) 47 | 48 | ; Set the results file 49 | setShellEnvVar(resultFile) 50 | 51 | ; run the simulation 52 | load(runFile) 53 | 54 | ; Send the function status to the server 55 | msg = "updateAndRun_OK" 56 | ) 57 | 58 | 59 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 60 | ;; Server related functions ;; 61 | ;; - Start python server ;; 62 | ;; - Handle server requests ;; 63 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 64 | 65 | ;; Send data to server. First it sends the data size and then the message 66 | ;; 67 | ;; @param {number} cid - Server handle 68 | ;; @param {string} msg - data to send 69 | ;; 70 | procedure( sendData(cid msg) 71 | printf("[INFO] Sending message to server: %s\n" msg) 72 | ; First sends the size of the data to send 73 | ipcWriteProcess(cid sprintf(nil "%d\n" strlen(msg))) 74 | ; Then sends the data 75 | ipcWriteProcess(cid msg) 76 | ) 77 | 78 | 79 | ;; Handles requests from the server (through stdout) 80 | ;; 81 | ;; @param {number} cid - Server handle 82 | ;; @param {string} request - Request received from the server 83 | ;; 84 | procedure( requestHandler(cid request) 85 | let( (result resultStr) 86 | if( serverHasStarted <= 0 then 87 | if( request == "Python server has started!" then 88 | serverHasStarted = 1 89 | printf("[INFO] Cadence is connected to server! Waiting for a connection from the client...\n") 90 | else 91 | printf("[INFO] Waiting for server... Message: %s\n" request) 92 | ) 93 | else ; if the server is running 94 | ; if the request is to call a function 95 | if( rexMatchp("(.*)" request) then 96 | ; The "errsetstring" evaluates the request and returns the result, 97 | ; if valid, or an error message. E.g. if the request is a function, 98 | ; it executes the function and returns the result. 99 | if( result = errsetstring(request 't) then 100 | sprintf(resultStr "%L\n" car(result)) 101 | else 102 | sprintf(resultStr "%s\n" car(nthelem(5 errset.errset))) 103 | ) 104 | sendData(cid resultStr) 105 | else 106 | printf("[INFOs] %s\n" request) 107 | ) 108 | ) 109 | ) 110 | ) 111 | 112 | 113 | ;; Handles server errors (through the stderr) 114 | ;; 115 | ;; @param {number} cid - Server handle 116 | ;; @param {string} errorMessage - Error message received from the server 117 | ;; 118 | procedure( errorHandler(cid errorMessage) 119 | warn("%s\n" errorMessage) 120 | ) 121 | 122 | 123 | ;; Handles the server shutdown 124 | ;; 125 | ;; @param {number} cid - Server handle 126 | ;; @param {number} exitStatus - Server exit status 127 | ;; 128 | procedure( exitHandler(cid exitStatus) 129 | printf("Server has stopped with the exit code %d. I'm out!!!\n" exitStatus) 130 | hiRegTimer("exit()", 10) ; exit Cadence 131 | ) 132 | 133 | 134 | ;; Starts the python server as child process for inter-process communication 135 | ;; 136 | procedure( startServer() 137 | printf("[INFO] Starting server process...\n") 138 | serverHasStarted = 0 139 | cid = ipcBeginProcess("sh run_server.sh" "" 'requestHandler 'errorHandler 'exitHandler "") 140 | msg = "Python server has started!\n" 141 | ipcWriteProcess(cid sprintf(nil "%d\n" strlen(msg))) 142 | ipcWriteProcess(cid msg) 143 | ) 144 | 145 | serverHasStarted = 0 146 | ; Starts the server 147 | startServer() -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Configuration file for the Sphinx documentation builder. 4 | # 5 | # This file does only contain a selection of the most common options. For a 6 | # full list see the documentation: 7 | # http://www.sphinx-doc.org/en/master/config 8 | 9 | # -- Path setup -------------------------------------------------------------- 10 | 11 | # If extensions (or modules to document with autodoc) are in another directory, 12 | # add these directories to sys.path here. If the directory is relative to the 13 | # documentation root, use os.path.abspath to make it absolute, like shown here. 14 | 15 | import os 16 | import sys 17 | sys.path.insert(0, os.path.abspath('..')) 18 | 19 | 20 | # -- Project information ----------------------------------------------------- 21 | 22 | project = 'SOCAD' 23 | copyright = '2018 Miguel Fernandes' 24 | author = 'Miguel Fernandes' 25 | 26 | # The short X.Y version 27 | version = '' 28 | # The full version, including alpha/beta/rc tags 29 | release = '0.1.0' 30 | 31 | 32 | # -- General configuration --------------------------------------------------- 33 | 34 | # If your documentation needs a minimal Sphinx version, state it here. 35 | # 36 | # needs_sphinx = '1.0' 37 | 38 | # Add any Sphinx extension module names here, as strings. They can be 39 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 40 | # ones. 41 | extensions = [ 42 | 'sphinx.ext.autodoc', 43 | 'sphinx.ext.intersphinx', 44 | 'sphinx.ext.githubpages', 45 | 'sphinx.ext.napoleon' 46 | ] 47 | 48 | # Add any paths that contain templates here, relative to this directory. 49 | templates_path = ['_templates'] 50 | 51 | # The suffix(es) of source filenames. 52 | # You can specify multiple suffix as a list of string: 53 | # 54 | # source_suffix = ['.rst', '.md'] 55 | source_suffix = '.rst' 56 | 57 | # The master toctree document. 58 | master_doc = 'index' 59 | 60 | # The language for content autogenerated by Sphinx. Refer to documentation 61 | # for a list of supported languages. 62 | # 63 | # This is also used if you do content translation via gettext catalogs. 64 | # Usually you set "language" from the command line for these cases. 65 | language = None 66 | 67 | # List of patterns, relative to source directory, that match files and 68 | # directories to ignore when looking for source files. 69 | # This pattern also affects html_static_path and html_extra_path . 70 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 71 | 72 | # The name of the Pygments (syntax highlighting) style to use. 73 | pygments_style = 'default' 74 | 75 | 76 | # -- Options for HTML output ------------------------------------------------- 77 | 78 | # The theme to use for HTML and HTML Help pages. See the documentation for 79 | # a list of builtin themes. 80 | # 81 | html_theme = 'nature' 82 | 83 | # Theme options are theme-specific and customize the look and feel of a theme 84 | # further. For a list of options available for each theme, see the 85 | # documentation. 86 | 87 | html_theme_options = {"body_max_width": "1050px"} 88 | 89 | # Add any paths that contain custom static files (such as style sheets) here, 90 | # relative to this directory. They are copied after the builtin static files, 91 | # so a file named "default.css" will overwrite the builtin "default.css". 92 | html_static_path = ['_static'] 93 | 94 | # Custom sidebar templates, must be a dictionary that maps document names 95 | # to template names. 96 | # 97 | # The default sidebars (for documents that don't match any pattern) are 98 | # defined by theme itself. Builtin themes are using these templates by 99 | # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', 100 | # 'searchbox.html']``. 101 | # 102 | # html_sidebars = {} 103 | 104 | 105 | # -- Options for HTMLHelp output --------------------------------------------- 106 | 107 | # Output file base name for HTML help builder. 108 | htmlhelp_basename = 'SOCADdoc' 109 | 110 | 111 | # -- Options for LaTeX output ------------------------------------------------ 112 | 113 | latex_elements = { 114 | # The paper size ('letterpaper' or 'a4paper'). 115 | # 116 | # 'papersize': 'letterpaper', 117 | 118 | # The font size ('10pt', '11pt' or '12pt'). 119 | # 120 | # 'pointsize': '10pt', 121 | 122 | # Additional stuff for the LaTeX preamble. 123 | # 124 | # 'preamble': '', 125 | 126 | # Latex figure (float) alignment 127 | # 128 | # 'figure_align': 'htbp', 129 | } 130 | 131 | # Grouping the document tree into LaTeX files. List of tuples 132 | # (source start file, target name, title, 133 | # author, documentclass [howto, manual, or own class]). 134 | latex_documents = [ 135 | (master_doc, 'SOCAD.tex', 'SOCAD Documentation', 136 | 'Miguel Fernandes', 'manual'), 137 | ] 138 | 139 | 140 | # -- Options for manual page output ------------------------------------------ 141 | 142 | # One entry per manual page. List of tuples 143 | # (source start file, name, description, authors, manual section). 144 | man_pages = [ 145 | (master_doc, 'socad', 'SOCAD Documentation', 146 | [author], 1) 147 | ] 148 | 149 | 150 | # -- Options for Texinfo output ---------------------------------------------- 151 | 152 | # Grouping the document tree into Texinfo files. List of tuples 153 | # (source start file, target name, title, author, 154 | # dir menu entry, description, category) 155 | texinfo_documents = [ 156 | (master_doc, 'SOCAD', 'SOCAD Documentation', 157 | author, 'SOCAD', 'One line description of project.', 158 | 'Miscellaneous'), 159 | ] 160 | 161 | 162 | # -- Extension configuration ------------------------------------------------- 163 | 164 | # -- Options for intersphinx extension --------------------------------------- 165 | 166 | # Example configuration for intersphinx: refer to the Python standard library. 167 | intersphinx_mapping = {'https://docs.python.org/': None} -------------------------------------------------------------------------------- /example/socad_cadence/cadence.py: -------------------------------------------------------------------------------- 1 | # This file is part of SOCAD 2 | # Copyright (C) 2018 Miguel Fernandes 3 | # 4 | # SOCAD is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # SOCAD is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | """This module handles the communication between Cadence and the server.""" 17 | 18 | import os 19 | import sys 20 | 21 | import util 22 | 23 | # Try to import 'Server' from the global package 'socad' 24 | try: 25 | from socad import Server 26 | except ImportError as err: 27 | # If can't import from the global package 28 | try: # Try to import from server.py 29 | from interface.server import Server 30 | except ImportError as err: 31 | # If can't import the package, quit the program 32 | print("[ERROR] {0}. Exiting...".format(err)) 33 | sys.exit('1') 34 | 35 | # Simulator files 36 | SIM_FILE = os.environ.get('SOCAD_SCRIPT_DIR') + "/loadSimulator.ocn" 37 | RUN_FILE = os.environ.get('SOCAD_SCRIPT_DIR') + "/run.ocn" 38 | VAR_FILE = os.environ.get('SOCAD_SCRIPT_DIR') + '/vars.ocn' 39 | OUT_FILE = os.environ.get('SOCAD_ROOT_DIR') + "/sim_res" 40 | 41 | 42 | def process_skill_request(req): 43 | """Process a skill request from the client. 44 | 45 | Based on the given request object, returns the skill expression to be 46 | evaluated by Cadence. 47 | 48 | Arguments: 49 | req {dict} -- request object 50 | 51 | Raises: 52 | KeyError -- if the input request format is invalid 53 | TypeError -- if the type parameter of the received object is invalid 54 | 55 | Returns: 56 | str -- expression to be evaluated by Cadence 57 | """ 58 | try: 59 | type_ = req['type'] 60 | data = req['data'] 61 | except KeyError as err: # if the key does not exist 62 | raise KeyError(err) 63 | 64 | if type_ == 'info' and data.lower() == 'exit': 65 | res = 'exit' 66 | 67 | elif type_ == 'loadSimulator': 68 | res = 'loadSimulator( "{0}")'.format(SIM_FILE) 69 | 70 | elif type_ == 'updateAndRun': 71 | # Store circuit variables in file 72 | util.store_vars_in_file(data, VAR_FILE) 73 | res = 'updateAndRun("{0}" "{1}" "SOCAD_RESULT_FILE={2}")'.format(RUN_FILE, VAR_FILE, OUT_FILE) 74 | else: 75 | raise TypeError("Invalid object received from the client.") 76 | 77 | return res 78 | 79 | 80 | def process_skill_response(msg): 81 | """Process the skill response from Cadence. 82 | 83 | Arguments: 84 | msg {str} -- cadence response 85 | 86 | Raises: 87 | TypeError -- if the input message format is invalid 88 | 89 | Returns: 90 | tuple -- response type (type_) and response object (obj) 91 | """ 92 | if "loadSimulator_OK" in msg: 93 | type_ = 'loadSimulator' 94 | # Get the original circuit variables (user defined) to send 95 | var = util.get_vars_from_file(VAR_FILE) 96 | obj = var 97 | 98 | elif "updateAndRun_OK" in msg: 99 | type_ = 'updateAndRun' 100 | # Get the results from file 101 | obj = util.get_results_from_file(OUT_FILE) 102 | 103 | else: 104 | raise TypeError("Invalid message received from Cadence.") 105 | 106 | return type_, obj 107 | 108 | 109 | def main(): 110 | """Module main function.""" 111 | try: 112 | # Start the server 113 | server = Server(sys) 114 | except OSError as err: 115 | server.send_warn("[SOCKET ERROR] {0}".format(err)) 116 | return 1 117 | 118 | host = os.environ.get('SOCAD_CLIENT_ADDR') 119 | port = int(os.environ.get('SOCAD_CLIENT_PORT')) 120 | 121 | try: 122 | addr = server.run(host, port) 123 | 124 | # Log the connectivity to Cadence 125 | log = "Connected to client with address {0}:{1}".format(addr[0], addr[1]) 126 | server.send_skill(log) 127 | 128 | except IOError as err: # NOTE: "ConnectionError" nao existe no Python 2 -_- 129 | server.send_warn("[CONNECTION ERROR] {0}".format(err)) 130 | return 2 131 | 132 | code = 0 # Return code 133 | try: 134 | while True: 135 | # Wait for a client request 136 | req = server.recv_data() 137 | 138 | # Process the client request 139 | expr = process_skill_request(req) 140 | 141 | if expr == 'exit': 142 | break 143 | else: 144 | # Send the request to Cadence 145 | server.send_skill(expr) 146 | # Wait for a response from Cadence 147 | res = server.recv_skill() 148 | # Process the Cadence response 149 | typ, obj = process_skill_response(res) 150 | # Send the processed response to the client 151 | server.send_data(dict(type=typ, data=obj)) 152 | 153 | except IOError as err: # NOTE: "ConnectionError" nao existe no Python 2 -_- 154 | server.send_warn("[CONNECTION ERROR] {0}".format(err)) 155 | code = 3 156 | except TypeError as err: 157 | server.send_warn("[TYPE ERROR] {0}".format(err)) 158 | code = 4 159 | except KeyError as err: 160 | server.send_warn("[KEY ERROR] {0}".format(err)) 161 | code = 5 162 | 163 | server.close(code) 164 | return code 165 | 166 | 167 | if __name__ == "__main__": 168 | sys.exit(main()) 169 | -------------------------------------------------------------------------------- /socad/client.py: -------------------------------------------------------------------------------- 1 | # This file is part of SOCAD 2 | # Copyright (C) 2018 Miguel Fernandes 3 | # 4 | # SOCAD is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # SOCAD is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | """Client that communicates with Cadence through a server.""" 17 | 18 | import json 19 | import socket 20 | import struct 21 | 22 | 23 | class Client: 24 | """A client that handles Cadence Virtuoso requests. 25 | 26 | This client receives data from Cadence (through a server) and processes 27 | that data. It then gather the processed data and send it back to Cadence 28 | through the server. It sends data in JSON format and the received data 29 | should also be serialized in JSON. 30 | 31 | Arguments: 32 | sock (object, optional): socket to use for the connection 33 | (default: None). 34 | """ 35 | 36 | def __init__(self, sock=None): 37 | """Create the client socket.""" 38 | if sock is None: 39 | self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 40 | else: 41 | self.socket = sock 42 | 43 | def run(self, host, port): 44 | """Start the client. 45 | 46 | Arguments: 47 | host (str): remote socket IP address. 48 | port (int): remote socket port. 49 | 50 | Raises: 51 | ConnectionError: if can't connect to server. 52 | 53 | Returns: 54 | list: remote socket name. 55 | """ 56 | try: 57 | # Try to connect to the specified server 58 | self.socket.connect((host, port)) 59 | except OSError as err: 60 | raise ConnectionError(err) 61 | 62 | # The next function calls don't need a try statement because if they 63 | # have an exception the error will be caught in the function that 64 | # calls this one 65 | 66 | # Send the local socket name to the server 67 | self.send_data(dict(type="info", data=self.socket.getsockname())) 68 | 69 | # Receive the remote socket name 70 | return self.recv_data()["data"] 71 | 72 | def send_data(self, obj): 73 | """Send an object through a socket. 74 | 75 | 1 - Serialize the object in JSON and encode the string; 76 | 77 | 2 - pack the serialized object length in an unsigned int (I)[4 bytes], 78 | and big-endian byte order (>) (this way the *object size* message 79 | has always the same size); 80 | 81 | 3 - send the data. 82 | 83 | Arguments: 84 | obj (dict): object to send. 85 | 86 | Raises: 87 | TypeError: if the object is not serializable in JSON. 88 | ConnectionError: if the socket connection is broken. 89 | """ 90 | # Serialize the object in JSON and encode the string as a bytes object 91 | try: 92 | serialized = json.dumps(obj).encode() 93 | except (TypeError, ValueError): 94 | raise TypeError("It can only send JSON-serializable data") 95 | 96 | serialized_len = len(serialized) # String length 97 | 98 | # Packed string length 99 | pack_serialized_len = struct.pack(">I", serialized_len) 100 | 101 | # Data to send 102 | data = pack_serialized_len + serialized 103 | 104 | total_sent = 0 105 | 106 | while total_sent < serialized_len: 107 | sent = self.socket.send(data[total_sent:]) 108 | 109 | if not sent: 110 | raise ConnectionError("Socket connection broken while sending data") 111 | 112 | total_sent += sent 113 | 114 | def recv_data(self): 115 | """Receive an object through a socket. 116 | 117 | 1 - Receive the first 4 bytes of data, which contains the data length; 118 | 119 | 2 - Receive the data, serialized in JSON, and decode it; 120 | 121 | 3 - Convert the received data in an object. 122 | 123 | Raises: 124 | ConnectionError: if the socket connection is broken. 125 | TypeError: if the received data is not in JSON format. 126 | 127 | Returns: 128 | dict: decoded and de-serialized received data. 129 | """ 130 | data_len = self.recv_bytes(4) 131 | 132 | if not data_len: 133 | raise ConnectionError("Socket connection broken while receiving data") 134 | 135 | # >I means a unsigned int (I) (with four bytes length) and big-endian byte order (>) 136 | msglen = struct.unpack(">I", data_len)[0] 137 | 138 | serialized = self.recv_bytes(msglen).decode() 139 | 140 | try: 141 | obj = json.loads(serialized) 142 | except (TypeError, ValueError): 143 | raise TypeError("Received data is not in JSON format") 144 | 145 | return obj 146 | 147 | def recv_bytes(self, n_bytes): 148 | """Receive a specified number of bytes through a socket. 149 | 150 | Arguments: 151 | n_bytes (int): number of bytes to receive. 152 | 153 | Raises: 154 | ConnectionError: if the socket connection is broken. 155 | 156 | Returns: 157 | bytes: received bytes stream. 158 | """ 159 | data = b"" # Bytes literal 160 | data_len = len(data) 161 | 162 | while data_len < n_bytes: 163 | packet = self.socket.recv(min(n_bytes - data_len, 1024)) 164 | 165 | if not packet: 166 | raise ConnectionError("Socket connection broken while receiving a byte") 167 | 168 | data_len += len(packet) 169 | data += packet 170 | 171 | return data 172 | 173 | def close(self): 174 | """Close the socket.""" 175 | self.socket.close() 176 | -------------------------------------------------------------------------------- /example/socad_example.py: -------------------------------------------------------------------------------- 1 | # This file is part of SOCAD 2 | # Copyright (C) 2018 Miguel Fernandes 3 | # 4 | # SOCAD is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # SOCAD is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | """Main module.""" 17 | 18 | import sys 19 | 20 | from util import print_menu 21 | from socad import Client 22 | 23 | 24 | def load_simulator(client): 25 | """Load the Cadence simulator. 26 | 27 | This task is performed once per run (contrary to the Cadence ADE) that 28 | loads the simulator everytime we run a simulation, which is very 29 | inefficient. 30 | 31 | Arguments: 32 | client {handler} -- client that communicates with the simulator 33 | 34 | Raises: 35 | TypeError -- if the server response is not from the expected type 36 | 37 | Returns: 38 | dict -- circuit design variables 39 | """ 40 | req = dict(type='loadSimulator', data=None) 41 | client.send_data(req) 42 | res = client.recv_data() 43 | 44 | try: 45 | res_type = res['type'] 46 | data = res['data'] 47 | except KeyError as err: # if the key does not exist 48 | raise KeyError(err) 49 | 50 | if res_type != 'loadSimulator': 51 | raise TypeError('The response type should be "loadSimulator"!!!') 52 | 53 | return data 54 | 55 | 56 | def process_server_response(res): 57 | """Process a response received from the server. 58 | 59 | Args: 60 | res (dict): server response 61 | 62 | Raises: 63 | KeyError: if the received data is corrupted 64 | KeyError: if the received data is invalid 65 | 66 | Returns: 67 | tuple: type of response, received data 68 | """ 69 | try: 70 | typ = res['type'] 71 | data = res['data'] 72 | except KeyError as err: # if the key does not exist 73 | raise KeyError(err) 74 | 75 | # If response type is loadSimulator we want to receive the original (user defined) 76 | # circuit variables. 77 | if 'loadSimulator' in typ: 78 | print("\nSimulator loaded with success! Received variables:") 79 | for key, val in data.items(): 80 | print(f"Variable: {key} - Value: {val}") 81 | 82 | return 'vars', data 83 | # If response type is updateAndRun we want to receive simulation results to 84 | # fed into the optimizer 85 | elif 'updateAndRun' in typ: 86 | print('\nReceived updateAndRun from Cadence') 87 | 88 | print(f"Simulation results: {data}") 89 | 90 | return 'results', data 91 | else: 92 | raise KeyError("Invalid data received from server.") 93 | 94 | 95 | def main(): 96 | """Main function""" 97 | 98 | # Print license 99 | print("\nSOCAD Copyright (C) 2018 Miguel Fernandes") 100 | print("This program comes with ABSOLUTELY NO WARRANTY.") 101 | print("This is free software, and you are welcome to redistribute it under the terms") 102 | print("of the GNU General Public License as published by the Free Software Foundation,") 103 | print("either version 3 of the License, or (at your option) any later version.") 104 | print("For more information, see \n") 105 | 106 | try: 107 | print("Starting client...") 108 | client = Client() 109 | except OSError as err: 110 | print(f"[SOCKET ERROR] {err}") 111 | print("\n**** Ending program... Bye! ****") 112 | return 1 113 | 114 | host = "localhost" 115 | port = 3000 116 | 117 | try: 118 | print("Connecting to server...") 119 | addr = client.run(host, port) 120 | print(f"[INFO] Connected to server with the address {addr[0]}:{addr[1]}") 121 | 122 | data = {} 123 | variables = {} # Circuit variables (to be optimized) 124 | 125 | # Main loop 126 | while True: 127 | option = print_menu() 128 | 129 | if option == 1: 130 | req = dict(type='loadSimulator', data='ola') 131 | elif option == 2: 132 | print("\nSending updated variables...") 133 | for key, val in variables.items(): 134 | print(f"Key: {key} - Val:{val}") 135 | req = dict(type='updateAndRun', data=variables) 136 | else: 137 | if option: # if option != 0 138 | print("Wrong option!!!") 139 | print("Shutting down.") 140 | req = dict(type='info', data='exit') 141 | client.send_data(req) 142 | break 143 | 144 | # Send data to server 145 | client.send_data(req) 146 | 147 | # Wait for data from server 148 | res = client.recv_data() 149 | 150 | typ, data = process_server_response(res) 151 | 152 | if typ == 'vars': 153 | variables = data 154 | elif typ == 'results': 155 | # results = data 156 | for key, val in variables.items(): 157 | variables[key] = val * 1.1 158 | else: 159 | raise KeyError(f"Invalid data type: {typ}") 160 | 161 | # End the program 162 | req = dict(type='info', data='exit') 163 | client.send_data(req) 164 | 165 | except ConnectionError as err: 166 | print(f"[CONNECTION ERROR] {err}") 167 | return 2 168 | except (TypeError, ValueError) as err: 169 | print(f"[TYPE/VALUE ERROR] {err}") 170 | return 3 171 | except KeyError as err: 172 | print(f"[KEY ERROR] {err}") 173 | return 4 174 | finally: 175 | print("\n**** Closing socket and ending program... Bye! ****") 176 | client.close() # Close the client socket 177 | 178 | return 0 179 | 180 | 181 | if __name__ == "__main__": 182 | sys.exit(main()) 183 | -------------------------------------------------------------------------------- /example/socad_cadence/server.py: -------------------------------------------------------------------------------- 1 | # This file is part of SOCAD 2 | # Copyright (C) 2018 Miguel Fernandes 3 | # 4 | # SOCAD is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # SOCAD is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | """Server that stands between the client and cadence.""" 17 | 18 | import json 19 | import socket 20 | import struct 21 | import time 22 | from contextlib import contextmanager 23 | 24 | 25 | @contextmanager 26 | def closing(thing): 27 | """Close stream when using the "with" since the __close__ method of 28 | streams is not defined in python 2. 29 | 30 | Arguments: 31 | thing {stream} -- stream (file, socket, ...) 32 | """ 33 | try: 34 | yield thing 35 | finally: 36 | thing.close() 37 | 38 | 39 | class Server: 40 | """A server that handles skill commands. 41 | 42 | This server is started and ran by cadence. It listens for commands from the optimizer 43 | from a TCP socket, then pass the command to cadence. It then gather the result and 44 | send it back to the optimizer. 45 | 46 | Arguments: 47 | cad_file {file} -- cadence stream 48 | 49 | Keyword Arguments: 50 | sock {obj} -- socket to use in the connection (default: None) 51 | """ 52 | 53 | def __init__(self, cad_file, sock=None): 54 | """Create the server socket.""" 55 | self.cad_file = cad_file 56 | self.server_in = cad_file.stdin 57 | self.server_out = cad_file.stdout 58 | self.server_err = cad_file.stderr 59 | 60 | # Uninitialized variables 61 | self.conn = None # Client socket 62 | 63 | # Receive initial message from cadence, to check connectivity, and send it back 64 | # to print on screen 65 | msg = self.recv_skill() 66 | self.send_skill(msg) 67 | 68 | if sock is None: 69 | self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 70 | # define socket options to allow the reuse of the same addr 71 | self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 72 | else: 73 | self.socket = sock 74 | 75 | def run(self, host, port): 76 | """Start the server. 77 | 78 | Arguments: 79 | host {str} -- remote socket IP address 80 | port {int} -- remote socket port 81 | 82 | Raises: 83 | ConnectionError -- if there's a communication problem 84 | 85 | Returns: 86 | list -- remote socket name 87 | """ 88 | try: 89 | # Start connection between client and server (UNIX socket) 90 | # NOTE: After the connection with the client, the "self.conn" is the socket 91 | # that communicates with the client, so the "self.socket" is not required 92 | # anymore and can be closed. 93 | with closing(self.socket) as s: 94 | s.bind((host, port)) 95 | s.listen(1) # Waits for client connection 96 | 97 | # Accept the client connection and get his socket and address 98 | self.conn, addr = s.accept() 99 | except OSError as err: 100 | raise IOError(err) # TODO: Replace to "ConnectionError" 101 | 102 | # The next function calls don't need a try statement because if they 103 | # have an exception the error will be caught in the function that 104 | # calls this one 105 | 106 | # Send the socket address to the client 107 | self.send_data(dict(data=addr)) 108 | 109 | # Receive remote socket name 110 | return self.recv_data()['data'] 111 | 112 | def send_data(self, obj): 113 | """Send an object through a socket. 114 | 115 | 1 - Serialize the object in JSON and encode the string as a bytes object; 116 | 2 - pack the serialized object length in an unsigned int (I) [four bytes], 117 | and big-endian byte order (>) (this way the object size message has 118 | always the same size (four bytes)); 119 | 3 - send the data. 120 | 121 | Arguments: 122 | obj {dict} -- object to send 123 | 124 | Raises: 125 | TypeError -- if the object is not serializable 126 | ConnectionError -- if the socket connection is broken 127 | """ 128 | # Serialize the object in JSON and encode the string as a bytes object 129 | try: 130 | serialized = json.dumps(obj).encode() 131 | except (TypeError, ValueError): 132 | raise TypeError('It can only send JSON-serializable data') 133 | 134 | serialized_len = len(serialized) # String length 135 | 136 | # Packed string length 137 | pack_serialized_len = struct.pack('>I', serialized_len) 138 | 139 | # Data to send 140 | data = pack_serialized_len + serialized 141 | 142 | total_sent = 0 143 | 144 | while total_sent < serialized_len: 145 | sent = self.conn.send(data[total_sent:]) 146 | 147 | if not sent: 148 | # TODO: Replace to "ConnectionError" 149 | raise IOError("Socket connection broken while sending data") 150 | 151 | total_sent += sent 152 | 153 | def recv_data(self): 154 | """Receive an object through a socket. 155 | 156 | 1 - Receive the first four bytes of data, which contains the data length; 157 | 2 - Receive the data, serialized in JSON, and decode it; 158 | 3 - Convert the received data in an object. 159 | 160 | Raises: 161 | ConnectionError -- if the socket connection is broken 162 | TypeError -- if the received data is not in JSON format 163 | 164 | Returns: 165 | obj {dict} -- decoded and de-serialized received data 166 | """ 167 | data_len = self.recv_bytes(4) 168 | 169 | if not data_len: 170 | # TODO: Replace to "ConnectionError" 171 | raise IOError("Socket connection broken while receiving data") 172 | 173 | msg_len = struct.unpack('>I', data_len)[0] 174 | 175 | serialized = self.recv_bytes(msg_len).decode() 176 | 177 | try: 178 | obj = json.loads(serialized) 179 | except (TypeError, ValueError): 180 | raise TypeError('Received data is not in JSON format') 181 | 182 | return obj 183 | 184 | def recv_bytes(self, n_bytes): 185 | """Receive a specified number of bytes through a socket. 186 | 187 | Arguments: 188 | n_bytes {int} -- number of bytes to receive 189 | 190 | Raises: 191 | ConnectionError -- if the socket connection is broken 192 | 193 | Returns: 194 | bytes -- received bytes stream 195 | """ 196 | data = b'' # Bytes literal 197 | data_len = len(data) 198 | 199 | while data_len < n_bytes: 200 | # Receives a maximum of 1024 bytes per iteration 201 | packet = self.conn.recv(min(n_bytes - data_len, 1024)) 202 | 203 | if not packet: 204 | # TODO: Replace to "ConnectionError" 205 | raise IOError("Socket connection broken while receiving bytes") 206 | 207 | data_len += len(packet) 208 | data += packet 209 | 210 | return data 211 | 212 | def send_skill(self, expr): 213 | """Send a skill expression to Cadence for evaluation. 214 | 215 | Arguments: 216 | data {str} -- skill expression 217 | """ 218 | self.server_out.write(expr) 219 | self.server_out.flush() 220 | 221 | def recv_skill(self): 222 | """Receive a response from Cadence. 223 | 224 | First receives the message length (number of bytes) and then receives the message. 225 | 226 | Returns: 227 | str -- message received from cadence 228 | """ 229 | num_bytes = int(self.server_in.readline()) 230 | msg = self.server_in.read(num_bytes) 231 | 232 | # Remove the '\n' from the message 233 | if msg[-1] == '\n': 234 | msg = msg[:-1] 235 | 236 | return msg 237 | 238 | def send_warn(self, warn): 239 | """Send a warning message to Cadence. 240 | 241 | Arguments: 242 | warn {str} -- warning message 243 | """ 244 | self.server_err.write(warn) 245 | self.server_err.flush() 246 | 247 | def send_debug(self, msg): 248 | """Send a debug message to Cadence. 249 | 250 | Arguments: 251 | msg {str} -- debug message 252 | """ 253 | time.sleep(1) 254 | self.send_warn("[Debug] {0}".format(msg)) 255 | 256 | def close(self, code): 257 | """Close the server socket and end the communication with Cadence.""" 258 | self.conn.close() 259 | # Send feedback to Cadence 260 | self.send_warn("Connection with the client ended!\n\n") 261 | self.server_out.close() # close stdout 262 | self.server_err.close() # close stderr 263 | self.cad_file.exit(code) # close connection to cadence (code up to 255) 264 | -------------------------------------------------------------------------------- /socad/server.py: -------------------------------------------------------------------------------- 1 | # This file is part of SOCAD 2 | # Copyright (C) 2018 Miguel Fernandes 3 | # 4 | # SOCAD is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # SOCAD is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | """Server that stands between a client and Cadence Virtuoso.""" 17 | 18 | import json 19 | import socket 20 | import struct 21 | import time 22 | from contextlib import contextmanager 23 | 24 | 25 | @contextmanager 26 | def closing(thing): 27 | """Close stream when using the "with" since the __close__ method of 28 | streams is not defined in python 2. 29 | 30 | Arguments: 31 | thing (stream): stream (file, socket, ...) 32 | """ 33 | try: 34 | yield thing 35 | finally: 36 | thing.close() 37 | 38 | 39 | class Server: 40 | """A server that handles skill commands. 41 | 42 | This server is started and ran by Cadence Virtuoso. It receives data from 43 | a client and passes it to Cadence. It then gather the Cadence response and 44 | send it back to the client. The data sent to client is serialized in JSON 45 | and the data from client should also be in JSON. 46 | 47 | Arguments: 48 | cad_stream (object): Cadence stream. 49 | sock (object, optional): socket to use in the connection 50 | (default: None). 51 | """ 52 | 53 | def __init__(self, cad_stream, sock=None): 54 | """Create the server socket.""" 55 | self.cad_stream = cad_stream 56 | self.server_in = cad_stream.stdin 57 | self.server_out = cad_stream.stdout 58 | self.server_err = cad_stream.stderr 59 | 60 | # Uninitialized variables 61 | self.conn = None # Client socket 62 | 63 | # Receive initial message from cadence, to check connectivity, and send it back 64 | # to print on screen 65 | msg = self.recv_skill() 66 | self.send_skill(msg) 67 | 68 | if sock is None: 69 | self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 70 | # define socket options to allow the reuse of the same addr 71 | self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 72 | else: 73 | self.socket = sock 74 | 75 | def run(self, host, port): 76 | """Start the server. 77 | 78 | Arguments: 79 | host (str): remote socket IP address. 80 | port (int): remote socket port. 81 | 82 | Raises: 83 | ConnectionError: if there's a communication problem. 84 | 85 | Returns: 86 | list: remote socket name. 87 | """ 88 | try: 89 | # Start connection between client and server (UNIX socket) 90 | # NOTE: After the connection with the client, the "self.conn" is the socket 91 | # that communicates with the client, so the "self.socket" is not required 92 | # anymore and can be closed. 93 | with closing(self.socket) as s: 94 | s.bind((host, port)) 95 | s.listen(1) # Waits for client connection 96 | 97 | # Accept the client connection and get his socket and address 98 | self.conn, addr = s.accept() 99 | except OSError as err: 100 | raise IOError(err) # TODO: Replace to "ConnectionError" 101 | 102 | # The next function calls don't need a try statement because if they 103 | # have an exception the error will be caught in the function that 104 | # calls this one 105 | 106 | # Send the socket address to the client 107 | self.send_data(dict(data=addr)) 108 | 109 | # Receive remote socket name 110 | return self.recv_data()['data'] 111 | 112 | def send_data(self, obj): 113 | """Send an object through a socket. 114 | 115 | 1 - Serialize the object in JSON and encode the string; 116 | 117 | 2 - pack the serialized object length in an unsigned int (I) [4 bytes], 118 | and big-endian byte order (>) (this way the *object size* message 119 | has always the same size); 120 | 121 | 3 - send the data. 122 | 123 | Arguments: 124 | obj (dict): object to send. 125 | 126 | Raises: 127 | TypeError: if the object is not serializable in JSON. 128 | ConnectionError: if the socket connection is broken. 129 | """ 130 | # Serialize the object in JSON and encode the string as a bytes object 131 | try: 132 | serialized = json.dumps(obj).encode() 133 | except (TypeError, ValueError): 134 | raise TypeError('It can only send JSON-serializable data') 135 | 136 | serialized_len = len(serialized) # String length 137 | 138 | # Packed string length 139 | pack_serialized_len = struct.pack('>I', serialized_len) 140 | 141 | # Data to send 142 | data = pack_serialized_len + serialized 143 | 144 | total_sent = 0 145 | 146 | while total_sent < serialized_len: 147 | sent = self.conn.send(data[total_sent:]) 148 | 149 | if not sent: 150 | # TODO: Replace to "ConnectionError" 151 | raise IOError("Socket connection broken while sending data") 152 | 153 | total_sent += sent 154 | 155 | def recv_data(self): 156 | """Receive an object through a socket. 157 | 158 | 1 - Receive the first 4 bytes of data, which contains the data length; 159 | 160 | 2 - Receive the data, serialized in JSON, and decode it; 161 | 162 | 3 - Convert the received data in an object. 163 | 164 | Raises: 165 | ConnectionError: if the socket connection is broken. 166 | TypeError: if the received data is not in JSON format. 167 | 168 | Returns: 169 | dict: decoded and de-serialized received data. 170 | """ 171 | data_len = self.recv_bytes(4) 172 | 173 | if not data_len: 174 | # TODO: Replace to "ConnectionError" 175 | raise IOError("Socket connection broken while receiving data") 176 | 177 | msg_len = struct.unpack('>I', data_len)[0] 178 | 179 | serialized = self.recv_bytes(msg_len).decode() 180 | 181 | try: 182 | obj = json.loads(serialized) 183 | except (TypeError, ValueError): 184 | raise TypeError('Received data is not in JSON format') 185 | 186 | return obj 187 | 188 | def recv_bytes(self, n_bytes): 189 | """Receive a specified number of bytes through a socket. 190 | 191 | Arguments: 192 | n_bytes (int): number of bytes to receive. 193 | 194 | Raises: 195 | ConnectionError: if the socket connection is broken. 196 | 197 | Returns: 198 | bytes: received bytes stream. 199 | """ 200 | data = b'' # Bytes literal 201 | data_len = len(data) 202 | 203 | while data_len < n_bytes: 204 | # Receives a maximum of 1024 bytes per iteration 205 | packet = self.conn.recv(min(n_bytes - data_len, 1024)) 206 | 207 | if not packet: 208 | # TODO: Replace to "ConnectionError" 209 | raise IOError("Socket connection broken while receiving bytes") 210 | 211 | data_len += len(packet) 212 | data += packet 213 | 214 | return data 215 | 216 | def send_skill(self, expr): 217 | """Send a skill expression to Cadence Virtuoso for evaluation. 218 | 219 | Arguments: 220 | data (str): skill expression. 221 | """ 222 | self.server_out.write(expr) 223 | self.server_out.flush() 224 | 225 | def recv_skill(self): 226 | """Receive a response from Cadence. 227 | 228 | First receives the message length (number of bytes) and then receives 229 | the message. 230 | 231 | Returns: 232 | str: message received from Cadence Virtuoso. 233 | """ 234 | num_bytes = int(self.server_in.readline()) 235 | msg = self.server_in.read(num_bytes) 236 | 237 | # Remove the '\n' from the message 238 | if msg[-1] == '\n': 239 | msg = msg[:-1] 240 | 241 | return msg 242 | 243 | def send_warn(self, warn): 244 | """Send a warning message to Cadence Virtuoso. 245 | 246 | Arguments: 247 | warn (str): warning message. 248 | """ 249 | self.server_err.write(warn) 250 | self.server_err.flush() 251 | 252 | def send_debug(self, msg): 253 | """Send a debug message to Cadence Virtuoso. 254 | 255 | Arguments: 256 | msg (str): debug message. 257 | """ 258 | time.sleep(1) # Wait a second before send the message 259 | self.send_warn("[Debug] {0}".format(msg)) 260 | 261 | def close(self, code): 262 | """Close the server socket and end the communication with Cadence. 263 | 264 | Arguments: 265 | code (int): exit code. 266 | """ 267 | self.conn.close() 268 | # Send feedback to Cadence 269 | self.send_warn("Connection with the client ended!\n\n") 270 | self.server_out.close() # close stdout 271 | self.server_err.close() # close stderr 272 | self.cad_stream.exit(code) # close connection to cadence (code up to 255) 273 | -------------------------------------------------------------------------------- /docs/tutorials/common_source.rst: -------------------------------------------------------------------------------- 1 | .. _common_source: 2 | 3 | *********************************************************** 4 | Simulation of a common-source circuit using SOCAD and ADE-L 5 | *********************************************************** 6 | 7 | This tutorial demonstrates how to use **SOCAD** to simulate a common-source circuit on Cadence Virtuoso from a Python program. It uses the files provided in the `project example `_. 8 | 9 | **SOCAD** is divided in two programs: 10 | 11 | * The first program is designated as **SOCAD server** (for simplification). It is responsible to make the bridge between *Cadence Virtuoso* and the **SOCAD client**, executing the tasks required by the **SOCAD client** and returning the results from Cadence. 12 | * The second program is designated as **SOCAD client**. It is responsible to control the Cadence behavior (e.g. update circuit variables values, run simulation, ...), and to receive the simulation results. 13 | 14 | .. _section1: 15 | 16 | 1. Design the circuit and configure the simulation environment 17 | ============================================================== 18 | 19 | This circuit was designed with the STM 65nm technology, using Cadence Virtuoso IC6.1.7-64b.500.15 and the ADE-L environment. 20 | 21 | 1.1. Design the circuit 22 | ----------------------- 23 | The common-source (CS) circuit is shown below. 24 | 25 | .. image:: ../_static/img/schematic.png 26 | 27 | After designing the circuit, the circuit parameters to be updated by the **SOCAD client** need to be associated with variables (e.g. width of transistor *M1* is named **W1**, biasing current is named **IB**, and so on). For this specific circuit, the author defined the following variables: 28 | 29 | ================= ===================================== 30 | Parameter Description 31 | ================= ===================================== 32 | W1 [um] Width of the transistor M1 33 | W2 [um] Width of the transistors M2 and MB 34 | L [um] Length of all transistors 35 | IB [A] Biasing current of the current-mirror 36 | VBIAS [V] Biasing voltage of the transistor M1 37 | ================= ===================================== 38 | 39 | 1.2. Configure the simulation environment using *ADE-L* 40 | ------------------------------------------------------- 41 | 42 | The ADE setup is highly circuit-dependent, and for this circuit is the following: 43 | 44 | .. image:: ../_static/img/ade-l.png 45 | 46 | These are the steps performed to achieve the state shown in the figure: 47 | 48 | 1. Import the variables to the *ADE-L* (*Variables -> Copy From Cellview*). 49 | 2. Define the analysis to perform. In this example the author chose: 50 | * DC - to get the transistors' operating regions, and the overall power consumption; 51 | * AC - to get the circuit gain and GBW. 52 | 3. Set the simulation outputs, as following: 53 | * GAIN - ``ymax(mag(v(\"/out\" ?result \"ac\"))`` 54 | * REG1 - ``pv(\"M1.m1\" \"region\" ?result \"dcOpInfo\")`` 55 | * REG2 - ``pv(\"M2.m1\" \"region\" ?result \"dcOpInfo\")`` 56 | * POWER - ``(- pv(\"V0\" \"pwr\" ?result \"dcOpInfo\"))`` 57 | * GBW - ``gainBwProd(mag(v(\"/out\" ?result \"ac\"))) || 0.0`` 58 | 59 | The DC outputs (REG1, REG2, POWER) are easily obtained from the *Tools -> Results Browser...* menu, and the AC outputs (GAIN, GBW) can be obtained from the *Tools -> Calculator...*. 60 | 61 | In the GBW output, the expression ends with ``|| 0.0``. This sub-expression indicates that the GBW default value is 0.0 (with type = float), i.e. if the simulator can't obtain the GBW value, it will assign zero to GBW. This prevents simulation errors that can broke the program. 62 | 63 | After setting the *ADE-L* environment, perform a simulation and be sure that there are no errors and the simulation outputs are correctly displayed. It's also recommended to save the environment state. 64 | 65 | 2. Generate the OCEAN scripts 66 | ============================= 67 | 68 | The OCEAN scripts are executed by Cadence, when requested by the **SOCAD client**, and include commands to load the simulator, run a simulation, update the circuit variables. These files are obtained from the *ADE-L* state that was configured in :ref:`Section 1 ` 69 | 70 | This is the trickiest part of the configuration. This step comprises two main tasks: 71 | 72 | 1. Export an OCEAN script with the *ADEL-L* configurations. 73 | 2. Split the previous file in three scripts: 74 | * Load the simulator (in this example is *Spectre*) (*loadSimulator.ocn*); 75 | * Load the circuit variables before run a simulation (*run.ocn*); 76 | * Run a simulation and save the outputs to a file (*vars.ocn*). 77 | 78 | 2.1. Export the OCEAN script 79 | ---------------------------- 80 | The OCEAN script with the *ADE-L* configuration can be exported from *Session -> Save Ocean Script ...*. For the circuit of this example, it content is the following: 81 | 82 | .. code-block:: scheme 83 | 84 | simulator( 'spectre ) 85 | design("CADENCE_WORKSPACE/simulation/COMMON_SOURCE/spectre/schematic/netlist/netlist") 86 | resultsDir("CADENCE_WORKSPACE/simulation/COMMON_SOURCE/spectre/schematic" ) 87 | modelFile( 88 | '("CADENCE_WORKSPACE/nominal/spectre/nominalwrapper.scs" "") 89 | ) 90 | definitionFile( 91 | "models.scs" 92 | ) 93 | analysis('ac ?start "10k" ?stop "1G" ) 94 | analysis('dc ?saveOppoint t ) 95 | desVar( "IB" 100u ) 96 | desVar( "L" 0.28 ) 97 | desVar( "VBIAS" 500m ) 98 | desVar( "W1" 2 ) 99 | desVar( "W2" 6 ) 100 | envOption( 101 | 'analysisOrder list("dc" "ac") 102 | ) 103 | temp( 27 ) 104 | run() 105 | GAIN = ymax(mag(v("/out" ?result "ac"))) 106 | plot( GAIN ?expr '( "GAIN" ) ) 107 | REG1 = pv("M1.m1" "region" ?result "dcOpInfo") 108 | plot( REG1 ?expr '( "REG1" ) ) 109 | REG2 = pv("M2.m1" "region" ?result "dcOpInfo") 110 | plot( REG2 ?expr '( "REG2" ) ) 111 | GBW = (gainBwProd(mag(v("/out" ?result "ac"))) || 0.0) 112 | plot( GBW ?expr '( "GBW" ) ) 113 | POWER = (- pv("V0" "pwr" ?result "dcOpInfo")) 114 | plot( POWER ?expr '( "POWER" ) ) 115 | 116 | .. _split_files: 117 | 118 | 2.2. Split the OCEAN script in multiple files 119 | --------------------------------------------- 120 | 121 | These files are available provided with the project exemple under the *socad_cadence -> script* directory. 122 | 123 | 2.2.1. loadSimulator.ocn 124 | ^^^^^^^^^^^^^^^^^^^^^^^^ 125 | 126 | This script includes the definition of the simulator (*spectre*), the netlist and results directories, the file with the devices models, and the analysis to perform. One only needs to load this file once per program execution, usually at the begin of the program. 127 | 128 | .. code-block:: scheme 129 | 130 | ; Set up the number notation, precision, etc, of the results 131 | setup(?numberNotation 'engineering) 132 | 133 | ; Simulator and design folders 134 | simulator( 'spectre ) 135 | design("CADENCE_WORKSPACE/simulation/COMMON_SOURCE/spectre/schematic/netlist/netlist") 136 | resultsDir("CADENCE_WORKSPACE/simulation/COMMON_SOURCE/spectre/schematic" ) 137 | modelFile( 138 | '("CADENCE_WORKSPACE/nominal/spectre/nominalwrapper.scs" "") 139 | ) 140 | definitionFile( 141 | "models.scs" 142 | ) 143 | 144 | ; Analysis to perform 145 | analysis('ac ?start "10k" ?stop "1G" ) 146 | analysis('dc ?saveOppoint t ) 147 | envOption( 148 | 'analysisOrder list("dc" "ac") 149 | ) 150 | 151 | ; Other settings 152 | temp( 27 ) 153 | 154 | The only parameter that is not included in the original script file is the ``setup(?numberNotation 'engineering)``, which changes the number notation to engineering. More info about this command can be found in the Cadence help documentation [CDCHELP]_. 155 | 156 | 2.2.2. run.ocn 157 | ^^^^^^^^^^^^^^ 158 | This file runs the simulation, get the results and store them in the *SOCAD_RESULT_FILE*. 159 | 160 | .. code-block:: scheme 161 | 162 | run() ; run a simulation 163 | 164 | ; Output file 165 | out_file = getShellEnvVar("SOCAD_RESULT_FILE") 166 | outf = outfile(out_file "w") 167 | 168 | ; Simulation results 169 | GAIN = ymax(mag(v("/out" ?result "ac"))) 170 | REG1 = pv("M1.m1" "region" ?result "dcOpInfo") 171 | REG2 = pv("M2.m1" "region" ?result "dcOpInfo") 172 | GBW = (gainBwProd(mag(v("/out" ?result "ac"))) || 0.0) 173 | POWER = (- pv("V0" "pwr" ?result "dcOpInfo")) 174 | 175 | ; Save results to file 176 | fprintf( outf "%s\t%g\n", "GAIN", GAIN) 177 | fprintf( outf "%s\t%d\n", "REG1", REG1) 178 | fprintf( outf "%s\t%d\n", "REG2", REG2) 179 | fprintf( outf "%s\t%g\n", "GBW", GBW) 180 | fprintf( outf "%s\t%e\n", "POWER", POWER) 181 | 182 | close(outf) ; Close the file 183 | 184 | The format specifiers (e.g. ``%d``) of the ``fprintf`` function must be chosen according to the respective result's data type. In doubt, one can use the function ``float()`` to convert the result to float, and then use the ``%f`` or ``%g`` specifier. If the wrong specifier is provided, the Cadence will trigger an error. More info about the used functions can be found on the Cadence help documentation [CDCHELP]_. 185 | 186 | 2.2.3. vars.ocn 187 | ^^^^^^^^^^^^^^^ 188 | This file includes the circuit design variables. 189 | 190 | .. code-block:: scheme 191 | 192 | desVar( "IB" 100u ) 193 | desVar( "L" 0.28 ) 194 | desVar( "VBIAS" 500m ) 195 | desVar( "W1" 2 ) 196 | desVar( "W2" 6 ) 197 | 198 | 3. Run the program 199 | ================== 200 | 201 | The program is started in two steps: 202 | 203 | 1. Start the **SOCAD server**, which should be located in the machine where *Cadence Virtuoso* is installed. 204 | 2. Start the **SOCAD client**, which can be in any machine that reach the **SOCAD server**, or in the same machine, depending to the chosen socket type (more info about the sockets can be found in the :ref:`Library Reference `). 205 | 206 | **NOTE:** It is mandatory to run the **SOCAD server** before the **SOCAD client**!!! 207 | 208 | 3.1. SOCAD server 209 | ----------------- 210 | 211 | .. _config_server: 212 | 213 | 3.1.1. Configure the server 214 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 215 | 216 | The **SOCAD server** configurations are in the file *start_cadence.sh* located in the directory *socad_cadence* from the `project example `_. This file is responsible to create the required variables, directories and files, and runs *Cadence Virtuoso*. The following variables can be changed by the user: 217 | 218 | * ``SOCAD_PROJECT_NAME="project_example"`` - project name and directory 219 | * ``SOCAD_WORK_SPACE="/home/example/project_ws"`` - project work space, i.e. the directory that contains the project directory. 220 | * ``SOCAD_CLIENT_ADDR="localhost"`` - IP address of the **SOCAD client**. 221 | * ``SOCAD_CLIENT_PORT="4000"`` - port of the **SOCAD client**. 222 | 223 | 3.1.2. Run the server 224 | ^^^^^^^^^^^^^^^^^^^^^ 225 | 226 | 1. Copy the directory *socad_cadence*, located in the `project example `_, to the machine where *Cadence Virtuoso* is installed. 227 | 2. Replace the files in the *socad_cadence/script* folder for the ones generated in :ref:`Section 2.2 `. 228 | 3. Run the *start_cadence.sh* script with the command ``sh start_cadence.sh``. If it's the first time that the program is executed for a project, the folder *SOCAD_WORK_SPACE/SOCAD_PROJECT_NAME* described in :ref:`Section 3.1.1. ` is created and the folder *socad_cadence/script* is copied to that folder. If further modifications to the scripts are required, they should be made in the new *script* folder, i.e. *SOCAD_WORK_SPACE/SOCAD_PROJECT_NAME/script*. 229 | 230 | If the program is started successfully, the terminal should present the following message in the last line: 231 | 232 | .. code-block:: text 233 | 234 | [INFO] Cadence is connected to server! Waiting for a connection from the client... 235 | 236 | This means that the **SOCAD server** is connected to *Cadence Virtuoso* and is waiting for a connection from the **SOCAD client**. 237 | 238 | 3.2. SOCAD client 239 | ----------------- 240 | 241 | 3.2.1. Configure the client 242 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 243 | 244 | The **SOCAD client** configurations are only regarding the **SOCAD server** IP and port, and can be modified on the ``main()`` function of the *socad_example.py* module on the `project example `_, where: 245 | 246 | * ``host = "localhost"`` - IP address of the **SOCAD server**. 247 | * ``port = 4000`` - port of the **SOCAD server**. 248 | 249 | 250 | 3.2.2. Run the client 251 | ^^^^^^^^^^^^^^^^^^^^^ 252 | 253 | The **SOCAD client** is executed with the command ``python socad_example.py``. If the program is started successfully, the terminal output should be similar to: 254 | 255 | .. code-block:: text 256 | 257 | mdmfernandes@EXAMPLE:~socad/example$ python socad_example.py 258 | 259 | 260 | 261 | Starting client... 262 | Connecting to server... 263 | [INFO] Connected to server with the address 127.0.0.1:46434 264 | 265 | ############### SOCAD EXAMPLE ############### 266 | 1 - Load simulator 267 | 2 - Update variables and run a simulation 268 | 0 - Exit. 269 | 270 | -> Please Select: 271 | 272 | This means that the **SOCAD client** is connected to the **SOCAD server**. The **SOCAD server** also displays an info message: 273 | 274 | .. code-block:: text 275 | 276 | [INFOs] Connected to client with address 127.0.0.1:51912 277 | 278 | 4. Running example 279 | ================== 280 | 281 | This section shows a typical execution of SOCAD. After starting both the **SOCAD server** and **SOCAD client** successfully, one may load the simulator and then run simulations. 282 | 283 | **NOTE**: The simulator should de loaded before running a simulation, otherwise *Cadence* will trigger an error and the program will terminate. Also, this can erase all circuit variables from the *vars.ocn* file. 284 | 285 | 4.1. Load the simulator 286 | ----------------------- 287 | 288 | The simulator is loaded from the file *loadSimulator.ocn*, through *Cadence Virtuoso*, after choosing the option **1** on the **SOCAD client**. If everything goes well, *Cadence* sends the message **loadSimulator_OK** to the **SOCAD server**. When the **SOCAD server** receives this message, it sends the circuit design variables, stored in the file *vars.ocn*, to the **SOCAD client**. The **SOCAD client** terminal output is similar to: 289 | 290 | .. code-block:: text 291 | 292 | ############### SOCAD EXAMPLE ############### 293 | 1 - Load simulator 294 | 2 - Update variables and run a simulation 295 | 0 - Exit. 296 | 297 | -> Please Select: 1 298 | 299 | Simulator loaded with success! Received variables: 300 | Variable: VBIAS - Value: 0.55 301 | Variable: IB - Value: 0.00011 302 | Variable: L - Value: 0.308 303 | Variable: W1 - Value: 2.2 304 | Variable: W2 - Value: 6.6 305 | 306 | 4.2. Update variables and run a simulation 307 | ------------------------------------------ 308 | 309 | To simulate that the circuit design variables were updated (e.g. by a circuit optimizer), the **SOCAD client** increases their value by 10% when it receives the simulation results from the **SOCAD server**. 310 | 311 | By selecting the option **2** on the **SOCAD client**, the *Cadence* will start a simulation (the simulation log is shown on the **SOCAD server** terminal output). If the simulation is successful, it sends the message **updateAndRun_OK** to the **SOCAD server**, which in turn sends the simulation results, stored in the file *SOCAD_RESULT_FILE*, to the **SOCAD client**. The **SOCAD client** terminal output is similar to: 312 | 313 | .. code-block:: text 314 | 315 | ############### SOCAD EXAMPLE ############### 316 | 1 - Load simulator 317 | 2 - Update variables and run a simulation 318 | 0 - Exit. 319 | 320 | -> Please Select: 2 321 | 322 | Sending updated variables... 323 | Key: VBIAS - Val:0.5 324 | Key: IB - Val:0.0001 325 | Key: L - Val:0.28 326 | Key: W1 - Val:2.0 327 | Key: W2 - Val:6.0 328 | 329 | Received updateAndRun from Cadence 330 | Simulation results: {'GBW': 6221070.0, 'REG2': 2.0, 'GAIN': 0.832934, 'POWER': 0.0002527307, 'REG1': 1.0} 331 | 332 | 4.3. Exit from SOCAD 333 | -------------------- 334 | 335 | By selecting the option **0** on the **SOCAD client**, both **SOCAD** and *Cadence Virtuoso* are terminated. The **SOCAD server** terminal outputs the message ``Server has stopped with the exit code 0. I'm out!!!`` and the **SOCAD client** terminal outputs the message ``**** Closing socket and ending program... Bye! ****``. 336 | 337 | 338 | References 339 | ========== 340 | .. [CDCHELP] The Cadence Virtuoso help documentation can be accessed through the program, in *Help -> User Guide*. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------