simparse 0.3.3__tar.gz → 0.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of simparse might be problematic. Click here for more details.
- {simparse-0.3.3 → simparse-0.3.4}/Cargo.lock +5 -4
- {simparse-0.3.3 → simparse-0.3.4}/Cargo.toml +1 -1
- {simparse-0.3.3 → simparse-0.3.4}/PKG-INFO +18 -1
- {simparse-0.3.3 → simparse-0.3.4}/README.md +17 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/Cargo.toml +1 -0
- simparse-0.3.4/crates/simparse-core/examples/ir_asset_probe.rs +444 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/dispatch.rs +23 -3
- simparse-0.3.4/crates/simparse-core/src/ir.rs +264 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/lib.rs +4 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/parsers/mod.rs +2 -0
- simparse-0.3.4/crates/simparse-core/src/parsers/simulink.rs +1029 -0
- simparse-0.3.4/crates/simparse-core/src/parsers/step.rs +302 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/schema.rs +17 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/summary.rs +81 -1
- simparse-0.3.4/crates/simparse-core/tests/simulink.rs +419 -0
- simparse-0.3.4/crates/simparse-core/tests/step_ir.rs +209 -0
- {simparse-0.3.3 → simparse-0.3.4}/pyproject.toml +1 -1
- {simparse-0.3.3 → simparse-0.3.4}/LICENSE +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/error.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/parsers/abaqus.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/parsers/comsol.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/parsers/flotherm.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/parsers/hfss.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/src/parsers/icepak.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-core/tests/synthetic.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-hdf5/Cargo.toml +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-hdf5/src/lib.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-py/Cargo.toml +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/crates/simparse-py/src/lib.rs +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/python/simparse/__init__.py +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/python/simparse/__init__.pyi +0 -0
- {simparse-0.3.3 → simparse-0.3.4}/python/simparse/py.typed +0 -0
|
@@ -826,7 +826,7 @@ checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
|
|
826
826
|
|
|
827
827
|
[[package]]
|
|
828
828
|
name = "simparse-cli"
|
|
829
|
-
version = "0.3.
|
|
829
|
+
version = "0.3.4"
|
|
830
830
|
dependencies = [
|
|
831
831
|
"anyhow",
|
|
832
832
|
"clap",
|
|
@@ -837,13 +837,14 @@ dependencies = [
|
|
|
837
837
|
|
|
838
838
|
[[package]]
|
|
839
839
|
name = "simparse-core"
|
|
840
|
-
version = "0.3.
|
|
840
|
+
version = "0.3.4"
|
|
841
841
|
dependencies = [
|
|
842
842
|
"flate2",
|
|
843
843
|
"quick-xml",
|
|
844
844
|
"schemars",
|
|
845
845
|
"serde",
|
|
846
846
|
"serde_json",
|
|
847
|
+
"sha2",
|
|
847
848
|
"simparse-hdf5",
|
|
848
849
|
"tar",
|
|
849
850
|
"tempfile",
|
|
@@ -854,7 +855,7 @@ dependencies = [
|
|
|
854
855
|
|
|
855
856
|
[[package]]
|
|
856
857
|
name = "simparse-hdf5"
|
|
857
|
-
version = "0.3.
|
|
858
|
+
version = "0.3.4"
|
|
858
859
|
dependencies = [
|
|
859
860
|
"flate2",
|
|
860
861
|
"hdf5-pure",
|
|
@@ -867,7 +868,7 @@ dependencies = [
|
|
|
867
868
|
|
|
868
869
|
[[package]]
|
|
869
870
|
name = "simparse-py"
|
|
870
|
-
version = "0.3.
|
|
871
|
+
version = "0.3.4"
|
|
871
872
|
dependencies = [
|
|
872
873
|
"pyo3",
|
|
873
874
|
"serde",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simparse
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Classifier: Development Status :: 3 - Alpha
|
|
5
5
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -22,6 +22,7 @@ case metadata.
|
|
|
22
22
|
|
|
23
23
|
| Format | Files |
|
|
24
24
|
|---|---|
|
|
25
|
+
| STEP Part 21 declarations | `.step`, `.stp` |
|
|
25
26
|
| COMSOL | `.mph` |
|
|
26
27
|
| Abaqus | `.inp`, `.inc` |
|
|
27
28
|
| Fluent | `.cas.h5`, `.msh.h5` |
|
|
@@ -29,6 +30,7 @@ case metadata.
|
|
|
29
30
|
| Ansys Mechanical | `.mechdb`, `.mechdat` |
|
|
30
31
|
| Icepak Classic | `.tzr` |
|
|
31
32
|
| Simcenter FloTHERM | `.pack`, `.xml`, `.floxml` |
|
|
33
|
+
| Simulink | `.slx`, `.mdl` |
|
|
32
34
|
|
|
33
35
|
## Design
|
|
34
36
|
|
|
@@ -37,10 +39,18 @@ It focuses on lightweight agent workflows: metadata, inventory, quick directory
|
|
|
37
39
|
scans, and deciding when a heavier vendor or Python tool should be called next.
|
|
38
40
|
See [tool design principles](docs/design-principles.md).
|
|
39
41
|
|
|
42
|
+
The [draft AI Infra System IR](docs/ir.md) defines compact inspection manifests
|
|
43
|
+
for cooling, advanced packaging and 3D IC, with CAD/CAE dialects and software
|
|
44
|
+
extensions. Geometry, meshes and result data stay in referenced artifacts.
|
|
45
|
+
JSON inspection results include an additive `ir` field alongside the existing
|
|
46
|
+
format-specific summary. STEP uses the CAD dialect; supported simulation formats
|
|
47
|
+
use the CAE dialect. The draft describes observed metadata, not executable models.
|
|
48
|
+
|
|
40
49
|
## CLI
|
|
41
50
|
|
|
42
51
|
```powershell
|
|
43
52
|
cargo run -p simparse-cli -- inspect /path/to/model.mph --json
|
|
53
|
+
cargo run -p simparse-cli -- inspect /path/to/assembly.step --json --summary
|
|
44
54
|
cargo run -p simparse-cli -- inspect /path/to/thermal-model.xml --json --summary
|
|
45
55
|
cargo run -p simparse-cli -- inspect /path/to/model.mph --json --summary
|
|
46
56
|
cargo run -p simparse-cli -- scan /path/to/history --jsonl
|
|
@@ -50,6 +60,13 @@ Use `--summary` for a deterministic, bounded preflight view. It reports total
|
|
|
50
60
|
counts with capped samples and explicit parser limitations. Omit it when the
|
|
51
61
|
full shallow inventory is needed.
|
|
52
62
|
|
|
63
|
+
STEP inspection streams source declarations with bounded metadata retention. It
|
|
64
|
+
reports schema names, entity-type counts, selected product names and length-unit
|
|
65
|
+
declarations. Counts are source records, not assembly occurrence counts or proof
|
|
66
|
+
of valid geometry. Units remain scoped declarations; no global scale is guessed.
|
|
67
|
+
Incomplete input or skipped records set `truncated`. For STEP, `--max-text-bytes`
|
|
68
|
+
limits each retained record, capped at 64 KiB, rather than the entire file read.
|
|
69
|
+
|
|
53
70
|
FloXML files commonly use the generic `.xml` suffix. `simparse` checks their
|
|
54
71
|
root element, so directory scans include `<xml_case>` and `<sm_xml_case>` files
|
|
55
72
|
while skipping unrelated XML.
|
|
@@ -7,6 +7,7 @@ case metadata.
|
|
|
7
7
|
|
|
8
8
|
| Format | Files |
|
|
9
9
|
|---|---|
|
|
10
|
+
| STEP Part 21 declarations | `.step`, `.stp` |
|
|
10
11
|
| COMSOL | `.mph` |
|
|
11
12
|
| Abaqus | `.inp`, `.inc` |
|
|
12
13
|
| Fluent | `.cas.h5`, `.msh.h5` |
|
|
@@ -14,6 +15,7 @@ case metadata.
|
|
|
14
15
|
| Ansys Mechanical | `.mechdb`, `.mechdat` |
|
|
15
16
|
| Icepak Classic | `.tzr` |
|
|
16
17
|
| Simcenter FloTHERM | `.pack`, `.xml`, `.floxml` |
|
|
18
|
+
| Simulink | `.slx`, `.mdl` |
|
|
17
19
|
|
|
18
20
|
## Design
|
|
19
21
|
|
|
@@ -22,10 +24,18 @@ It focuses on lightweight agent workflows: metadata, inventory, quick directory
|
|
|
22
24
|
scans, and deciding when a heavier vendor or Python tool should be called next.
|
|
23
25
|
See [tool design principles](docs/design-principles.md).
|
|
24
26
|
|
|
27
|
+
The [draft AI Infra System IR](docs/ir.md) defines compact inspection manifests
|
|
28
|
+
for cooling, advanced packaging and 3D IC, with CAD/CAE dialects and software
|
|
29
|
+
extensions. Geometry, meshes and result data stay in referenced artifacts.
|
|
30
|
+
JSON inspection results include an additive `ir` field alongside the existing
|
|
31
|
+
format-specific summary. STEP uses the CAD dialect; supported simulation formats
|
|
32
|
+
use the CAE dialect. The draft describes observed metadata, not executable models.
|
|
33
|
+
|
|
25
34
|
## CLI
|
|
26
35
|
|
|
27
36
|
```powershell
|
|
28
37
|
cargo run -p simparse-cli -- inspect /path/to/model.mph --json
|
|
38
|
+
cargo run -p simparse-cli -- inspect /path/to/assembly.step --json --summary
|
|
29
39
|
cargo run -p simparse-cli -- inspect /path/to/thermal-model.xml --json --summary
|
|
30
40
|
cargo run -p simparse-cli -- inspect /path/to/model.mph --json --summary
|
|
31
41
|
cargo run -p simparse-cli -- scan /path/to/history --jsonl
|
|
@@ -35,6 +45,13 @@ Use `--summary` for a deterministic, bounded preflight view. It reports total
|
|
|
35
45
|
counts with capped samples and explicit parser limitations. Omit it when the
|
|
36
46
|
full shallow inventory is needed.
|
|
37
47
|
|
|
48
|
+
STEP inspection streams source declarations with bounded metadata retention. It
|
|
49
|
+
reports schema names, entity-type counts, selected product names and length-unit
|
|
50
|
+
declarations. Counts are source records, not assembly occurrence counts or proof
|
|
51
|
+
of valid geometry. Units remain scoped declarations; no global scale is guessed.
|
|
52
|
+
Incomplete input or skipped records set `truncated`. For STEP, `--max-text-bytes`
|
|
53
|
+
limits each retained record, capped at 64 KiB, rather than the entire file read.
|
|
54
|
+
|
|
38
55
|
FloXML files commonly use the generic `.xml` suffix. `simparse` checks their
|
|
39
56
|
root element, so directory scans include `<xml_case>` and `<sm_xml_case>` files
|
|
40
57
|
while skipping unrelated XML.
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
//! Test-only, Rust-native projections for the draft AI Infra System IR.
|
|
2
|
+
//! Usage: cargo run -p simparse-core --example ir_asset_probe -- assets.json output-dir
|
|
3
|
+
//! Sources are read-only. The output contains full native inspection sidecars and
|
|
4
|
+
//! compact trial manifests. This is not a production IR exporter or solver adapter.
|
|
5
|
+
|
|
6
|
+
use quick_xml::Reader;
|
|
7
|
+
use quick_xml::events::Event;
|
|
8
|
+
use serde_json::{Value, json};
|
|
9
|
+
use sha2::{Digest, Sha256};
|
|
10
|
+
use simparse_core::{InspectOptions, inspect_path};
|
|
11
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
12
|
+
use std::error::Error;
|
|
13
|
+
use std::fs::{self, File};
|
|
14
|
+
use std::io::{BufReader, Read};
|
|
15
|
+
use std::path::Path;
|
|
16
|
+
|
|
17
|
+
type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
|
18
|
+
const INLINE_SAMPLE: usize = 24;
|
|
19
|
+
|
|
20
|
+
fn sha256(path: &Path) -> Result<String> {
|
|
21
|
+
let mut reader = BufReader::new(File::open(path)?);
|
|
22
|
+
let mut digest = Sha256::new();
|
|
23
|
+
let mut buffer = [0_u8; 65536];
|
|
24
|
+
loop {
|
|
25
|
+
let count = reader.read(&mut buffer)?;
|
|
26
|
+
if count == 0 {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
digest.update(&buffer[..count]);
|
|
30
|
+
}
|
|
31
|
+
Ok(format!("{:x}", digest.finalize()))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fn reference(path: &Path, format: &str) -> Result<Value> {
|
|
35
|
+
let absolute = fs::canonicalize(path)?;
|
|
36
|
+
let path = absolute.to_string_lossy().replace('\\', "/");
|
|
37
|
+
if path.starts_with("//?/UNC/") || (path.starts_with("//") && !path.starts_with("//?/")) {
|
|
38
|
+
return Err("UNC paths are not supported by this offline probe".into());
|
|
39
|
+
}
|
|
40
|
+
let path = path.strip_prefix("//?/").unwrap_or(&path);
|
|
41
|
+
let mut encoded = String::new();
|
|
42
|
+
for byte in path.trim_start_matches('/').bytes() {
|
|
43
|
+
if byte.is_ascii_alphanumeric() || b"/-._~:".contains(&byte) {
|
|
44
|
+
encoded.push(char::from(byte));
|
|
45
|
+
} else {
|
|
46
|
+
encoded.push_str(&format!("%{byte:02X}"));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
Ok(json!({"uri": format!("file:///{encoded}"), "format": format, "sha256": sha256(&absolute)?}))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fn step_observations(path: &Path) -> Result<Value> {
|
|
53
|
+
if fs::metadata(path)?.len() > 32 * 1024 * 1024 {
|
|
54
|
+
return Err("STEP file exceeds probe read limit".into());
|
|
55
|
+
}
|
|
56
|
+
let text = fs::read_to_string(path)?;
|
|
57
|
+
if !text.contains("ISO-10303-21;") {
|
|
58
|
+
return Err("not a STEP physical file".into());
|
|
59
|
+
}
|
|
60
|
+
let mut entities = Vec::new();
|
|
61
|
+
let mut counts = BTreeMap::<String, usize>::new();
|
|
62
|
+
for record in text.split(';') {
|
|
63
|
+
let Some((left, right)) = record.trim().split_once('=') else {
|
|
64
|
+
continue;
|
|
65
|
+
};
|
|
66
|
+
let Some(number) = left.trim().strip_prefix('#') else {
|
|
67
|
+
continue;
|
|
68
|
+
};
|
|
69
|
+
if number.parse::<u64>().is_err() {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
let native_type = right.split('(').next().unwrap_or("").trim();
|
|
73
|
+
let kind = match native_type {
|
|
74
|
+
"MANIFOLD_SOLID_BREP" | "BREP_WITH_VOIDS" => "body",
|
|
75
|
+
"ADVANCED_FACE" => "face",
|
|
76
|
+
"EDGE_CURVE" => "edge",
|
|
77
|
+
"VERTEX_POINT" => "vertex",
|
|
78
|
+
_ => continue,
|
|
79
|
+
};
|
|
80
|
+
*counts.entry(native_type.into()).or_default() += 1;
|
|
81
|
+
entities.push(json!({"id": format!("step-{number}"), "kind": kind, "native_ref": format!("#{number}")}));
|
|
82
|
+
}
|
|
83
|
+
let compact: String = text.chars().filter(|c| !c.is_whitespace()).collect();
|
|
84
|
+
let units: BTreeSet<_> = compact
|
|
85
|
+
.split("SI_UNIT(")
|
|
86
|
+
.skip(1)
|
|
87
|
+
.filter_map(|tail| tail.split_once(')').map(|(unit, _)| unit))
|
|
88
|
+
.filter_map(|unit| unit.strip_suffix(",.METRE."))
|
|
89
|
+
.collect();
|
|
90
|
+
let mut observations = json!({"entities": entities, "observed_types": counts});
|
|
91
|
+
if units.len() == 1 && !text.contains("CONVERSION_BASED_UNIT") {
|
|
92
|
+
let unit = match units.first().copied() {
|
|
93
|
+
Some("$") => Some("m"),
|
|
94
|
+
Some(".MILLI.") => Some("mm"),
|
|
95
|
+
Some(".MICRO.") => Some("um"),
|
|
96
|
+
_ => None,
|
|
97
|
+
};
|
|
98
|
+
if let Some(unit) = unit {
|
|
99
|
+
observations["length_unit"] = json!(unit);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
Ok(observations)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fn freecad_observations(path: &Path) -> Result<Value> {
|
|
106
|
+
let mut archive = zip::ZipArchive::new(File::open(path)?)?;
|
|
107
|
+
let mut entry = archive.by_name("Document.xml")?;
|
|
108
|
+
if entry.size() > 4 * 1024 * 1024 {
|
|
109
|
+
return Err("FreeCAD metadata exceeds probe read limit".into());
|
|
110
|
+
}
|
|
111
|
+
let mut xml = String::new();
|
|
112
|
+
entry.read_to_string(&mut xml)?;
|
|
113
|
+
let mut reader = Reader::from_str(&xml);
|
|
114
|
+
let mut in_objects = false;
|
|
115
|
+
let mut entities = Vec::new();
|
|
116
|
+
loop {
|
|
117
|
+
match reader.read_event()? {
|
|
118
|
+
Event::Start(ref element) if element.name().as_ref() == b"Objects" => in_objects = true,
|
|
119
|
+
Event::End(ref element) if element.name().as_ref() == b"Objects" => in_objects = false,
|
|
120
|
+
Event::Empty(ref element) | Event::Start(ref element)
|
|
121
|
+
if in_objects && element.name().as_ref() == b"Object" =>
|
|
122
|
+
{
|
|
123
|
+
let mut name = None;
|
|
124
|
+
let mut native_type = None;
|
|
125
|
+
for attribute in element.attributes() {
|
|
126
|
+
let attribute = attribute?;
|
|
127
|
+
let value = attribute
|
|
128
|
+
.decode_and_unescape_value(reader.decoder())?
|
|
129
|
+
.into_owned();
|
|
130
|
+
match attribute.key.as_ref() {
|
|
131
|
+
b"name" => name = Some(value),
|
|
132
|
+
b"type" => native_type = Some(value),
|
|
133
|
+
_ => {}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if let Some(name) = name {
|
|
137
|
+
let mut entity = json!({"id": name, "kind": "unknown", "native_ref": name});
|
|
138
|
+
if let Some(native_type) = native_type {
|
|
139
|
+
entity["extensions"] = json!({"freecad": {"version": "0", "attributes": {"object_type": native_type}}});
|
|
140
|
+
}
|
|
141
|
+
entities.push(entity);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
Event::Eof => break,
|
|
145
|
+
_ => {}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
Ok(json!({"entities": entities}))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fn cae_projection(raw: &Value, source: Value, setup: Value) -> Value {
|
|
152
|
+
let data = &raw["summary"]["data"];
|
|
153
|
+
let format = raw["format"].as_str().unwrap_or("unknown");
|
|
154
|
+
let namespace = match format {
|
|
155
|
+
"comsol-mph" => "comsol",
|
|
156
|
+
"hfss-aedt" => "ansys.aedt",
|
|
157
|
+
"ansys-mechanical" => "ansys.mechanical",
|
|
158
|
+
"fluent-hdf5" => "ansys.fluent",
|
|
159
|
+
"abaqus-inp" => "abaqus",
|
|
160
|
+
"flotherm-floxml" => "flotherm",
|
|
161
|
+
_ => "source",
|
|
162
|
+
};
|
|
163
|
+
let mut features = Vec::new();
|
|
164
|
+
// Preserve AEDT design identity separately from flattened setup inventories.
|
|
165
|
+
if let Some(designs) = data["designs"].as_array() {
|
|
166
|
+
for (index, design) in designs.iter().enumerate() {
|
|
167
|
+
let mut feature = json!({"id": format!("design-{index}"), "kind": "analysis"});
|
|
168
|
+
for (source_key, target_key) in [("name", "name"), ("design_type", "native_type")] {
|
|
169
|
+
if let Some(value) = design[source_key].as_str().filter(|v| !v.is_empty()) {
|
|
170
|
+
feature[target_key] = json!(value);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
let mut attrs = serde_json::Map::new();
|
|
174
|
+
for key in ["solution_type", "is_solved"] {
|
|
175
|
+
if !design[key].is_null() {
|
|
176
|
+
attrs.insert(key.into(), design[key].clone());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if !attrs.is_empty() {
|
|
180
|
+
feature["extensions"] = json!({namespace: {"version": "0", "attributes": attrs}});
|
|
181
|
+
}
|
|
182
|
+
features.push(feature);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
for (key, kind) in [
|
|
186
|
+
("material_tags", "material"),
|
|
187
|
+
("materials", "material"),
|
|
188
|
+
("physics_tags", "physics"),
|
|
189
|
+
("study_tags", "study"),
|
|
190
|
+
("steps", "study"),
|
|
191
|
+
("setups", "study"),
|
|
192
|
+
("boundaries", "condition"),
|
|
193
|
+
("ports", "condition"),
|
|
194
|
+
("loads_and_conditions", "condition"),
|
|
195
|
+
("analyses", "analysis"),
|
|
196
|
+
("contacts", "interface"),
|
|
197
|
+
("mesh_operations", "mesh"),
|
|
198
|
+
] {
|
|
199
|
+
if let Some(names) = data[key].as_array() {
|
|
200
|
+
for (index, name) in names.iter().enumerate() {
|
|
201
|
+
if let Some(name) = name.as_str().filter(|v| !v.is_empty()) {
|
|
202
|
+
features
|
|
203
|
+
.push(json!({"id": format!("{key}-{index}"), "kind": kind, "name": name}));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
let mut attrs = json!({"observed_feature_count": features.len()});
|
|
209
|
+
for key in [
|
|
210
|
+
"node_count",
|
|
211
|
+
"element_count",
|
|
212
|
+
"version_hint",
|
|
213
|
+
"comsol_version",
|
|
214
|
+
"mechanical_version",
|
|
215
|
+
"product",
|
|
216
|
+
] {
|
|
217
|
+
if data[key].is_number() || data[key].as_str().is_some_and(|value| !value.is_empty()) {
|
|
218
|
+
attrs[key] = data[key].clone();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (key, label) in [
|
|
222
|
+
("parameters", "unscoped_value_count"),
|
|
223
|
+
("datasets", "dataset_count"),
|
|
224
|
+
("results", "result_object_count"),
|
|
225
|
+
] {
|
|
226
|
+
if let Some(values) = data[key].as_array() {
|
|
227
|
+
attrs[label] = json!(values.len());
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Serialized COMSOL node properties remain in the native setup sidecar.
|
|
231
|
+
// No enabled flags, parameter scopes, units or selections are guessed.
|
|
232
|
+
features.truncate(INLINE_SAMPLE);
|
|
233
|
+
let mut dialect = json!({"version": 0, "source": source, "features": features,
|
|
234
|
+
"setup": setup, "extensions": {namespace: {"version": "0", "attributes": attrs}},
|
|
235
|
+
"warnings": ["Test projection of shallow inventories; scopes and effective activation are not established."]});
|
|
236
|
+
if matches!(format, "abaqus-inp" | "fluent-hdf5") {
|
|
237
|
+
dialect["mesh"] = dialect["source"].clone();
|
|
238
|
+
}
|
|
239
|
+
dialect
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
fn probe(path: &Path, case_dir: &Path) -> Result<Value> {
|
|
243
|
+
fs::create_dir_all(case_dir)?;
|
|
244
|
+
let extension = path
|
|
245
|
+
.extension()
|
|
246
|
+
.unwrap_or_default()
|
|
247
|
+
.to_string_lossy()
|
|
248
|
+
.to_ascii_lowercase();
|
|
249
|
+
let observations_path = case_dir.join("observations.json");
|
|
250
|
+
let (document, format, count) = if matches!(extension.as_str(), "step" | "stp" | "fcstd") {
|
|
251
|
+
let (raw, format) = if extension == "fcstd" {
|
|
252
|
+
(freecad_observations(path)?, "freecad")
|
|
253
|
+
} else {
|
|
254
|
+
(step_observations(path)?, "step")
|
|
255
|
+
};
|
|
256
|
+
fs::write(&observations_path, serde_json::to_vec(&raw)?)?;
|
|
257
|
+
let entities = raw["entities"]
|
|
258
|
+
.as_array()
|
|
259
|
+
.ok_or("entity inventory missing")?;
|
|
260
|
+
let mut dialect = json!({"version": 0, "source": reference(path, format)?,
|
|
261
|
+
"entities": entities.iter().take(INLINE_SAMPLE).collect::<Vec<_>>(),
|
|
262
|
+
"inventory": reference(&observations_path, "json")?,
|
|
263
|
+
"warnings": ["Test probe reads a shallow object inventory; topology and assembly transforms are not validated."]});
|
|
264
|
+
if let Some(unit) = raw["length_unit"].as_str() {
|
|
265
|
+
dialect["length_unit"] = json!(unit);
|
|
266
|
+
}
|
|
267
|
+
(
|
|
268
|
+
json!({"schema": "ai-infra-system/v0", "dialects": {"cad": dialect}}),
|
|
269
|
+
format.to_owned(),
|
|
270
|
+
entities.len(),
|
|
271
|
+
)
|
|
272
|
+
} else {
|
|
273
|
+
let result = inspect_path(path, InspectOptions::default())?;
|
|
274
|
+
let format = result.format.to_string();
|
|
275
|
+
let raw = serde_json::to_value(result)?;
|
|
276
|
+
fs::write(&observations_path, serde_json::to_vec(&raw)?)?;
|
|
277
|
+
let dialect = cae_projection(
|
|
278
|
+
&raw,
|
|
279
|
+
reference(path, &format)?,
|
|
280
|
+
reference(&observations_path, "simparse-inspect-json")?,
|
|
281
|
+
);
|
|
282
|
+
let count = dialect["extensions"]
|
|
283
|
+
.as_object()
|
|
284
|
+
.and_then(|v| v.values().next())
|
|
285
|
+
.and_then(|v| v["attributes"]["observed_feature_count"].as_u64())
|
|
286
|
+
.unwrap_or(0) as usize;
|
|
287
|
+
(
|
|
288
|
+
json!({"schema": "ai-infra-system/v0", "dialects": {"cae": dialect}}),
|
|
289
|
+
format,
|
|
290
|
+
count,
|
|
291
|
+
)
|
|
292
|
+
};
|
|
293
|
+
let bytes = serde_json::to_vec(&document)?;
|
|
294
|
+
fs::write(case_dir.join("system.json"), &bytes)?;
|
|
295
|
+
Ok(
|
|
296
|
+
json!({"format": format, "source_bytes": fs::metadata(path)?.len(),
|
|
297
|
+
"source_sha256": sha256(path)?, "manifest_bytes": bytes.len(), "observed_records": count}),
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
fn main() -> Result<()> {
|
|
302
|
+
let args: Vec<_> = std::env::args().collect();
|
|
303
|
+
if args.len() != 3 {
|
|
304
|
+
return Err("usage: ir_asset_probe assets.json output-dir".into());
|
|
305
|
+
}
|
|
306
|
+
let input = fs::read_to_string(&args[1])?;
|
|
307
|
+
let paths: Vec<String> = serde_json::from_str(input.trim_start_matches('\u{feff}'))?;
|
|
308
|
+
let output = Path::new(&args[2]);
|
|
309
|
+
fs::create_dir_all(output)?;
|
|
310
|
+
let mut results = Vec::new();
|
|
311
|
+
let mut failed = false;
|
|
312
|
+
for (index, path) in paths.iter().enumerate() {
|
|
313
|
+
let mut result = match probe(Path::new(path), &output.join(format!("case-{index:03}"))) {
|
|
314
|
+
Ok(mut value) => {
|
|
315
|
+
value["ok"] = json!(true);
|
|
316
|
+
value
|
|
317
|
+
}
|
|
318
|
+
Err(error) => {
|
|
319
|
+
failed = true;
|
|
320
|
+
json!({"ok": false, "error": error.to_string()})
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
result["case"] = json!(index);
|
|
324
|
+
println!("{}", serde_json::to_string(&result)?);
|
|
325
|
+
result["path"] = json!(path);
|
|
326
|
+
results.push(result);
|
|
327
|
+
}
|
|
328
|
+
fs::write(
|
|
329
|
+
output.join("report.json"),
|
|
330
|
+
serde_json::to_vec_pretty(&results)?,
|
|
331
|
+
)?;
|
|
332
|
+
if failed {
|
|
333
|
+
return Err("one or more asset probes failed; inspect report.json".into());
|
|
334
|
+
}
|
|
335
|
+
Ok(())
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
#[cfg(test)]
|
|
339
|
+
mod tests {
|
|
340
|
+
use super::*;
|
|
341
|
+
|
|
342
|
+
fn project(format: &str, data: Value) -> Value {
|
|
343
|
+
cae_projection(
|
|
344
|
+
&json!({"format": format, "summary": {"data": data}}),
|
|
345
|
+
json!({"uri": "source.bin"}),
|
|
346
|
+
json!({"uri": "native-inventory.json"}),
|
|
347
|
+
)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
#[test]
|
|
351
|
+
fn comsol_serialized_properties_do_not_become_global_parameters() {
|
|
352
|
+
let result = project(
|
|
353
|
+
"comsol-mph",
|
|
354
|
+
json!({"parameters": [
|
|
355
|
+
{"name": "T", "value": "1|1,'300[K]'"}, {"name": "T", "value": "1|1,'400[K]'"}],
|
|
356
|
+
"physics_tags": ["ht"], "is_runnable": false}),
|
|
357
|
+
);
|
|
358
|
+
assert!(result.get("parameters").is_none());
|
|
359
|
+
assert!(result["features"][0].get("enabled").is_none());
|
|
360
|
+
assert_eq!(
|
|
361
|
+
result["extensions"]["comsol"]["attributes"]["unscoped_value_count"],
|
|
362
|
+
2
|
|
363
|
+
);
|
|
364
|
+
assert_eq!(result["setup"]["uri"], "native-inventory.json");
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
#[test]
|
|
368
|
+
fn aedt_designs_keep_solution_state_separate_from_activation() {
|
|
369
|
+
let result = project(
|
|
370
|
+
"hfss-aedt",
|
|
371
|
+
json!({"designs": [
|
|
372
|
+
{"name": "Design", "design_type": "HFSS", "solution_type": "DrivenModal", "is_solved": false},
|
|
373
|
+
{"name": "Design", "design_type": "Icepak", "solution_type": "SteadyState", "is_solved": true}]}),
|
|
374
|
+
);
|
|
375
|
+
let features = result["features"].as_array().unwrap();
|
|
376
|
+
assert_ne!(features[0]["id"], features[1]["id"]);
|
|
377
|
+
assert_eq!(features[0]["native_type"], "HFSS");
|
|
378
|
+
assert_eq!(features[1]["native_type"], "Icepak");
|
|
379
|
+
assert!(
|
|
380
|
+
features
|
|
381
|
+
.iter()
|
|
382
|
+
.all(|feature| feature.get("enabled").is_none())
|
|
383
|
+
);
|
|
384
|
+
assert_eq!(
|
|
385
|
+
features[0]["extensions"]["ansys.aedt"]["attributes"]["is_solved"],
|
|
386
|
+
false
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
#[test]
|
|
391
|
+
fn mechanical_contacts_and_result_objects_are_not_solve_evidence() {
|
|
392
|
+
let result = project(
|
|
393
|
+
"ansys-mechanical",
|
|
394
|
+
json!({"analyses": ["Thermal"],
|
|
395
|
+
"contacts": ["Die interface"], "loads_and_conditions": ["Temperature"],
|
|
396
|
+
"results": ["Equivalent stress"], "mechanical_version": "test-version"}),
|
|
397
|
+
);
|
|
398
|
+
let kinds: Vec<_> = result["features"]
|
|
399
|
+
.as_array()
|
|
400
|
+
.unwrap()
|
|
401
|
+
.iter()
|
|
402
|
+
.map(|v| v["kind"].as_str().unwrap())
|
|
403
|
+
.collect();
|
|
404
|
+
assert!(
|
|
405
|
+
kinds.contains(&"analysis")
|
|
406
|
+
&& kinds.contains(&"interface")
|
|
407
|
+
&& kinds.contains(&"condition")
|
|
408
|
+
);
|
|
409
|
+
assert!(result.get("results").is_none());
|
|
410
|
+
assert_eq!(
|
|
411
|
+
result["extensions"]["ansys.mechanical"]["attributes"]["result_object_count"],
|
|
412
|
+
1
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
#[test]
|
|
417
|
+
fn large_feature_inventories_keep_the_full_sidecar() {
|
|
418
|
+
let names: Vec<_> = (0..100).map(|i| format!("material-{i}")).collect();
|
|
419
|
+
let result = project("comsol-mph", json!({"material_tags": names}));
|
|
420
|
+
assert_eq!(result["features"].as_array().unwrap().len(), INLINE_SAMPLE);
|
|
421
|
+
assert_eq!(
|
|
422
|
+
result["extensions"]["comsol"]["attributes"]["observed_feature_count"],
|
|
423
|
+
100
|
|
424
|
+
);
|
|
425
|
+
assert_eq!(result["setup"]["uri"], "native-inventory.json");
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
#[test]
|
|
429
|
+
fn conflicting_step_units_remain_unknown() -> Result<()> {
|
|
430
|
+
let directory = tempfile::tempdir()?;
|
|
431
|
+
let path = directory.path().join("mixed.step");
|
|
432
|
+
fs::write(
|
|
433
|
+
&path,
|
|
434
|
+
"ISO-10303-21;DATA;#1=SI_UNIT(.MILLI.,.METRE.);#2=SI_UNIT(.CENTI.,.METRE.);ENDSEC;",
|
|
435
|
+
)?;
|
|
436
|
+
assert!(step_observations(&path)?.get("length_unit").is_none());
|
|
437
|
+
fs::write(
|
|
438
|
+
&path,
|
|
439
|
+
"ISO-10303-21;DATA;#1=SI_UNIT(.MILLI.,.METRE.);ENDSEC;",
|
|
440
|
+
)?;
|
|
441
|
+
assert_eq!(step_observations(&path)?["length_unit"], "mm");
|
|
442
|
+
Ok(())
|
|
443
|
+
}
|
|
444
|
+
}
|
|
@@ -4,6 +4,7 @@ use walkdir::WalkDir;
|
|
|
4
4
|
|
|
5
5
|
use crate::parsers::{
|
|
6
6
|
abaqus, comsol, flotherm, hfss, icepak, inspect_fluent_hdf5, inspect_mechanical_mechdb,
|
|
7
|
+
simulink,
|
|
7
8
|
};
|
|
8
9
|
use crate::{
|
|
9
10
|
FormatSummary, InspectOptions, Result, ScanOptions, SimFormat, SimparseError, SimparseResult,
|
|
@@ -11,7 +12,9 @@ use crate::{
|
|
|
11
12
|
|
|
12
13
|
pub fn detect_format(path: &Path) -> Option<SimFormat> {
|
|
13
14
|
let name = path.file_name()?.to_string_lossy().to_ascii_lowercase();
|
|
14
|
-
if name.ends_with(".
|
|
15
|
+
if name.ends_with(".step") || name.ends_with(".stp") {
|
|
16
|
+
Some(SimFormat::Step)
|
|
17
|
+
} else if name.ends_with(".mph") {
|
|
15
18
|
Some(SimFormat::ComsolMph)
|
|
16
19
|
} else if name.ends_with(".inp") || name.ends_with(".inc") {
|
|
17
20
|
Some(SimFormat::AbaqusInp)
|
|
@@ -29,6 +32,10 @@ pub fn detect_format(path: &Path) -> Option<SimFormat> {
|
|
|
29
32
|
Some(SimFormat::FlothermFloxml)
|
|
30
33
|
} else if name.ends_with(".pack") {
|
|
31
34
|
Some(SimFormat::FlothermPack)
|
|
35
|
+
} else if name.ends_with(".slx") && simulink::looks_like_slx(path) {
|
|
36
|
+
Some(SimFormat::SimulinkSlx)
|
|
37
|
+
} else if name.ends_with(".mdl") && simulink::looks_like_mdl(path) {
|
|
38
|
+
Some(SimFormat::SimulinkMdl)
|
|
32
39
|
} else {
|
|
33
40
|
None
|
|
34
41
|
}
|
|
@@ -42,6 +49,10 @@ pub fn inspect_path(path: impl AsRef<Path>, options: InspectOptions) -> Result<S
|
|
|
42
49
|
.ok_or_else(|| SimparseError::UnsupportedFormat(path.display().to_string()))?;
|
|
43
50
|
|
|
44
51
|
let summary = match format {
|
|
52
|
+
SimFormat::Step => FormatSummary::Step(crate::parsers::step::inspect_step(
|
|
53
|
+
path,
|
|
54
|
+
options.max_text_bytes,
|
|
55
|
+
)?),
|
|
45
56
|
SimFormat::ComsolMph => FormatSummary::ComsolMph(comsol::inspect_comsol_mph(path)?),
|
|
46
57
|
SimFormat::AbaqusInp => FormatSummary::AbaqusInp(abaqus::inspect_abaqus_inp(path)?),
|
|
47
58
|
SimFormat::FluentHdf5 => FormatSummary::FluentHdf5(inspect_fluent_hdf5(path)?),
|
|
@@ -61,9 +72,12 @@ pub fn inspect_path(path: impl AsRef<Path>, options: InspectOptions) -> Result<S
|
|
|
61
72
|
path,
|
|
62
73
|
options.max_text_bytes,
|
|
63
74
|
)?),
|
|
75
|
+
SimFormat::SimulinkSlx | SimFormat::SimulinkMdl => FormatSummary::Simulink(Box::new(
|
|
76
|
+
crate::parsers::simulink::inspect_simulink_model(path)?,
|
|
77
|
+
)),
|
|
64
78
|
};
|
|
65
79
|
|
|
66
|
-
|
|
80
|
+
let mut result = SimparseResult {
|
|
67
81
|
path: options.include_paths.then(|| path.display().to_string()),
|
|
68
82
|
file_name: path
|
|
69
83
|
.file_name()
|
|
@@ -73,7 +87,10 @@ pub fn inspect_path(path: impl AsRef<Path>, options: InspectOptions) -> Result<S
|
|
|
73
87
|
ok: true,
|
|
74
88
|
warnings: Vec::new(),
|
|
75
89
|
summary,
|
|
76
|
-
|
|
90
|
+
ir: None,
|
|
91
|
+
};
|
|
92
|
+
result.ir = Some(crate::ir::project(&result));
|
|
93
|
+
Ok(result)
|
|
77
94
|
}
|
|
78
95
|
|
|
79
96
|
pub fn scan_paths(paths: &[PathBuf], options: ScanOptions) -> Result<Vec<SimparseResult>> {
|
|
@@ -117,6 +134,9 @@ fn should_include(path: &Path, patterns: &[String]) -> bool {
|
|
|
117
134
|
Some(name) => name.to_string_lossy().to_ascii_lowercase(),
|
|
118
135
|
None => return false,
|
|
119
136
|
};
|
|
137
|
+
if name.starts_with("._") {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
120
140
|
patterns.iter().any(|pattern| {
|
|
121
141
|
let pattern = pattern.trim().to_ascii_lowercase();
|
|
122
142
|
if pattern == "*" {
|