Skip to main content

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

  1. Install PyCadence using pip pip install pycadence

Add the --user option if you don't want to install it systemwide.

Usage

  1. Make sure to have a template init.ocn file ready
  2. In the ocn file placeholder values must be marked as {{value}} as shown in the sample init.ocn file placed in the sample folder
  3. 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>
  1. 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.

  1. 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")
  1. 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.
  2. 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 the read_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)
  1. The above code will read the output.txt file and return a numpy array of the values.

  2. Refer to the init.ocn file in the sample folder for the template file format.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cadenceconnector-0.1.7.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

CadenceConnector-0.1.7-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file cadenceconnector-0.1.7.tar.gz.

File metadata

  • Download URL: cadenceconnector-0.1.7.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for cadenceconnector-0.1.7.tar.gz
Algorithm Hash digest
SHA256 24f22cdb7967e1b939065e80014c672c71217570b2b00c67c7f250585abbcfcf
MD5 002ea326d8f25688299e8b9fd298e0b4
BLAKE2b-256 44d08d2ea43f981905edd893c19603d57bbb7ae69bd09859cdeda3e847a498dd

See more details on using hashes here.

File details

Details for the file CadenceConnector-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for CadenceConnector-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1288bf8a4ae0775930e26b9636995d92413785becf07e208a8ac5620462f597c
MD5 b93635bc919309ada6c1b3da43e5fbe8
BLAKE2b-256 b45a664f8e7c2b08877fba692bfdab6bb86c38122c7dc49cbf71954980f70a03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page