Repository navigation
fix(runtime): judge a written quantity by classification and by the quantity value type it is held as - #2287
Merged
Conversation
…ms its type A quantity bypassed the shared classification on a write: a target fixing no dimension held it unjudged and a scalar target judged it as a bare Rational, so a Real, Number or unrelated attribute definition held a quantity that istype denies. The write now asks classifyValue, keeping the dimension wording for a refusal by dimension. Co-Authored-By: jason.han <hanhuijun@gmail.com>
A feature declared by a quantity value type marks the quantity it holds as of that type, so istype, hastype, as and a later write read it: a sibling type of the same dimension refuses it, a supertype or subtype holds it, and a quantity an operator computes or `[` constructs carries no kind. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
…nrelated to the one it is held as Co-Authored-By: jason.han <hanhuijun@gmail.com>
…alue type Co-Authored-By: jason.han <hanhuijun@gmail.com>
…d as Co-Authored-By: jason.han <hanhuijun@gmail.com>
…it is held as Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
…nt is held as Co-Authored-By: jason.han <hanhuijun@gmail.com>
…e that resolves differently Co-Authored-By: jason.han <hanhuijun@gmail.com>
…the scalar lattice Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
There was a problem hiding this comment.
Devin Review found 2 findings. Devin automatically fixed all 2 findings.
Fixed by Devin (2)
- Quantity kind is lost over gRPC — The wire quantity now carries the quantity value type it is held as (Quantity.value_type), the service validates and restores it on the way back in, and every client keeps it; a round-trip test pins the sibling refusal.
- Document queries drop quantity value types — A quantity a document query reads off a feature now keeps the quantity value type it is held as, on both the folded and the evaluated path, and the gRPC and JSON document encoders send it; a test pins that the sibling type refuses it sent back.
…t the value it evaluates to The fixture bound a quantity to a Real feature, which a quantity is not (SysML v2.1 9.8.2), so enginedemo::speed evaluated to a type mismatch and the parity tests compared two equal errors. Co-Authored-By: jason.han <hanhuijun@gmail.com>
…ents Co-Authored-By: jason.han <hanhuijun@gmail.com>
…d, as before A feature typed by a ScalarMeasurementReference keeps holding a quantity written to it (hp : PowerUnit = 745.7 [W] in the OMG individuals example), the contract the function-library map and TestBoundMeasurementUnit record. The row's claim about the pilot is corrected to what it does. Co-Authored-By: jason.han <hanhuijun@gmail.com>
…ce family A feature typed by any TensorMeasurementReference (a unit, scale, vector reference or coordinate frame) holds a quantity written to it, as before this branch. The written-value row states that one unjudged write and stays approximate until it is ruled on. Co-Authored-By: jason.han <hanhuijun@gmail.com>
…quantity-and-scalar-kinds
… the wire A quantity left the service without the quantity value type it was held as, so one read off an EnergyValue feature and sent back was taken by a TorqueValue parameter. Quantity.value_type (valueType in JSON) names that type; the service resolves it in the receiving model and refuses a name that is no quantity value type or fixes another dimension. Every client keeps the field and sends it back. Co-Authored-By: jason.han <hanhuijun@gmail.com>
…t query answers Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
…quantity-and-scalar-kinds Co-Authored-By: jason.han <hanhuijun@gmail.com> # Conflicts: # client/node/src/generated/sysml_pb.ts # client/python/opensysml/proto/sysml_pb2.py # client/rust/conformance/sysml.descriptor.binpb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
The compliance row "A value written to a feature conforms to that feature's declared type" (Action map) was⚠️ because a written quantity was not judged by the relation every other value is. Two defects on
develop:classifyValueon a write.quantityConformsjudged a scalar target as if the quantity were a bareRational, and held the quantity unjudged wherever the target fixed no dimension. SoReal,Number, a subtype ofRealand an unrelatedattribute def Count;all held5.0 [m], although5.0 [m] istype Realisfalse.EnergyValuefeature's value was held by aTorqueValuefeature, andenergy istype TorqueValuewastrue.Changes in
internal/exec/runtime:write_conformance.goquantityConformsasksclassifyValue;dimensionRefusalkeeps the two-dimension wording for a refusal by dimension (also used for vector and tensor components, whose typestructuredConformsalready judges).value.gomeasured/Value.ofQuantityKind/Value.QuantityKindandwrite_conformance.goholdAsMeasured: a feature declared by a specialization ofScalarQuantityValuemarks the quantity it holds as of that type. A quantity[constructs or an operator computes carries none (the operators returnScalarQuantityValue).classification.goclassifyValue: the held type is one of the quantity's types, so a supertype or subtype holds it afterwards and an unrelated quantity value type refuses it, also when it is read through a wider feature (general : ScalarQuantityValue = work).hastypestill answers by the quantity's own type,ScalarQuantityValue.dependents.goheldSame: a derivation is evaluated again when a feature comes to hold an equal quantity as another quantity value type.expr_tree.govalueArgument: overload selection types a quantity argument by the type it is held as.adopt.go: a carry-over into a re-analysis rebinds the held type, and refuses the object where that type resolves differently now.Across the wire (
api/proto,internal/frontend/protoconv,internal/frontend/engine, the clients):EnergyValuefeature and sent back as a calculation argument was taken by aTorqueValueparameter.Quantity.value_type(field 7;valueTypein JSON) now names the held quantity value type by qualified name, empty for none.protoconv.ProtoToQuantityand the engine'sprotoToQuantityresolve a name in the receiving model and hold the quantity throughruntime.QuantityHeldAs, which refuses a name that is no proper specialization ofScalarQuantityValue(semantics.Model.IsQuantityValueType) or that fixes another dimension than the unit.docs/reference/wire-contract.mddocuments it. The field is additive (make proto-breakingpasses) and no capability governs it.One change in
internal/check/passes, found by the corpus guard over the new fixture:typecheck_value.gocheckElementConformance: a literal bound to a supertype of its scalar type that is not itself in the scalar lattice (n : ScalarValues::NumericalValue = 0.5, orScalarValue) was reported ascannot bind Rational value to a feature typed by NumericalValue. It is now accepted where the type generalizes the literal's scalar type; an unrelated literal ("hello") is reported as before. The run time already held these values.Specification basis
Feature::type): "the values must be instances of all the types" — a write is held exactly where classification affirms the type.[constructs aScalarQuantityValue, which specializesTensorQuantityValueandNumericalValue, notReal; "all direct specializations of (abstract) ScalarQuantityValue … must be disjoint … all lower level specializations … must be disjoint at each sibling level"; "EnergyValue and TorqueValue have the same quantity dimension … but it is not valid to add an energy quantity to a torque quantity".AssignmentNode/FeatureValueparse as before).tq : TorqueValue = eandr : Real = e(withe : EnergyValue) and is silent onReal = 5 [s]; this change is stricter than the pilot and follows the clause text.Row restated, still⚠️ (every write is judged by classification except a quantity written to a measurement-reference-typed feature, pending the maintainer ruling below):
docs/project/spec-compliance/02-detailed-semantic-compliance-map/13-action.md, the written-value row.Stated limits
e : EnergyValue, bothtq : TorqueValue = ConvertQuantity(e, N*m)andtq : TorqueValue = e + 0 [J]are held, whiletq : TorqueValue = eis refused. Basis: theQuantityCalculationslibrary model (SysML v2.1 §9.8, Quantities and Units Domain Library) declares the result of every operator and ofConvertQuantityasScalarQuantityValue(calc def '+' … return : ScalarQuantityValue;,calc def ConvertQuantity { in x: ScalarQuantityValue[1]; in targetMRef: ScalarMeasurementReference[1]; return : ScalarQuantityValue[1]; }), not as the type of an operand, and KerML 1.1 §8.3.3.3.4 asks only that the value be an instance of the feature's types. A result is therefore a quantity of its dimension and of no particular quantity value type until a typed feature holds it; refusing it would be stricter than the clause text. The same holds for a value converted onto or off a measurement scale.attribute hp : PowerUnit = 745.7 [SI::W];(examples/pilot-corpora/sysml-examples/Individuals Examples/AnalysisIndividualExample.sysml, line 23) evaluates to745.7 [SI::W], as ondevelop:quantityConformsdoes not judge a quantity written to a feature whose type specializesMeasurementReferences::TensorMeasurementReference— units, scales, coordinate frames and the vector and tensor references above them — (decided by specialization, not by name), which keeps the contract the measurement-reference row of18-kerml-function-library.mdandpasses.TestBoundMeasurementUnitrecord.value_conformance_test.go:TestQuantityIsHeldUnjudgedByAUnitTypedFeaturepins it, with aVectorMeasurementReference, aTensorMeasurementReferenceand aCoordinateFrameholding it both bound and written, andReal, an unrelated definition, aUnitConversionand a quantity value type of another dimension still refusing the same quantity.developjudged a quantity only against a primitive scalar type or a type with a dimension, so it also held one in every other definition, among them theMeasurementReferencestypes outside that family (UnitConversion,UnitPrefix,QuantityValueMapping); those are not measurement references and are refused here like any unrelated definition. That row's wording "as the pilot implementation accepts it" is corrected to what the pilot (2026-09.1) does: the validator reports nothing on the line, and the expression evaluator returns the[operator expression unreduced, so neither judges the type. The question: by KerML 1.1 §8.3.3.3.4 this write should be refused, since aScalarQuantityValueis not an instance ofPowerUnit, aMeasurementUnit(SysML v2.1 §9.8.3.2.19, "a ScalarMeasurementReference that represents a measurement unit"). The conforming declaration of such a unit is the one §9.8.3.2.19 (unitConversion : UnitConversion [0..1], "a linear conversion relationship with respect to another MeasurementUnit") and §9.8.3.2.3 (ConversionByConvention, withreferenceUnitandconversionFactor) give, and the oneUSCustomaryUnitsuses for horsepower itself:attribute <hp> 'horsepower (550 ft*lbf/s)' : PowerUnit { :>> unitConversion: ConversionByConvention { :>> referenceUnit = W; :>> conversionFactor = 7.456999E+02; :>> isExact = false; } }. Against refusing: besides the OMG example, the standard library binds a quantity to a unit-typed feature in eight places inISQSpaceTime(azimuth : AngularMeasureUnit = num#(2) [mRef.mRefs#(2)]and its like in the cylindrical, spherical and planetary position vectors), possibly an erratum forAngularMeasureValue. Those eight do not evaluate ondevelopor here for another reason (not a measurement unit expression, the unit operand beingmRef.mRefs#(i); theLengthValuecomponents beside them fail the same way), so this change does not touch them either way. No other file inexamples/or the training, pilot and specification-example corpora binds a quantity to a unit-typed feature (text search). Whether to refuse the write, and with it report the binding statically, is left for a maintainer ruling.speed : Real = 10.0 [m] / 2.0 [s], which validates clean); the refusal is raised when the value is evaluated.How it was verified
New tests, failing on
develop:value_conformance_test.go:TestQuantityIsHeldByTheTypesItIsOf,TestQuantityHeldAsAKindIsRefusedByASiblingKind,TestQuantityKindIsReadThroughAWiderFeatureAndByDerivations,TestAdoptCarriesTheQuantityKindAWrittenQuantityIsHeldAs,TestAdoptRefusesAQuantityHeldAsAChangedQuantityKind,TestCalcCallSelectsByTheQuantityKindAnArgumentIsHeldAsrobustness_quantities_test.go:quantity_write_to_a_type_no_quantity_is_ofconformance
assign_quantity_write_violates_scalar_type,assign_quantity_write_conforms_to_supertypeinternal/check/passes/typecheck_expr_test.go:TestExprBindLiteralToAScalarSupertypeinternal/frontend/grpc/convert_quantity_value_type_test.go:TestQuantityValueTypeRoundTrip(an energy read and sent back is refused by a torque parameter, taken by an energy one; the same quantity without a type is taken by both),TestQuantityValueTypeIsChecked(undeclared names, a calculation, a feature, a scalar type,ScalarQuantityValue, a unit, another dimension)client/opensysml/quantity_value_type_test.goover the in-process, Connect protobuf and Connect JSON transports, and a round-trip test in each of the Python, Node, Rust, Java, Julia and MATLAB clientsExisting expectations that moved, each adjudicated:
conformance/action_quantity_assign.sysmlwrote10.0 [m] / 2.0 [s]tospeed : Real. A quantity is not aReal; the fixture now declaresspeed : ISQ::SpeedValue, its expected output unchanged.tests/wasm/testdata/engine.sysmldeclaredspeed : Real = 10.0 [SI::m] / 2.0 [SI::s]; it now declaresISQ::SpeedValue.TestEngineWireParityandTestCombinedWireParityonly compared the two transports, which agreed on the type mismatch, so they now assert throughwantSpeedAnswerthatenginedemo::speedevaluates to the quantity 5 m/s (they fail with the old declaration).client/node/test/wasm.test.tsreads the same fixture and asserts a quantity.robustness_quantities_test.go"scale whose mapping maps a quantity, not a definitional value": stillErrTypeMismatch, now raised when theQuantityValueMappingbinds the quantity tomappedQuantityValue : DefinitionalQuantityValue, ahead of the scale reading it.editors/vscode/src/landing/mass.jsonandmission.jsonare regenerated (-update-landing): the only movement isvalueTypeon the quantities typed features hold.tests/wasmwantSpeedAnsweralso requiresenginedemo::speedto be held asISQSpaceTime::SpeedValue.No corpus baseline moved.
Gates run locally on the head (current
developmerged):gofmt -l .(empty),go build ./...,go vet ./...,make lint,make proto-lint proto-breaking,python3 scripts/spec_compliance.py check,python3 scripts/changelog.py check, andgo test -count=1 -timeout 40m ./...with the training, pilot and specification-example corpora required (without-race). Every package passes except one subtest oftests/wasm, the engine size budget: gzippedsysml-engine.wasmis 11,105,256 bytes against 11,100,000.developalone measures 11,094,557 and this branch merged with it before the wire change 11,102,533; the budget is not touched here (#2319 raises it). Client suites against a locally builtsysml-grpc: Go, Python (1822 passed), Node (493 passed, 1 skipped), Rust, Java and Julia pass; the MATLAB tests were not run (no Octave on the machine).Checklist
make testandmake lintpass locally (make lintpasses; the suite was run asgo test ./..., without the race detector)changes/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (none moved)F4,K5) in the body, docs, or changelogLink to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/d78af7b1ace947d8b56c3a65eb35a256
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/d78af7b1ace947d8b56c3a65eb35a256?variant=devin
Requested by: @HuiJun
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work