Skip to content

Commit 1af2fe8

Browse files
committed
Added ability to time simulations
1 parent 9483179 commit 1af2fe8

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

simphony/simulation.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import numpy as np
2323
import copy
2424
from scipy.interpolate import interp1d
25+
import time
2526

2627
from . import models
2728
from . import netlist as nl
@@ -49,10 +50,13 @@ class MathPrefixes:
4950

5051
class Simulation:
5152
def __init__(self, netlist):
53+
start = time.time()
5254
self.s_matrix, self.frequency, self.ports, self.external_components = nl.get_sparameters(netlist)
5355
self.external_port_list = [-int(x) for x in self.ports]
5456
self.external_port_list.sort()
5557
self._rearrangeSMatrix()
58+
stop = time.time()
59+
print("Simulation time:", stop-start, "seconds.")
5660
return
5761

5862
def _rearrangeSMatrix(self):
@@ -105,7 +109,6 @@ def exportSMatrix(self):
105109

106110
import matplotlib.pyplot as plt
107111
from scipy.io import savemat
108-
import time
109112

110113
class MonteCarloSimulation:
111114
DEF_NUM_SIMS = 10
@@ -214,10 +217,15 @@ def __init__(self, netlist):
214217
super().__init__(netlist)
215218

216219
def multi_input_simulation(self, inputs: list=[]):
220+
"""
221+
Parameters
222+
----------
223+
inputs : list
224+
A 0-indexed list of the ports to be used as inputs.
225+
"""
217226
active = [0] * len(self.ports)
218227
for val in inputs:
219-
# Inputs is 1-indexed, while active is 0-indexed
220-
active[val - 1] = 1
228+
active[val] = 1
221229
self.simulated_matrix = self._measure_s_matrix(active)
222230

223231
def _measure_s_matrix(self, inputs):
@@ -238,11 +246,23 @@ def plot(self, output_port):
238246
plt.show()
239247

240248
def get_magnitude_by_frequency_thz(self, output_port):
249+
"""
250+
Parameters
251+
----------
252+
output_port : int
253+
Gets the values at that output port (0-indexed).
254+
"""
241255
freq = np.divide(self.frequency, MathPrefixes.TERA)
242256
mag = np.power(np.absolute(self.simulated_matrix[:, output_port]), 2)
243257
return freq, mag
244258

245259
def get_magnitude_by_wavelength_nm(self, output_port):
260+
"""
261+
Parameters
262+
----------
263+
output_port : int
264+
Gets the values at that output port (0-indexed).
265+
"""
246266
wl = self.frequencyToWavelength(self.frequency) / MathPrefixes.NANO
247267
mag = np.power(np.absolute(self.simulated_matrix[:, output_port]), 2)
248268
return wl, mag

0 commit comments

Comments
 (0)