SimClient¶
- class spicelib.client_server.sim_client.SimClient(host_address, port)[source]¶
Bases:
objectClass used for launching simulations in a Spice Simulation Server. A Spice Simulation Server is a machine running a script with an active SimServer object.
This class only implement basic level handshaking with a single simulation Server. Upon instance, it will establish a connection with Simulation Server. This connection is kept alive during the whole live of this object.
The run() method will transfer the netlist for the server, execute a simulation and transfer the simulation results back to the client.
Data is returned from the server inside a zipfie which is copied into the directory defined when the job was created, /i.e./ run() method called.
Two lists are kept by this class:
A list of started jobs (started_jobs) and,
a list with finished jobs on the server, but, which haven’t been yet transferred to the client (stored_jobs).
This distinction is important because the data is erased on the server side when the data is transferred.
This class implements an iterator that is to be used for retrieving the job. See the example below. The iterator polls the server with a time interval defined by the attribute
minimum_time_between_server_calls. This attribute is set to 0.2 seconds by default, but it can be overriden.Usage:
import zipfile from PySpice.sim.sim_client import SimClient server = SimClient('http://localhost', 9000) # Use another computer address. print(server.session_id) runid = server.run("../../tests/testfile.net") print("Got Job id", runid) for runid in server: # may not arrive in the same order as runids were launched zip_filename = server.get_runno_data(runid) print(f"Received {zip_filename} from runid {runid}") if zip_filename is None: print(f"Run id {runid} has no data") continue # the zip file normally contains a `.raw` and a `.log` file, # but it can instead only hold a `.fail` file in case of a simulation error. with zipfile.ZipFile(zip_filename, 'r') as zipf: # Extract the contents of the zip file for name in zipf.namelist(): print(f"Extracting {name} from {zip_filename}") zipf.extract(name) os.remove(zip_filename) # Remove the zip file
NOTE: More elaborate algorithms such as managing multiple servers will be done on another class.
- add_sources(sources)[source]¶
Add sources to the simulation environment. The sources are a list of file paths that are going to be transferred to the server. The server will add the sources to the simulation folder. Returns True if the sources were added and False if the session_id is not valid.
- get_runno_data(runno)[source]¶
Returns the simulation output data inside a zip file name.
- Returns:
The name of the zip file containing the simulation output data, or None if not found. The zip file is not guaranteed to hold both a .raw file and a .log file. It can hold a .fail file in case of a simulation error.
- Return type:
Path | None
- run(circuit, dependencies=None)[source]¶
Sends the netlist identified with the argument “circuit” to the server, and it receives a run identifier (runno). Since the server can receive requests from different machines, this identifier is not guaranteed to be sequential.
- Parameters:
circuit (str | Path) – path to the netlist file containing the simulation directives.
dependencies (list[str | Path] | None) – list of files that the netlist depends on. This is used to ensure that the netlist is transferred to the server with all the necessary files.
- Returns:
identifier on the server of the simulation.
- Return type:
int