How to programmatically derive specific product instances from a configurable base model?

Hi,

I’m implementing Product Line Engineering where I need to derive specific product instances from a configurable base model. My goal is to:

1. Load a base model with variable configuration (e.g., `[0..*]` multiplicity)

2. Read a feature configuration that specifies concrete values (e.g., `[4]`)

3. Programmatically generate a derived product model with fixed configuration

When I try to create the derived model using the API and serialize it with `syside.pprint()`, I get:

RuntimeError: Specialization can only be printed in KerML mode

### Base Model (base.sysml)

package VehiclePLE {

part def Wheel { }

// 150% base with variable multiplicity

part def Vehicle_Base {

part wheels : Wheel [0..*];

}

}

### Feature Configuration (using PLEML library from SysAND)

```sysml

#featureConfiguration def Sedan_Config :> VehicleProductLine {

#feature :>> useWheels \[4\];  // Specifies exactly 4 wheels for this product

}

```

### Programmatic Derivation

```python

# Load model and find base

model = syside.try_load_model([“base.sysml”, “features.sysml”])

base_vehicle = # … find Vehicle_Base

# Create derived 100% model

_, sedan = pkg.children.append(syside.OwningMembership, syside.PartDefinition)

sedan.declared_name = “Sedan_100”

# Add specialization (:> Vehicle_Base)

sedan.heritage.insert(0, syside.Specialization, base_vehicle)

# Add redefinition (part redefines wheels [4])

base_wheels = # … find wheels in base_vehicle

_, wheels_redef = sedan.children.append(syside.FeatureMembership, syside.PartUsage)

wheels_redef.declared_name = “wheels”

wheels_redef.heritage.insert(0, syside.Redefinition, base_wheels)

# Try to serialize - FAILS

output = syside.pprint(sedan) # RuntimeError: Specialization can only be printed in KerML mode

All API calls succeed and the model exists in memory, but serialization to SysML v2 fails.

### Questions

1. Is programmatic product derivation (creating specialized instances from a base model) a supported use case?

2. If so, how can I serialize the derived model to SysML v2 format?

Thanks!

Hi,

You want syside.Subclassification for part def Sedan_100 :> Vehicle_Base

Thanks for the `Subclassification` solution - it works perfectly for creating derived models!

A follow-up question: How can I programmatically set multiplicity values (e.g., `[4]`) in derived product models?

**Goal:** Generate this programmatically:

```sysml

part def Sedan :> Vehicle_Base {

part wheels :>> Vehicle_Base::wheels [4]; // Need to add [4]

}

```

**Current approach** - structure works, but missing multiplicity:

```python

# Create derived product

_, sedan = pkg.children.append(syside.OwningMembership, syside.PartDefinition)

sedan.declared_name = “Sedan”

sedan.heritage.insert(0, syside.Subclassification, vehicle_base)

# Redefine wheels

_, wheels = sedan.children.append(syside.FeatureMembership, syside.PartUsage)

wheels.declared_name = “wheels”

wheels.heritage.insert(0, syside.Redefinition, base_wheels)

# Output: part wheels :>> Vehicle_Base::wheels; ✓ works, but missing [4]

```

**What I tried:**

- Using `children.append(syside.OwningMembership, syside.MultiplicityRange)` → “MultiplicityRange can only be printed in KerML mode”

- Using `declared_multiplicity_member.add_member_element()` → same error when serializing

Is there a way to set multiplicity values programmatically that can be serialized to SysML v2?

You will need to use .declared_multiplicity and .bounds_expression_member, e.g.

# create multiplicity member
_, multi = part.declared_multiplicity_member.add_member_element()
# create multiplicity bounds expression (any expression is supported)
_, expr = multi.bounds_expression_member.set_member_element(syside.LiteralInteger)
expr.value = 4

Do note that SysML definitions cannot have multiplicity in textual syntax.

1 Like