-
Notifications
You must be signed in to change notification settings - Fork 47
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
Extended Amici history #1263
Merged
Merged
Extended Amici history #1263
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2528989
add extended history for AmiciObjective
plakrisenko 293f8b7
test amici history
plakrisenko 50f582b
add _simulation_to_values method
plakrisenko 29e5f7e
add CsvAmiciHistory
plakrisenko 4d8d34f
docstrings
plakrisenko 079dbd6
fix typo
plakrisenko 6606558
spell out Backward
plakrisenko ec77861
import order
plakrisenko 3ac4073
Merge branch 'develop' into amici_history
m-philipps 1bd4fc7
black
m-philipps 92b8c5e
convert ms to s
plakrisenko ed63dfe
no amici in pypesto.optimize
plakrisenko 8c0fdfb
Update test/base/test_history.py
plakrisenko 26059db
Update pypesto/optimize/optimizer.py
plakrisenko 926620b
delete files in the test
plakrisenko 1388693
style
plakrisenko b6a750e
Merge branch 'develop' into amici_history
plakrisenko f543041
isort
plakrisenko ddeee94
black
plakrisenko 994900c
Update pypesto/history/amici.py
plakrisenko fce0037
more compact code
plakrisenko 996b21e
Merge branch 'develop' into amici_history
plakrisenko dcc8cd7
Merge branch 'develop' into amici_history
plakrisenko 1d96334
Merge branch 'develop' into amici_history
plakrisenko 7822cab
Merge branch 'develop' into amici_history
plakrisenko 9c9a229
Merge branch 'develop' into amici_history
plakrisenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
from pathlib import Path | ||
from typing import Sequence, Union | ||
|
||
import numpy as np | ||
|
||
from ..C import ( | ||
CPU_TIME_TOTAL, | ||
POSTEQ_CPU_TIME, | ||
POSTEQ_CPU_TIME_BACKWARD, | ||
PREEQ_CPU_TIME, | ||
PREEQ_CPU_TIME_BACKWARD, | ||
RDATAS, | ||
) | ||
from .csv import CsvHistory | ||
from .hdf5 import Hdf5History | ||
from .options import HistoryOptions | ||
from .util import trace_wrap | ||
|
||
|
||
class Hdf5AmiciHistory(Hdf5History): | ||
""" | ||
Stores history extended by AMICI-specific time traces in an HDF5 file. | ||
|
||
Stores AMICI-specific traces of total simulation time, pre-equilibration | ||
time and post-equilibration time. | ||
|
||
Parameters | ||
---------- | ||
id: | ||
Id of the history | ||
file: | ||
HDF5 file name. | ||
options: | ||
History options. Defaults to ``None``. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
id: str, | ||
file: Union[str, Path], | ||
options: Union[HistoryOptions, dict, None] = None, | ||
): | ||
super().__init__(id, file, options=options) | ||
|
||
@staticmethod | ||
def _simulation_to_values(x, result, used_time): | ||
values = Hdf5History._simulation_to_values(x, result, used_time) | ||
# default unit for time in amici is [ms], converted to [s] | ||
values |= { | ||
plakrisenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CPU_TIME_TOTAL: sum( | ||
[rdata[CPU_TIME_TOTAL] for rdata in result[RDATAS]] | ||
)*0.001, | ||
PREEQ_CPU_TIME: sum( | ||
[rdata[PREEQ_CPU_TIME] for rdata in result[RDATAS]] | ||
)*0.001, | ||
PREEQ_CPU_TIME_BACKWARD: sum( | ||
[rdata[PREEQ_CPU_TIME_BACKWARD] for rdata in result[RDATAS]] | ||
)*0.001, | ||
POSTEQ_CPU_TIME: sum( | ||
[rdata[POSTEQ_CPU_TIME] for rdata in result[RDATAS]] | ||
)*0.001, | ||
POSTEQ_CPU_TIME_BACKWARD: sum( | ||
[rdata[POSTEQ_CPU_TIME_BACKWARD] for rdata in result[RDATAS]] | ||
)*0.001, | ||
} | ||
return values | ||
|
||
@trace_wrap | ||
def get_cpu_time_total_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative simulation CPU time [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return self._get_hdf5_entries(CPU_TIME_TOTAL, ix) | ||
|
||
@trace_wrap | ||
def get_preeq_time_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative pre-equilibration time, [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return self._get_hdf5_entries(PREEQ_CPU_TIME, ix) | ||
|
||
@trace_wrap | ||
def get_preeq_timeB_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative pre-equilibration time of the backward problem, [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return self._get_hdf5_entries(PREEQ_CPU_TIME_BACKWARD, ix) | ||
|
||
@trace_wrap | ||
def get_posteq_time_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative post-equilibration time [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return self._get_hdf5_entries(POSTEQ_CPU_TIME, ix) | ||
|
||
@trace_wrap | ||
def get_posteq_timeB_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative post-equilibration time of the backward problem [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return self._get_hdf5_entries(POSTEQ_CPU_TIME_BACKWARD, ix) | ||
|
||
|
||
class CsvAmiciHistory(CsvHistory): | ||
""" | ||
Stores history extended by AMICI-specific time traces in a CSV file. | ||
|
||
Stores AMICI-specific traces of total simulation time, pre-equilibration | ||
time and post-equilibration time. | ||
|
||
Parameters | ||
---------- | ||
file: | ||
CSV file name. | ||
x_names: | ||
Parameter names. | ||
options: | ||
History options. | ||
load_from_file: | ||
If True, history will be initialized from data in the specified file. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
file: str, | ||
x_names: Sequence[str] = None, | ||
options: Union[HistoryOptions, dict] = None, | ||
load_from_file: bool = False, | ||
): | ||
super().__init__(file, x_names, options, load_from_file=load_from_file) | ||
|
||
def _trace_columns(self) -> list[tuple]: | ||
columns = super()._trace_columns() | ||
return columns + [ | ||
(c, np.nan) | ||
for c in [ | ||
CPU_TIME_TOTAL, | ||
PREEQ_CPU_TIME, | ||
PREEQ_CPU_TIME_BACKWARD, | ||
POSTEQ_CPU_TIME, | ||
POSTEQ_CPU_TIME_BACKWARD, | ||
] | ||
] | ||
|
||
def _simulation_to_values(self, result, used_time): | ||
values = super()._simulation_to_values(result, used_time) | ||
# default unit for time in amici is [ms], converted to [s] | ||
values |= { | ||
plakrisenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CPU_TIME_TOTAL: sum( | ||
[rdata[CPU_TIME_TOTAL] for rdata in result[RDATAS]] | ||
)*0.001, | ||
PREEQ_CPU_TIME: sum( | ||
[rdata[PREEQ_CPU_TIME] for rdata in result[RDATAS]] | ||
)*0.001, | ||
PREEQ_CPU_TIME_BACKWARD: sum( | ||
[rdata[PREEQ_CPU_TIME_BACKWARD] for rdata in result[RDATAS]] | ||
)*0.001, | ||
POSTEQ_CPU_TIME: sum( | ||
[rdata[POSTEQ_CPU_TIME] for rdata in result[RDATAS]] | ||
)*0.001, | ||
POSTEQ_CPU_TIME_BACKWARD: sum( | ||
[rdata[POSTEQ_CPU_TIME_BACKWARD] for rdata in result[RDATAS]] | ||
)*0.001, | ||
} | ||
return values | ||
|
||
@trace_wrap | ||
def get_cpu_time_total_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative simulation CPU time [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return list(self._trace[(CPU_TIME_TOTAL, np.nan)].values[ix]) | ||
|
||
@trace_wrap | ||
def get_preeq_time_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative pre-equilibration time [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return list(self._trace[(PREEQ_CPU_TIME, np.nan)].values[ix]) | ||
|
||
@trace_wrap | ||
def get_preeq_timeB_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative pre-equilibration time of the backward problem [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return list(self._trace[(PREEQ_CPU_TIME_BACKWARD, np.nan)].values[ix]) | ||
|
||
@trace_wrap | ||
def get_posteq_time_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative post-equilibration time [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return list(self._trace[(POSTEQ_CPU_TIME, np.nan)].values[ix]) | ||
|
||
@trace_wrap | ||
def get_posteq_timeB_trace( | ||
self, ix: Union[int, Sequence[int], None] = None, trim: bool = False | ||
) -> Union[Sequence[float], float]: | ||
""" | ||
Cumulative post-equilibration time of the backward problem [s]. | ||
|
||
Takes as parameter an index or indices and returns corresponding trace | ||
values. If only a single value is requested, the list is flattened. | ||
""" | ||
return list(self._trace[(POSTEQ_CPU_TIME_BACKWARD, np.nan)].values[ix]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it's
@staticmethod
, but nCsvAmiciHistory
it'ssuper()...
. Just curious, why?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
CsvHistory
it's not static as it uses dynamically updated attributes (e.g._n_fval
), inHdf5History
it's not the case, so I made the methods static both inHdf5History
andHdf5AmiciHistory
.