unihd-cag / skillbridge

A seamless python to Cadence Virtuoso Skill interface
https://unihd-cag.github.io/skillbridge/
GNU Lesser General Public License v3.0
181 stars 38 forks source link

[SUPPORT] Multiple communications from one device #256

Closed xiaohangguo closed 7 months ago

xiaohangguo commented 7 months ago

How do I get multiple programs to use this communication skillgridge on a single machine? I tried it and found that it would have sockets, changing the name didn't help either

TM90 commented 7 months ago

Hello,

Having multiple programs accessing the server is possible as long as they are working sequentially. You should use ws = Workspace.open() and ws.close() accordingly.

If you want to have multiple applications running that access virtuoso at any given time, this will be a problem since a lot of virtuosos commands will change state and you will get inconsistencies.

Another approach would be that each application spawns its virtuoso instance with a unique id.

I hope this helps.

Best regards

Tobias

xiaohangguo commented 7 months ago

Hello,

Having multiple programs accessing the server is possible as long as they are working sequentially. You should use ws = Workspace.open() and ws.close() accordingly.

If you want to have multiple applications running that access virtuoso at any given time, this will be a problem since a lot of virtuosos commands will change state and you will get inconsistencies.

Another approach would be that each application spawns its virtuoso instance with a unique id.

I hope this helps.

Best regards

Tobias

hello! thanks . i use the command ,But it didn't work. pyStartServer ?id "lvshuhang"

On the server I am using 'pyStartServer' which is working fine, now I want to set up different communication services on the same device so that I can have multiple users for running and communicating with their respective python-virtuoso programs. But now after I start it with the command pyStartServer ?id "lvshuhang", it doesn't work at all!

TM90 commented 7 months ago

Can you provide a simplified/minimal example of your use case?

xiaohangguo commented 7 months ago

Commands that can be successfully communicated

load("/home/lvshuhang/.local/lib/python3.9/site-packages/skillbridge/server/python_server.il"); 1
pyStartServer ;2

Commands that cannot be successfully communicated

load("/home/lvshuhang/.local/lib/python3.9/site-packages/skillbridge/server/python_server.il"); 1.
pyStartServer ?id "lvshuhang" ;2

I'm on a server with different users in it, and I'm trying to establish different communication channels by running commands on different virtuoso terminals by user id, but it doesn't seem to be working, I'm failing!

TM90 commented 7 months ago

In your second example how does your client open the workspace ?

Maybe this example is helpful:

https://unihd-cag.github.io/skillbridge/examples/multiple-instances.html

xiaohangguo commented 7 months ago

i got it,That's how I should ws = Workspace.open('lvshuhang')

xiaohangguo commented 7 months ago

image I'm trying to do it in two python terminals and in a virtuoso terminal, and it's still failing.

xiaohangguo commented 7 months ago

I have two accounts, one works fine and the other one has issues with permissions:

================================================================ FAILURES =================================================================
______________________________________________________________ test_awvPlot _______________________________________________________________

    def test_awvPlot():
>       awv_plot = VirtuosoAwvPlot()

ted-viewer/core/platform/virtuoso/awv_plot/tests/test_1.py:6: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ted-viewer/core/platform/virtuoso/awv_plot/plot.py:25: in __init__
    super().__init__(work_space, cell_view)
ted-viewer/core/platform/virtuoso/base/virtuoso_base.py:21: in __init__
    self.work_space = Workspace.open()
.local/lib/python3.9/site-packages/skillbridge/client/workspace.py:268: in open
    channel = channel_class(workspace_id)
.local/lib/python3.9/site-packages/skillbridge/client/channel.py:80: in __init__
    self.socket = self.start()
.local/lib/python3.9/site-packages/skillbridge/client/channel.py:89: in start
    return self.connect(sock)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <skillbridge.client.channel.create_channel_class.<locals>.UnixChannel object at 0x7f36cb89e550>
sock = <socket.socket fd=7, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>

    def connect(self, sock: socket) -> socket:
        sock.settimeout(1)
>       sock.connect(self.address)
E       PermissionError: [Errno 13] Permission denied

.local/lib/python3.9/site-packages/skillbridge/client/channel.py:99: PermissionError
========================================================= short test summary info =========================================================
FAILED ted-viewer/core/platform/virtuoso/awv_plot/tests/test_1.py::test_awvPlot - PermissionError: [Errno 13] Permission denied
============================================================ 1 failed in 0.25s ===========================================================
nielsbuwen commented 7 months ago

The skillbridge can only be used by the user that started Virtuoso. A different user does not have access to the socket out of the box.

You can either start two different Virtuoso instances (one by each user that needs access) or you implement shared access to skillbridge on your own (see idea below)

  1. Change the file permissions of the socket file in /tmp/skill-server-<id>.sockso it can be used by the user that created the server and the user that needs access (best would be to create a separate group and use chown)
  2. Implement a locking mechanism to ensure that only one of the user can access the socket file simultaneously (if you don't do this, the skillbridge requests will be mixed up and everything will break in weird ways)
    • this can be done by using a lock file that must be locked before each skillbridge access
xiaohangguo commented 7 months ago

I'm testing on the same server now, I have two accounts 'lvshuhang' and 'wuqingsen_s07'

Both users open the virtuoso instance in their own terminals and run open workspace in their own python

(py390) 
lvshuhang@s07:/tmp
$ ls -l skill-server-lvshuhang.sock
srwxrwxr-x 1 lvshuhang lvshuhang 0 Apr  8 16:59 skill-server-lvshuhang.sock
(py390) 
lvshuhang@s07:/tmp
$ ls -l skill-server-wuqingsen_s07-wqs.sock
srwxrwxr-x 1 wuqingsen_s07 wuqingsen_s07 0 Apr  8 17:32 skill-server-wuqingsen_s07-wqs.sock
wuqingsen_s07@s07:~
$ ls -l /tmp/skill-server-wuqingsen_s07-wqs.sock
srwxrwxr-x 1 wuqingsen_s07 wuqingsen_s07 0 Apr  8 17:32 /tmp/skill-server-wuqingsen_s07-wqs.sock
(py390) 
wuqingsen_s07@s07:~
$ 

Both users should have permission to read and write their own sock, but why is it that user 'wuqingsen_s07' can't run properly and reports a permission error?

output:

$ s180bcd ./ted-viewer/core/platform/virtuoso/awv_plot/tests/test_1.py
=========================================================== test session starts ===========================================================
platform linux -- Python 3.9.0, pytest-7.2.0, pluggy-1.0.0 -- /EDA/soft/anaconda3.7/envs/py390/bin/python
cachedir: .pytest_cache
rootdir: /home/wuqingsen_s07
plugins: typeguard-2.13.3, jaxtyping-0.2.28, regressions-2.4.1, xdist-3.1.0, anyio-3.6.2, cov-4.0.0, datadir-1.4.1, timeout-2.1.0
collected 1 item                                                                                                                          

ted-viewer/core/platform/virtuoso/awv_plot/tests/test_1.py::test_awvPlot FAILED

================================================================ FAILURES =================================================================
______________________________________________________________ test_awvPlot _______________________________________________________________

    def test_awvPlot():
>       awv_plot = VirtuosoAwvPlot()

ted-viewer/core/platform/virtuoso/awv_plot/tests/test_1.py:6: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ted-viewer/core/platform/virtuoso/awv_plot/plot.py:25: in __init__
    super().__init__(work_space, cell_view)
ted-viewer/core/platform/virtuoso/base/virtuoso_base.py:21: in __init__
    self.work_space = Workspace.open()
.local/lib/python3.9/site-packages/skillbridge/client/workspace.py:268: in open
    channel = channel_class(workspace_id)
.local/lib/python3.9/site-packages/skillbridge/client/channel.py:80: in __init__
    self.socket = self.start()
.local/lib/python3.9/site-packages/skillbridge/client/channel.py:89: in start
    return self.connect(sock)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <skillbridge.client.channel.create_channel_class.<locals>.UnixChannel object at 0x7ff11cb104f0>
sock = <socket.socket fd=7, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>

    def connect(self, sock: socket) -> socket:
        sock.settimeout(1)
>       sock.connect(self.address)
E       PermissionError: [Errno 13] Permission denied

.local/lib/python3.9/site-packages/skillbridge/client/channel.py:99: PermissionError
========================================================= short test summary info =========================================================
FAILED ted-viewer/core/platform/virtuoso/awv_plot/tests/test_1.py::test_awvPlot - PermissionError: [Errno 13] Permission denied
============================================================ 1 failed in 0.28s =====================================================
nielsbuwen commented 7 months ago

Did each user start their own Virtuoso session?

The permissions look like access is only allowed to the same group? Do the socket files belong to the shared group?

TM90 commented 7 months ago

Did each user start their own Virtuoso session?

If this is not the case it will not work it is not possible to run multiple server instances from one virtuoso session, as documented here.

xiaohangguo commented 7 months ago

Did each user start their own Virtuoso session?

The permissions look like access is only allowed to the same group? Do the socket files belong to the shared group?

Each user starts their own virtuoso, and socket permissions should only run their own user access to its socket

image

image

image

Excuse me A user may not have permissions for their own user group?

TM90 commented 7 months ago

In your

Did each user start their own Virtuoso session? The permissions look like access is only allowed to the same group? Do the socket files belong to the shared group?

Each user starts their own virtuoso, and socket permissions should only run their own user access to its socket

image

image

In the shown trace you just call Workspace.open() without the correct id.

xiaohangguo commented 7 months ago

In your

Did each user start their own Virtuoso session? The permissions look like access is only allowed to the same group? Do the socket files belong to the shared group?

Each user starts their own virtuoso, and socket permissions should only run their own user access to its socket image image

In the shown trace you just call Workspace.open() without the correct id.

no,not this problem. I've tried them all.

image

TM90 commented 7 months ago

Can you repeat this in a clean session. Maybe the testing led to some leftover processes?

nielsbuwen commented 7 months ago

Just to make sure we are on the same page. You did the following, right?

We are using that exact setup and it works, correct @TM90 ?

xiaohangguo commented 7 months ago

Can you repeat this in a clean session. Maybe the testing led to some leftover processes?

how to clean?

I tried killing the virtuoso terminal, reopening it, and running the

load("/home/wuqingsen_s07/.local/lib/python3.9/site-packages/skillbridge/server/python_server.il")
pyStartServer ?id "wqs"

but still :

================================================================ FAILURES =================================================================
______________________________________________________________ test_awvPlot _______________________________________________________________

    def test_awvPlot():
        #awv_plot = VirtuosoAwvPlot()
>       ws = Workspace.open("wqs")  # 可以理解为 打开的某个virtuoso终端

ted-viewer/core/platform/virtuoso/awv_plot/tests/test_1.py:7: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.local/lib/python3.9/site-packages/skillbridge/client/workspace.py:268: in open
    channel = channel_class(workspace_id)
.local/lib/python3.9/site-packages/skillbridge/client/channel.py:80: in __init__
    self.socket = self.start()
.local/lib/python3.9/site-packages/skillbridge/client/channel.py:89: in start
    return self.connect(sock)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <skillbridge.client.channel.create_channel_class.<locals>.UnixChannel object at 0x7f0377aef4c0>
sock = <socket.socket fd=7, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>

    def connect(self, sock: socket) -> socket:
        sock.settimeout(1)
>       sock.connect(self.address)
E       PermissionError: [Errno 13] Permission denied

.local/lib/python3.9/site-packages/skillbridge/client/channel.py:99: PermissionError
========================================================= short test summary info =========================================================
FAILED ted-viewer/core/platform/virtuoso/awv_plot/tests/test_1.py::test_awvPlot - PermissionError: [Errno 13] Permission denied
============================================================ 1 failed in 0.24s ============================================================
nielsbuwen commented 7 months ago

Maybe some leftover socket files cause a problem, you can safely delete them after Virtuoso is closed

xiaohangguo commented 7 months ago

Just to make sure we are on the same page. You did the following, right?

  • UserA on machine X starts Virtuoso
  • UserA runs pyStartServer ?id userA
  • UserA runs Workspace.open('userA')
  • UserB on machine X starts Virtuoso
  • UserB runs pyStartServer ?id userB
  • UserB runs Workspace.open('userB')

We are using that exact setup and it works, correct @TM90 ?

yes,Now my resultant surface, userA can be allowed normally, userB will have PermissionError: [Errno 13] Permission denied

xiaohangguo commented 7 months ago

i delete all the skill* file ,and ,run again. but: image

image

image

nielsbuwen commented 7 months ago

Something is weird on your side. Running pyStartServer ?id "wqs" should create skill-server-wqs.sock but your file is called skill-server-wuqingsen_s07-wqs.sock. That is why Workspace.open("wqs") fails with that error.

Did you rename the .sock file? It shouldn't be named like that

xiaohangguo commented 7 months ago

Something is weird on your side. Running pyStartServer ?id "wqs" should create skill-server-wqs.sock but your file is called skill-server-wuqingsen_s07-wqs.sock. That is why Workspace.open("wqs") fails with that error.

Did you rename the .sock file? It shouldn't be named like that

Something is weird on your side. Running pyStartServer ?id "wqs" should create skill-server-wqs.sock but your file is called skill-server-wuqingsen_s07-wqs.sock. That is why Workspace.open("wqs") fails with that error.

Did you rename the .sock file? It shouldn't be named like that

ok! nice, solve it. It seems that I had modified the source sock naming to add os.get_login(), and looking at the documentation later, I found that it had indeed been implemented. I re-installed and reinstalled skillbriadge just fine.

thanks @TM90 @nielsbuwen You're all enthusiastic.

xiaohangguo commented 7 months ago

I changed the source code on userA, reinstalled it later, and changed it on userB, but userB forgot to reinstall it, so I never noticed the problem