SciML / SciML/ModelingToolkitStandardLibrary.jl

Provide keyword-free constructors for single-arg components

Open
#53 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
171
Forks
49
Avg merge
15h 50m
Merged PRs (30d)
10

Description

It would be nice if we could provide a constructor that does not require a keyword argument for components that are typically associated with a single parameter. Some examples are

  • Resistor
  • Capacitor
  • Inertia
  • Spring
  • Damper

Even if these component constructors do sometimes take more than one argument (initial state etc.) there is arguably one parameter that is going to be the only one provided most of the time.

This could be achieved with a macro applied to the constructor definitions, e.g.,

@positional C function Capacitor(;name, C, v_start=0.0) 
    ...
end

where C indicates the keyword argument that is to be provided as the single positional argument in the alternative constructor.
Alternatively, the positional constructor could be the default and the macro would add a method that takes the keyword arg instead of the positional:

@add_keyword function Capacitor(C; name, v_start=0.0) 
    ...
end

This would remove the need to remember keywords in many common cases. For example, I always call spring constants k, but the keyword in MTKSL is c.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by reviewing the constructor definitions for Resistor, Capacitor, Inertia, Spring, and Damper, then compare the proposed @positional and @add_keyword approaches. Done requires an agreed API and positional constructors for the common single-parameter cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.