mario.Database.to_cvxlab
- Database.to_cvxlab(*, model_settings, path, mapping, scenarios='baseline')#
Fill CVXLab set and input workbooks using explicit name mappings.
- Parameters:
model_settings (str or pathlib.Path) – CVXLab
model_settings.xlsxworkbook defining sets, input tables, variables and the symbolic problem.path (str or pathlib.Path) – Destination model directory. The method writes the settings,
sets.xlsxandinput_data/input_data.xlsxworkbooks.mapping (dict) – Dictionary containing
setsandmatricesdictionaries. Set keys use MARIO flat coordinates such asActivity_to,Commodity_fromorScenario. Values name CVXLab sets, includingcopy_fromsets. A list of destination sets is accepted. Bare MARIO set names apply to either populated side. Matrix keys name MARIO matrices and values name CVXLab exogenous data tables, as defined in the settings workbook. Multiple matrices can populate one table when their mapped coordinates are disjoint.scenarios (str or iterable of str, optional) – Existing MARIO scenarios to transfer. Defaults to
"baseline". Multiple scenarios require an explicitScenariomapping.
- Returns:
Paths under
path,sets_fileandinput_files, together withwritten_cellsby CVXLab table andpending_sets,missing_attributes,pending_matrices,unmapped_tables,unmatched_coordinates,missing_valuesandextra_input_rowsdiagnostics. Extra input rows count existing records outside the current CVXLab coordinate/filter domain. Pending matrices list the additional CVXLab set coordinates needed before those matrices can be transferred.- Return type:
dict
Notes
Requires the optional
cvxlabpackage. CVXLab generates the workbook structures. Existing set members and attributes are kept, new mapped members are appended, and mapped matrix cells are updated by their coordinates. Other input tables and workbook sheets retain their existing contents. Missing information is reported so that the method can be called again after completion.Source axes with multiple labels require mappings. A singleton source axis can be omitted, and an additional target coordinate with one defined member can be filled automatically. Target coordinates filtered by CVXLab determine the rows to update. The report counts source rows outside those coordinates. Values use the units of the selected MARIO matrices.
Workbooks are prepared before destination files are updated. Concurrent exports to the same destination are rejected, and a failed file replacement restores the previous files. The returned workbooks provide inputs for subsequent CVXLab model initialization.
See Prepare CVXLab inputs for a downloadable settings workbook and an executable example.