Assets#

  • An Asset represents a unit of data managed by the project.

  • Assets link a Job’s inputs and outputs to physical resources such as files or folders.

  • The lifecycle of an Asset is tied to its parent Job: when a Job is deleted, all Assets it generated are automatically removed.

The table lists the assets, the jobs using the asset, its kind (file, folder), its location with respect to the project folder:

Asset

Job

Kind

Location

Swan body module

CodeGeneration(in), ModelCheck(in)

.swan file

‘assets’ project folder

Swan test module

Simulation(in), TestExecution(in)

.swant file

‘assets’ project folder

Swan interface module

None

.swani file

‘assets’ project folder

Generated C code

CodeGeneration(out)

out/code folder

Job folder

Mapping Info

CodeGeneration(out)

out/cg_map.json

Job folder

Test results

TestExecution(out)

out/testResults.json

Job folder

Trace

Simulation(out)

out/trace.sd

Job folder

Example#

The following example shows how to retrieve assets from a project, open them, and access their producer or consumer jobs.

from ansys.scadeone.core import ScadeOne
import ansys.scadeone.core.assets as assets
from ansys.scadeone.core.svc.simdata import FileBase

# Initialize Scade One application and load a project
s_one_install = "C:/Scade One"
app = ScadeOne(install_dir=s_one_install)
# Load project with a path given by sproj_path
project = app.load_project(sproj_path)

# Access an asset (module body) with its name given and inspect jobs consuming it
module_asset = next(
    a
    for a in project.assets
    if isinstance(a, assets.ModuleBodyAsset) and str(a.path) == "assets\\testBodyModule.swan"
)
# Open the asset
module = module_asset.open()  # swan.ModuleBody
# Get consumer jobs of the asset
consumers = module_asset.consumer_jobs

# Access an output asset (simulation trace) with its name SimulationJob1, run its producer job and open it
sim_asset = next(
    a
    for a in project.assets
    if isinstance(a, assets.SimulationDataAsset) and str(a.job_name) == "SimulationJob1"
)
# Get the producer job of the asset
producer = sim_asset.producer_job
# Launch the producer job to generate the trace file.
result = producer.run()
if result.code == 0:
    # Open the asset
    trace = sim_asset.open()
    assert isinstance(trace, FileBase)

# Delete job and its output assets
project.delete_job(producer)
assert project.get_job(producer.name) is None
assert sim_asset.producer_job is None

Asset base class#

Asset is a base class, and it has the following properties:

and it has the following method:

  • The Asset.open() method to open the underlying asset by returning its proper instance. This method must be implemented by its child classes.

Asset classes#

class ansys.scadeone.core.assets.Asset(path: str | Path, project: Project, job_name: str | None = None)#

Bases: ABC

Base class for project assets.

Parameters:
pathPath | str

Asset path relative to the project directory.

projectProject

Project owning the asset.

job_namestr, optional

Name of the job associated with the asset.

property path: Path | None#

Get the asset path.

Returns:
Optional[Path]

The asset path relative to the project directory.

property job_name: str | None#

Get the name of the job associated with the asset.

Returns:
Optional[str]

The name of the associated job, or None if not associated with any job.

property producer_job: Job | None#

Give the job produced by the asset.

Returns:
Job | None

The job produced by the asset, or None if not associated with a job.

property consumer_jobs: List[Job]#

Jobs consumed by the asset, if available in the project.

Returns:
List[Job]

List of job consumed by the asset. Empty if not available or not applicable.

abstractmethod open(**kwargs) → ModuleBody | ModuleInterface | TestModule | FileBase | Path | TestResults | CGMapping#

Open asset

Returns:
AssetOpenReturnType

Asset instance depends on its kind.

class ansys.scadeone.core.assets.ModuleBodyAsset(path: str | Path, project: Project, job_name: str | None = None)#

Bases: Asset

open(**kwargs) → ModuleBody#

Open asset

Returns:
ModuleBody

The module body instance corresponding to the asset.

property consumer_jobs: List[Job]#

Jobs consumed by the asset, if available in the project.

Returns:
List[Job]

List of job consumed by the asset. Empty if not available or not applicable.

property job_name: str | None#

Get the name of the job associated with the asset.

Returns:
Optional[str]

The name of the associated job, or None if not associated with any job.

property path: Path | None#

Get the asset path.

Returns:
Optional[Path]

The asset path relative to the project directory.

property producer_job: Job | None#

Give the job produced by the asset.

Returns:
Job | None

The job produced by the asset, or None if not associated with a job.

class ansys.scadeone.core.assets.ModuleInterfaceAsset(path: str | Path, project: Project, job_name: str | None = None)#

Bases: Asset

open(**kwargs) → ModuleInterface#

Open asset

Returns:
ModuleInterface

The module interface instance corresponding to the asset.

property consumer_jobs: List[Job]#

Jobs consumed by the asset, if available in the project.

Returns:
List[Job]

List of job consumed by the asset. Empty if not available or not applicable.

property job_name: str | None#

Get the name of the job associated with the asset.

Returns:
Optional[str]

The name of the associated job, or None if not associated with any job.

property path: Path | None#

Get the asset path.

Returns:
Optional[Path]

The asset path relative to the project directory.

property producer_job: Job | None#

Give the job produced by the asset.

Returns:
Job | None

The job produced by the asset, or None if not associated with a job.

class ansys.scadeone.core.assets.TestModuleAsset(path: str | Path, project: Project, job_name: str | None = None)#

Bases: Asset

open(**kwargs) → TestModule#

Open asset

Returns:
TestModule

The test module instance corresponding to the asset.

property consumer_jobs: List[Job]#

Jobs consumed by the asset, if available in the project.

Returns:
List[Job]

List of job consumed by the asset. Empty if not available or not applicable.

property job_name: str | None#

Get the name of the job associated with the asset.

Returns:
Optional[str]

The name of the associated job, or None if not associated with any job.

property path: Path | None#

Get the asset path.

Returns:
Optional[Path]

The asset path relative to the project directory.

property producer_job: Job | None#

Give the job produced by the asset.

Returns:
Job | None

The job produced by the asset, or None if not associated with a job.

class ansys.scadeone.core.assets.SimulationDataAsset(path: str | Path, project: Project, job_name: str | None = None)#

Bases: Asset

property path: Path | None#

Get the simulation data trace file path.

Returns:
Optional[Path]

The simulation trace file path, or None if unavailable.

open(mode: str = 'r', **kwargs) → FileBase#

Open the simulation data for reading or editing.

Parameters:
modestr, optional

Opening mode for the file: ‘r’ - reading or ‘w’ - writing to edit the file, by default “r”.

Returns:
FileBase

The simulation data file instance.

property consumer_jobs: List[Job]#

Jobs consumed by the asset, if available in the project.

Returns:
List[Job]

List of job consumed by the asset. Empty if not available or not applicable.

property job_name: str | None#

Get the name of the job associated with the asset.

Returns:
Optional[str]

The name of the associated job, or None if not associated with any job.

property producer_job: Job | None#

Give the job produced by the asset.

Returns:
Job | None

The job produced by the asset, or None if not associated with a job.

class ansys.scadeone.core.assets.GeneratedCodeAsset(path: str | Path, project: Project, job_name: str | None = None)#

Bases: Asset

property path: Path | None#

Get the code generation output directory path.

Returns:
Optional[Path]

The code generation output directory path, or None if unavailable.

open(**kwargs) → Path#

Open asset

Returns:
Path

The path to the generated code file corresponding to the asset.

property consumer_jobs: List[Job]#

Jobs consumed by the asset, if available in the project.

Returns:
List[Job]

List of job consumed by the asset. Empty if not available or not applicable.

property job_name: str | None#

Get the name of the job associated with the asset.

Returns:
Optional[str]

The name of the associated job, or None if not associated with any job.

property producer_job: Job | None#

Give the job produced by the asset.

Returns:
Job | None

The job produced by the asset, or None if not associated with a job.

class ansys.scadeone.core.assets.TestResultsAsset(path: str | Path, project: Project, job_name: str | None = None)#

Bases: Asset

property path: Path | None#

Get the test result file path.

Returns:
Optional[Path]

The path to the test result file, or None if unavailable.

open(**kwargs) → TestResults#

Open asset

Returns:
TestResults

The test results instance corresponding to the asset.

property consumer_jobs: List[Job]#

Jobs consumed by the asset, if available in the project.

Returns:
List[Job]

List of job consumed by the asset. Empty if not available or not applicable.

property job_name: str | None#

Get the name of the job associated with the asset.

Returns:
Optional[str]

The name of the associated job, or None if not associated with any job.

property producer_job: Job | None#

Give the job produced by the asset.

Returns:
Job | None

The job produced by the asset, or None if not associated with a job.

class ansys.scadeone.core.assets.CGMappingAsset(path: str | Path, project: Project, job_name: str | None = None)#

Bases: Asset

property path: Path | None#

Get the CG mapping file path.

Returns:
Optional[Path]

The path to the CG mapping file, or None if unavailable.

open(**kwargs) → CGMapping#

Open asset

Returns:
CGMapping

The CGMapping corresponding to the asset.

property consumer_jobs: List[Job]#

Jobs consumed by the asset, if available in the project.

Returns:
List[Job]

List of job consumed by the asset. Empty if not available or not applicable.

property job_name: str | None#

Get the name of the job associated with the asset.

Returns:
Optional[str]

The name of the associated job, or None if not associated with any job.

property producer_job: Job | None#

Give the job produced by the asset.

Returns:
Job | None

The job produced by the asset, or None if not associated with a job.