variables_to_names, _ = get_variables_name_mapping(root, root_key=model_key)
// In case of a MirroredVariable, look up the primary variable
variable = get_primary_variable(variable)
return variables_to_names.get(variable.ref())
def get_primary_variable(variable):
If :obj:`variable` is distributed, returns the primary component.
After Change
def get_variable_name(variable, root, model_key="model"):
Gets the variable name in the object-based representation.
names_to_variables = get_variables_name_mapping(root, root_key=model_key)
for name, var in names_to_variables.items():
if var is variable:
return name
return None
def get_primary_variable(variable):
If :obj:`variable` is distributed, returns the primary component.