-
Notifications
You must be signed in to change notification settings - Fork 34
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
Feat/parameter scan #74
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5429de3
feat: simulate and query multiple models
gurdeep330 fea4600
fix: address review requests
gurdeep330 63b5566
feat: update README
gurdeep330 5827df0
feat: add parameter_scan tool
gurdeep330 527fb29
Merge branch 'main' into feat/parameter-scan
gurdeep330 62ab846
fix: tests
gurdeep330 4d8ead7
fix: address reviewer requests
gurdeep330 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
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 |
---|---|---|
|
@@ -119,6 +119,68 @@ def test_simulate_model_tool(): | |
# Check if the data of the second model contains | ||
assert 'mTORC2' in dic_simulated_data[1]['data'] | ||
|
||
def test_param_scan_tool(): | ||
''' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The explanation is much appreciated 😊 |
||
In this test, we will test the parameter_scan tool. | ||
We will prompt it to scan the parameter `kIL6RBind` | ||
from 1 to 100 in steps of 10, record the changes | ||
in the concentration of the species `Ab{serum}` in | ||
model 537. | ||
|
||
We will pass the inaccuarate parameter (`KIL6Rbind`) | ||
and species names (just `Ab`) to the tool to test | ||
if it can deal with it. | ||
|
||
We expect the agent to first invoke the parameter_scan | ||
tool and raise an error. It will then invoke another | ||
tool get_modelinfo to get the correct parameter | ||
and species names. Finally, the agent will reinvoke | ||
the parameter_scan tool with the correct parameter | ||
and species names. | ||
|
||
''' | ||
unique_id = 123 | ||
app = get_app(unique_id) | ||
config = {"configurable": {"thread_id": unique_id}} | ||
app.update_state(config, {"llm_model": "gpt-4o-mini"}) | ||
prompt = """How will the value of Ab in model 537 change | ||
if the param kIL6Rbind is varied from 1 to 100 in steps of 10? | ||
Set the initial `DoseQ2W` concentration to 300. | ||
Reset the IL6{serum} concentration to 100 every 500 hours. | ||
Assume that the model is simulated for 2016 hours with | ||
an interval of 2016.""" | ||
# Invoke the agent | ||
app.invoke( | ||
{"messages": [HumanMessage(content=prompt)]}, | ||
config=config | ||
) | ||
current_state = app.get_state(config) | ||
reversed_messages = current_state.values["messages"][::-1] | ||
# Loop through the reversed messages until a | ||
# ToolMessage is found. | ||
df = pd.DataFrame(columns=['name', 'status', 'content']) | ||
names = [] | ||
statuses = [] | ||
contents = [] | ||
for msg in reversed_messages: | ||
# Assert that the message is a ToolMessage | ||
# and its status is "error" | ||
if not isinstance(msg, ToolMessage): | ||
continue | ||
names.append(msg.name) | ||
statuses.append(msg.status) | ||
contents.append(msg.content) | ||
df = pd.DataFrame({'name': names, 'status': statuses, 'content': contents}) | ||
# print (df) | ||
assert any((df["status"] == "error") & | ||
(df["name"] == "parameter_scan") & | ||
(df["content"].str.startswith("Error: ValueError('Invalid parameter name:"))) | ||
assert any((df["status"] == "success") & | ||
(df["name"] == "parameter_scan") & | ||
(df["content"].str.startswith("Parameter scan results of"))) | ||
assert any((df["status"] == "success") & | ||
(df["name"] == "get_modelinfo")) | ||
|
||
def test_integration(): | ||
''' | ||
Test the integration of the tools. | ||
|
@@ -184,9 +246,9 @@ def test_integration(): | |
reversed_messages = current_state.values["messages"][::-1] | ||
# Loop through the reversed messages | ||
# until a ToolMessage is found. | ||
expected_header = ['Time', 'CRP[serum]', 'CRPExtracellular'] | ||
expected_header = ['Time', 'CRP{serum}', 'CRPExtracellular'] | ||
expected_header += ['CRP Suppression (%)', 'CRP (% of baseline)'] | ||
expected_header += ['CRP[liver]'] | ||
expected_header += ['CRP{liver}'] | ||
dmccloskey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
predicted_artifact = [] | ||
for msg in reversed_messages: | ||
if isinstance(msg, ToolMessage): | ||
|
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.
I like the choice to split these two methods 👍