[PYTHON] Install multiple versions of Polyphony using venv

A Python virtual environment called venv

You can use venv to build multiple Python environments. Detailed stories are written in various places, so please search for them. I About VIRTUALENV Was easy to read.

It looks like you can build different versions of Python as well. Here, I will install multiple Polyphony (high-level synthesis by Python), which is one of the Python applications.

My environment is cygwin + Python 3.4 + tcsh

Install venv

pip3 install virtualenv Easy!!

Creating a virtual environment

Create with the pyvenv3 command. The directory will be created automatically.

> pyvenv
pyvenv3    pyvenv-3.4
> pyvenv3 polyphony-0.2.2
> ls
polyphony-0.2.2

[Addition] pyvenv is deprecated

Since pyvenv is deprecatd, use venv.

> python3.6 -m venv polyphony-0.2.2
> ls
polyphony-0.2.2/

The rest is probably the same.

Running a virtual environment

There is activate.csh under bin, so run it. People in bash will probably run bin / activate.

> source polyphony-0.2.2/bin/activate.csh
[polyphony-0.2.2] >

Installation of polyphony-0.2.2

You can install it with pip3. The installation destination is a virtual environment.

[polyphony-0.2.2] > pip3 install polyphony
Collecting polyphony
  Using cached polyphony-0.2.2.tar.gz
Installing collected packages: polyphony
  Running setup.py install for polyphony ... done
Successfully installed polyphony-0.2.2
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[polyphony-0.2.2] >

Do a little polyphony

Here is the Python source code.

c_xor.py


from polyphony import testbench

class BitOp:
    def __init__(self, w0, w1, b):
        self.w0 = w0
        self.w1 = w1
        self.b = b

    def eval(self, x0, x1):
        tmp0 = self.w0 * x0
        tmp1 = self.w1 * x1
        tmp = tmp0 + tmp1 + self.b
        if tmp <= 0:
            return 0
        else:
            return 1

def AND(x1, x2):
    op = BitOp(5, 5, -7)
    return op.eval(x1, x2)

def OR(x1, x2):
    op = BitOp(5, 5, -2)
    return op.eval(x1, x2)

def NAND(x1, x2):
    op = BitOp(-5, -5, 7)
    return op.eval(x1, x2)

def XOR(x1, x2):
    AND = BitOp(5, 5, -7)
    OR = BitOp(5, 5, -2)
    NAND = BitOp(-5, -5, 7)
    s1 = NAND.eval(x1, x2)
    s2 = OR.eval(x1, x2)
    y = AND.eval(s1, s2)
    return y

@testbench
def test():
    print(XOR(0, 0))
    print(XOR(1, 0))
    print(XOR(0, 1))
    print(XOR(1, 1))

test()

Do this first with python3

[polyphony-0.2.2] Persimmon:works> python c_xor.py
0
1
1
0

It worked fine. Let's run it with polyphony. You have successfully created the verilog code.

> polyphony c_xor.py
[polyphony-0.2.2] > ls
c_xor.py  polyphony_out.v  polyphony_out_test.v  polyphony_out_XOR.v

All you have to do is compile and run it with iverilog. It seems to be working fine.

> iverilog -I . -W all -o test -s test polyphony_out.v polyphony_out_test.v
> ./test
    0:XOR_0_in_x1=   x, XOR_0_in_x2=   x, XOR_0_out_0=   x
  110:XOR_0_in_x1=   0, XOR_0_in_x2=   0, XOR_0_out_0=   x
  280:XOR_0_in_x1=   0, XOR_0_in_x2=   0, XOR_0_out_0=   0
0
  290:XOR_0_in_x1=   1, XOR_0_in_x2=   0, XOR_0_out_0=   0
  460:XOR_0_in_x1=   1, XOR_0_in_x2=   0, XOR_0_out_0=   1
1
  470:XOR_0_in_x1=   0, XOR_0_in_x2=   1, XOR_0_out_0=   1
1
  650:XOR_0_in_x1=   1, XOR_0_in_x2=   1, XOR_0_out_0=   1
  820:XOR_0_in_x1=   1, XOR_0_in_x2=   1, XOR_0_out_0=   0
0

Install polyphony-0.3.0 in another environment

First, build and execute a virtual environment

> pyvenv3 polyphony-0.3.0
> source polyphony-0.3.0/bin/activate.csh
[polyphony-0.3.0] > cd polyphony-0.3.0/
[polyphony-0.3.0] >

Installation of polyphony-0.3.0

Since it is a version under development, specify a branch from github and clone it.

[polyphony-0.3.0] > git clone -b 0.3.0 https://github.com/ktok07b6/polyphony/
Cloning into 'polyphony'...
remote: Counting objects: 2202, done.
remote: Compressing objects: 100% (230/230), done.
remote: Total 2202 (delta 121), reused 0 (delta 0), pack-reused 1972
Receiving objects: 100% (2202/2202), 954.49 KiB | 371.00 KiB/s, done.
Resolving deltas: 100% (1512/1512), done.
Checking connectivity... done.
[polyphony-0.3.0] > cd polyphony/
[polyphony-0.3.0] > git branch
* 0.3.0
[polyphony-0.3.0] > ls -l setup.py
-rw-r--r--1 ryos None 481 March 25 17:01 setup.py
[polyphony-0.3.0] > python3 setup.py install
Rough capture

afterwards

python3 setup.py install

If you think it will work, it seems to look at the information in the URL of setup.py. So rewrite setup.py. The part added after @.

setup.py


 url='https://github.com/ktok07b6/[email protected]',

And

[polyphony-0.3.0] > python3 setup.py install

Try to run

Check if the new function io of 0.3.0 can be used.

[polyphony-0.3.0] > ./simu.py tests/io/
port01.py      port03.py      protocol01.py  protocol03.py
port02.py      port04.py      protocol02.py
[polyphony-0.3.0] > ./simu.py tests/io/port01.py
    0:p01_start=x, p01_in_valid=x, p01_out_valid=x, p01_out0=   x, p01_in0=   x
   10:p01_start=0, p01_in_valid=0, p01_out_valid=0, p01_out0=   0, p01_in0=   0
  110:p01_start=1, p01_in_valid=0, p01_out_valid=0, p01_out0=   0, p01_in0=   0
wait_rising out_valid
  120:p01_start=1, p01_in_valid=1, p01_out_valid=0, p01_out0=   0, p01_in0=   2
  140:p01_start=1, p01_in_valid=1, p01_out_valid=0, p01_out0=   4, p01_in0=   2
  150:p01_start=1, p01_in_valid=1, p01_out_valid=1, p01_out0=   4, p01_in0=   2
4
  200:finish

I feel like I can use it. With this, we have created multiple environments.

polyphony can also generate 64-bit integers by modifying env.py. It's a little troublesome, but it is also possible to create a 64-bit environment.

Recommended Posts

Install multiple versions of Polyphony using venv
Using multiple versions of Python on Mac OS X (2) Usage
Coexist multiple versions using Node.js n
Using multiple versions of Python on Mac OS X (1) Multiple Ver installation
Manage multiple execution environments using Python venv
How to build an environment for using multiple versions of Python on Mac
Use multiple versions of python environment with pyenv
[Java] How to switch between multiple versions of Java
Multiple inheritance of classes
Copy of multiple List
Example of using lambda
Switch versions when multiple versions of java are included on Linux
List of libraries to install when installing Python using Pyenv