SimServer

class spicelib.client_server.sim_server.SimServer(simulator=None, *, parallel_sims=4, output_folder='./temp', timeout=300, port=9000, host='localhost')[source]

Bases: object

This class implements a server that can run simulations by request of a client located in a different machine.

The server is implemented using the SimpleXMLRPCServer class from the xmlrpc.server module.

The client can request the server to start a session, run a simulation, check the status of the simulations and retrieve the results of the simulations. The server can run multiple simulations in parallel, but the number of parallel simulations is limited by the parallel_sims parameter.

The server can be stopped by the client by calling the stop_server method.

Parameters:
  • simulator (type | None) – The simulator to be used. It must be a class that derives from the BaseSimulator class.

  • parallel_sims (int) – The maximum number of parallel simulations that the server can run. Default is 4.

  • output_folder (str) – The folder where the results of the simulations will be stored. Default is ‘./temp’

  • timeout (float) – The maximum time that a simulation can run. Default is None, which means that there is no timeout.

  • port (int) – The port where the server will listen for requests. Default is 9000

  • host (str) – The IP address where the server will listen for requests. Default is ‘localhost’, which might mean that the server will only accept requests from the local machine. Use ‘0.0.0.0’ to accept requests from any IP address (if your firewall allows it).

add_sources(session_id, zip_data)[source]

Add sources to the simulation. The sources are contained in a zip file will be added to the simulation folder.

Returns:

True if the sources were added, False otherwise

Return type:

bool

close_session(session_id)[source]

Cleans all the pending sim_tasks with the session_id.

Returns:

True if the session was closed successfully, False otherwise

Return type:

bool

get_files(session_id, runno)[source]

Returns the files associated with a specific run number of a completed task in a session.

Parameters:
  • session_id (str) – The ID of the session to check

  • runno (int) – The run number to check

Returns:

file name and content of the file

Return type:

tuple[str, Binary]

run(session_id, circuit_name, zip_data)[source]

Runs a simulation for the given circuit.

Parameters:
  • session_id (str) – The ID of the session to run the simulation in

  • circuit_name (str) – The name of the circuit to simulate

  • zip_data (Binary) – The zip file containing the circuit files

Returns:

The run number of the simulation

Return type:

int

running()[source]

Checks if the server is currently running.

Returns:

True if the server is running, False otherwise

Return type:

bool

start_session()[source]

Returns an unique key that represents the session. It will be later used to sort the sim_tasks belonging to the session.

Returns:

A unique key that represents the session

Return type:

str

status(session_id)[source]

Returns a list with the task numbers that are completed for that session

Parameters:

session_id (str) – The ID of the session to check

Returns:

A list of completed task numbers for the session

Return type:

list[int]

stop_server()[source]

Stops the server and cleans up resources.

Returns:

True if the server was stopped successfully, False otherwise

Return type:

bool