Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore functionality of sequential runtime option #67

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.2.6

## Common

- Restored functionality of `sequential` runtime option

# 2.2.5

## CLI
Expand Down
2 changes: 1 addition & 1 deletion cace/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = '2.2.5'
__version__ = '2.2.6'

if __name__ == '__main__':
print(__version__, end='')
57 changes: 39 additions & 18 deletions cace/common/electrical_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,55 @@ def run(self):

self.cancel_point()

with ThreadPool(processes=max(cpu_count() - 1, 1)) as mypool:
# Run simulation jobs sequentially
if self.runtime_options['sequential']:

# Start the jobs
jobs = []
for sim in self.queued_jobs:
print(f'{self.param["name"]}: Starting task')
jobs.append(mypool.apply_async(sim.run, callback=self.cb_sims))

# Wait for completion
while 1:
# Start simulation job as single thread
sim.start()
presult = sim.join()

self.cancel_point()

# Check if all tasks have completed
if all([job.ready() for job in jobs]):
print(f'{self.param["name"]}: All tasks done')
break
self.new_testbenches[presult['sequence']] = presult

if self.cb_sims:
self.cb_sims()

# Run simulation jobs in parallel
else:
with ThreadPool(processes=max(cpu_count() - 1, 1)) as mypool:

# Start the jobs
jobs = []
for sim in self.queued_jobs:
print(f'{self.param["name"]}: Starting task')
jobs.append(
mypool.apply_async(sim.run, callback=self.cb_sims)
)

# Wait for completion
while 1:
self.cancel_point()

# Check if all tasks have completed
if all([job.ready() for job in jobs]):
print(f'{self.param["name"]}: All tasks done')
break

time.sleep(0.1)
time.sleep(0.1)

# Get the restuls
for job in jobs:
presult = job.get()
# Get the restuls
for job in jobs:
presult = job.get()

if presult:
# TODO make testbench name the key for easier access
self.new_testbenches[presult['sequence']] = presult
if presult:
# TODO make testbench name the key for easier access
self.new_testbenches[presult['sequence']] = presult

jobs = []
jobs = []

self.cancel_point()

Expand Down
9 changes: 8 additions & 1 deletion cace/common/simulation_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(
self.spiceproc = None

super().__init__(*args, **kwargs)
self._return = None

def cancel(self, cancel_cb):
# print(f'{self.param["name"]}: Cancel simulation: {self.testbenchlist}')
Expand Down Expand Up @@ -112,7 +113,13 @@ def run(self):
if os.path.isfile(outfilename):
os.remove(outfilename)

return tbzero if simulations > 0 else None
# For when the join function is called
self._return = tbzero if simulations > 0 else None
return self._return

def join(self, *args):
threading.Thread.join(self, *args)
return self._return

def collate_after_simulation(self, param, collnames, testbenchlist, debug):
# Sanity check: If there is only one testbench, then there is
Expand Down
3 changes: 3 additions & 0 deletions cace/gui/consoletext.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class StderrRedirector(IORedirector):
def write(self, str):
self.text_area.write(str, True)

def flush(self):
pass

def __init__(self, master=None, cnf={}, **kw):
"""See the __init__ for Tkinter.Text."""

Expand Down
Loading