A python SDK for running simulation and reading data from Ocean Cadence
Project description
PyCadence
A Python wrapper for running Cadence simulations
Pre-requisites
-
OS: Linux/Unix based OS
-
Python 3.6 or higher
-
IC615 or higher (Cadence Virtuoso) to be installed on the device with Ocean Spectre enabled
-
tmux to be installed on the device
To install tmux on Ubuntu/Debian based systems, run the following command
sudo apt-get install tmux
To install tmux on RedHat/CentOS based systems, run the following command
sudo yum install tmux
Installation
- Install PyCadence using pip
pip install pycadence
Add the --user option if you don't want to install it systemwide.
Usage
- Make sure to have a template init.ocn file ready
- In the ocn file placeholder values must be marked as {{value}} as shown in the sample init.ocn file placed in the sample folder
- Go to the directory where the init.ocn file is placed and enable the Cadence environment using the following shell command
csh
source /home/install/cshrc # Path to the cshrc file in the Cadence installation directory
Next, create a new tmux session using the following shell command
tmux new-session -s <session name>
- Install and enable ocean terminal using the following shell commands
ocean
Now, The terminal can be detached or left running in the background. To detach the terminal, press Ctrl+b and then press d.
- Now, create a python script and use the following code to run the simulation
from pycadence.pycadence import Connector
x = [1,2,3,4,5] # List of values to be substituted in the template .ocn file
default = [1,2,3,4,5] # List of default values to be substituted in the template in case no value is provided
p=Connector(screen_name=<session name>)
p.simulate(x, default,"init.ocn","output.ocn","output.txt")
- The result of simulation will be stored output.txt file and the output.ocn file will be the modified template file with the values substituted.
- The simulate function also has an argument called
read_output
which takes a function as an argument. This function will be called after the simulation is complete and the output.txt file is generated. The function should take the output.txt file as an argument and return a Iterable of the values parsed from the output.txt file. The following code demonstrates how to use theread_output
argument.
from pycadence.pycadence import Connector
import numpy as np
def read_output(output_log_path):
with open(output_log_path, 'r+') as fp:
# read an store all lines into list
lines = fp.readlines()
data=[]
for line in lines[2:]:
try:
temp = line.strip().split(" ")
# print(temp)
data.append([float(temp[0]),float(temp[-1])])
except Exception as e:
# print("Error in reading output file")
# print(e)
pass
data = np.array(data)
return data
p=Connector(screen_name="ocean_simulation")
x = [1,2,3,4,5] # List of values to be substituted in the template
default = [1,2,3,4,5] # List of default values to be substituted in the template in case of error
p.simulate(x, default,"init.ocn","output.ocn","output.txt",read_output)
-
The above code will read the output.txt file and return a numpy array of the values.
-
Refer to the init.ocn file in the sample folder for the template file format.
Examples
Refer to the examples page for examples on how to use PyCadence.
WorkFlow Diagram
Documentation
-
Class PyCadence.Connector
: This class is used to connect to the Cadence environment and run the simulation__init__(self, screen_name:str)
: Constructor to initialize the class with the screen name. The screen name is the name of the tmux session where the Cadence Ocean environment is runningsimulate(self, x:List, default:List, init_file_path:str, output_file_path:str, output_log_path:str, read_output:Callable=None)
: Function to run the simulation.- x : List of values to be substituted in the template file
- default : List of default values to be substituted in the template file in case of error
- init_file_path : Path to the template file
- output_file_path : Path to the output file
- output_log_path : Path to the output log file
- read_output : Function to read the output log file. The function should take the output log file as an argument and return an Iterable of the values parsed from the output log file
read_output(self, output_log_path:str) -> Iterable
: Function to read the output log file. The function should take the output log file as an argument and return an Iterable of the values parsed from the output log file.- Override this function to provide custom implementation to read the output log file. This can be done by passing the function as an argument to the simulate function.
generate_ocn_file(self, values:List, default:List, init_file_path:str, output_file_path:str, output_log_path:str, sim_status_log_path:str)
: Function to generate the output file by substituting the values in the template file- values : List of values to be substituted in the template file
- default : List of default values to be substituted in the template file in case of error
- init_file_path : Path to the template .ocn file
- output_file_path : Path to the output .ocn file created from the template file
- output_log_path : Path to the output log file where the output of the simulation will be stored
All the member of function of
Connector
class can be overridden to provide custom implementation.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Steps to contribute:
- Fork the repository
- Create a new branch with the issue name. (Note: If there is no issue related to the change, create a new issue)
- Make changes and commit the code
- Create a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cadenceconnector-0.1.9.tar.gz
.
File metadata
- Download URL: cadenceconnector-0.1.9.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be1858c3dd46d961b807a7c2570a0ae84aec7c7c689f1ed7a5e9dd5d760c03aa |
|
MD5 | ffb77ea4ae8aefc936c6dce62d598393 |
|
BLAKE2b-256 | 450a9512e697d8b07422b35e48005a581d09e7a892061f300f3bb2485f84a445 |
File details
Details for the file CadenceConnector-0.1.9-py3-none-any.whl
.
File metadata
- Download URL: CadenceConnector-0.1.9-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8152678f75e94d619fdc19d7535c843e3827eacaf4c65ce7a756c5fbb66e94d5 |
|
MD5 | 134a48fc4f713923f25bb8281dc9ac4c |
|
BLAKE2b-256 | 14f8ff13bc6b6be18a18ef0fec0e697ddf1021fe6f1a5a8172be78d884d6f7d0 |