1313from typing import TYPE_CHECKING
1414
1515import pandas as pd
16+ import sympy as sp
1617from pydantic import AnyUrl , BaseModel , Field
1718
1819from ..v1 import (
@@ -883,7 +884,7 @@ def validate(
883884 return validation_results
884885
885886 def add_condition (
886- self , id_ : str , name : str = None , ** kwargs : tuple [ str , Number | str ]
887+ self , id_ : str , name : str = None , ** kwargs : Number | str | sp . Expr
887888 ):
888889 """Add a simulation condition to the problem.
889890
@@ -895,27 +896,20 @@ def add_condition(
895896 """
896897 if not kwargs :
897898 return
898- records = [
899- {
900- CONDITION_ID : id_ ,
901- TARGET_ID : target_id ,
902- OPERATION_TYPE : "setCurrentValue" ,
903- TARGET_VALUE : target_value
904- if not isinstance (target_value , tuple )
905- else target_value [1 ],
906- }
899+ changes = [
900+ core .Change (target_id = target_id , target_value = target_value )
907901 for target_id , target_value in kwargs .items ()
908902 ]
909- # TODO: is the condition name supported in v2?
910- if name is not None :
911- for record in records :
912- record [CONDITION_NAME ] = [name ]
913- tmp_df = pd .DataFrame (records )
914- self .condition_df = (
915- pd .concat ([self .condition_df , tmp_df ], ignore_index = True )
916- if self .condition_df is not None
917- else tmp_df
903+ self .conditions_table .conditions .append (
904+ core .Condition (id = id_ , changes = changes )
918905 )
906+ if name is not None :
907+ self .mapping_table .mappings .append (
908+ core .Mapping (
909+ petab_id = id_ ,
910+ model_id = name ,
911+ )
912+ )
919913
920914 def add_observable (
921915 self ,
@@ -1036,27 +1030,16 @@ def add_measurement(
10361030 observable_parameters: The observable parameters
10371031 noise_parameters: The noise parameters
10381032 """
1039- record = {
1040- OBSERVABLE_ID : [obs_id ],
1041- EXPERIMENT_ID : [experiment_id ],
1042- TIME : [time ],
1043- MEASUREMENT : [measurement ],
1044- }
1045- if observable_parameters is not None :
1046- record [OBSERVABLE_PARAMETERS ] = [
1047- PARAMETER_SEPARATOR .join (map (str , observable_parameters ))
1048- ]
1049- if noise_parameters is not None :
1050- record [NOISE_PARAMETERS ] = [
1051- PARAMETER_SEPARATOR .join (map (str , noise_parameters ))
1052- ]
1053-
1054- tmp_df = pd .DataFrame (record )
1055- self .measurement_df = (
1056- pd .concat ([self .measurement_df , tmp_df ])
1057- if self .measurement_df is not None
1058- else tmp_df
1059- ).reset_index (drop = True )
1033+ self .measurement_table .measurements .append (
1034+ core .Measurement (
1035+ observable_id = obs_id ,
1036+ experiment_id = experiment_id ,
1037+ time = time ,
1038+ measurement = measurement ,
1039+ observable_parameters = observable_parameters ,
1040+ noise_parameters = noise_parameters ,
1041+ )
1042+ )
10601043
10611044 def add_mapping (self , petab_id : str , model_id : str ):
10621045 """Add a mapping table entry to the problem.
0 commit comments