-
Notifications
You must be signed in to change notification settings - Fork 222
Issue 5356 modelica measures squashed #5557
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
Conversation
- add a full Modelica parsing stack (ModelicaFile ownership/AST management, ANTLR grammar artifacts, SWIG interface, and CLI driver) so measures can inspect and edit Modelica source safely - expose ModelicaMeasure/ModelicaParameters, extend OSRunner + WorkflowJSON to pass parameters and surface the last simulation result, and wire everything through OSWorkflow with runModelica/runModelicaMeasures steps - ship a compact Modelica example workflow, measure, Modelica libraries, and README to demonstrate running the CLI end-to-end, while tightening logging, bindings, and CMake integration to make the feature production-ready
| # KSB: This is an abomination. the basic idea is that we need a full path to the crypto library | ||
| # so that we can use -force_load | ||
| # It would really be nice to have a simpler solution, but this appears to work |
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.
👀
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.
@kbenne did you mean to commit this?
| auto classDefinitions = moFile.getClassDefinitions(); | ||
|
|
||
| for (const auto& classDef : classDefinitions) { | ||
| std::cout << "Found class name: " << classDef.longClassSpecifier() << std::endl; // NOLINT |
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.
You're already importing fmt, so why not use it instead of iostream?
| ModelicaSyntax(std::shared_ptr<ModelicaFileImpl> modelicaFile, T* ctx) // NOLINT | ||
| : m_modelicaFile(std::move(modelicaFile)), m_ctx(ctx), m_id(Derived::idFromCTX(ctx)) { | ||
| if (auto file = m_modelicaFile.lock()) { | ||
| file->addModelicaSyntax(this); | ||
| } | ||
| } |
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.
Nitpick but you're using a cpp file to go with it, so why add the implementation inline in the header file?
| ModelicaSyntax(const ModelicaSyntax&) = delete; // NOLINT | ||
| ModelicaSyntax(ModelicaSyntax&&) = default; // NOLINT |
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.
(curious why NOLINT)
| namespace detail { | ||
| class ModelicaParameter_Impl | ||
| { | ||
| public: | ||
| ModelicaParameter_Impl(std::string_view model, std::string_view key, std::string_view value) : m_model(model), m_key(key), m_value(value) {} | ||
|
|
||
| std::string model() const { | ||
| return m_model; | ||
| }; | ||
|
|
||
| std::string key() const { | ||
| return m_key; | ||
| }; | ||
|
|
||
| std::string value() const { | ||
| return m_value; | ||
| } | ||
|
|
||
| void setValue(std::string_view value) { | ||
| m_value = value; | ||
| } | ||
|
|
||
| private: | ||
| std::string m_model; | ||
| std::string m_key; | ||
| std::string m_value; | ||
| }; |
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 find that weird to define the Impl fully inside the cpp file because it doesn't follow the usual convention in the repo.
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.
Generally we have a single cpp file for both Impl and the public forward methods.
| std::string ModelicaFileImpl::printTree() const { | ||
| std::stringstream ss; | ||
|
|
||
| const std::function<void(antlr4::tree::ParseTree*, antlr4::Parser*, int)> to_s = [&ss, &to_s](antlr4::tree::ParseTree* tree, antlr4::Parser* parser, |
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.
recursive std::function, fancy.
| //std::vector<ComponentDeclaration> ComponentClause::componentDeclarations() { | ||
| // std::vector<ComponentDeclaration> result; | ||
| // | ||
| // const auto component_declarations = antlr4::tree::xpath::XPath::findAll(ctx(), "//Component_declaration", parser()); | ||
| // | ||
| // for (auto* c : component_declarations) { | ||
| // auto* component_declaration_ctx = dynamic_cast<modelicaParser::Component_declarationContext*>(c); | ||
| // assert(component_declaration_ctx != nullptr); | ||
| // result.emplace_back(modelicaFile(), component_declaration_ctx); // NOLINT | ||
| // } | ||
| // | ||
| // return result; | ||
| //} | ||
|
|
||
| //std::string ComponentDeclaration::idFromCTX([[maybe_unused]] modelicaParser::Component_declarationContext* ctx) { | ||
| // // TODO | ||
| // return ""; | ||
| //} | ||
|
|
||
| //std::vector<Declaration> ClassDefinition::declarations() { | ||
| // class_definition::GetDeclarationsVisitor v; | ||
| // v.visit(m_ctx); | ||
| // return v.getResult(); | ||
| //} | ||
| // | ||
| //void ClassDefinition::addDeclaration(const std::string& declarationText) { | ||
| // const auto el = m_ctx->class_specifier()->long_class_specifier()->composition()->element_list(); | ||
| // | ||
| // antlr4::ANTLRInputStream input(declarationText + ";"); // Ensure it's a complete statement | ||
| // modelicaLexer lexer(&input); | ||
| // antlr4::CommonTokenStream tempTokens(&lexer); | ||
| // modelicaParser tempParser(&tempTokens); | ||
| // | ||
| // [[maybe_unused]] const auto* component = tempParser.component_clause(); | ||
| // | ||
| // // Attempt to parse as a component_clause (variable declaration) | ||
| // modelicaParser::Component_clauseContext* parsedDecl = nullptr; | ||
| //} | ||
| // | ||
| //Declaration::Declaration(modelicaParser::DeclarationContext* ctx) : m_ctx(ctx) {} | ||
| // | ||
| //std::string Declaration::name() const { | ||
| // return m_ctx->IDENT()->getText(); | ||
| //} |
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.
what's up with the commented code?
| if (workflowJSON.runOptions()->debug() && oriLogLevel > Debug) { | ||
| targetLogLevel = Debug; | ||
| } | ||
| LogLevel targetLogLevel = workflowJSON.runOptions()->debug() ? Debug : oriLogLevel; |
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.
Why?
Seems like you're no longer matching the comment above that says
If the user passed something like
openstudio --loglevel Trace run --debug -w workflow.osw, we retain the Trace
Summary
parse, edit, and run Modelica directly within OpenStudio.
alongside the .mat result file.
and the sample Modelica libraries you can run via the CLI.
Key Areas to Review
Notes / Follow-ups