-
Notifications
You must be signed in to change notification settings - Fork 4
Fix itools tutorial #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alicecaron
wants to merge
4
commits into
main
Choose a base branch
from
fix-itools-tutorial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| --- | ||
| layout: default | ||
| --- | ||
| # Write an IIDM exporter | ||
|
|
||
| From Powsybl's `Exporter` interface, it is possible to add a new data serialization format | ||
| for a IIDM network. | ||
|
|
||
| In order to do so, you will need to: | ||
| - Write an implementation of the `Exporter` interface and assign it a unique ID format | ||
| - Declare the new class as a service implementation with the `@AutoService` annotation | ||
| - Build your jar | ||
|
|
||
| ## Configuring your module | ||
|
|
||
| In order to implement a new `Exporter`, add the following dependencies in your `pom.xml` file: | ||
| - `auto-service (com.google.auto.service)`: Configuration/metadata generator for `ServiceLoader`-style providers | ||
| - `powsybl-iidm-converter-api`: IIDM network import/export API | ||
|
|
||
| ```xml | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.google.auto.service</groupId> | ||
| <artifactId>auto-service</artifactId> | ||
| <version>1.0-rc2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.powsybl</groupId> | ||
| <artifactId>powsybl-iidm-converter-api</artifactId> | ||
| <version>${powsybl.core.version}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| ``` | ||
|
|
||
| ## Implementation | ||
|
|
||
| As said above, you will need to write your own implementation of the `Exporter` interface and declare it as a service | ||
| implementation. Here is an empty class template of an `Exporter` implementation: | ||
|
|
||
| ```java | ||
| import com.powsybl.commons.datasource.DataSource; | ||
| import com.powsybl.iidm.export.Exporter; | ||
| import com.powsybl.iidm.network.Network; | ||
|
|
||
| import java.util.Properties; | ||
|
|
||
| @AutoService(Exporter.class) | ||
| public class MyExporter implements Exporter { | ||
|
|
||
| /** | ||
| * @return the unique ID for the given format | ||
| */ | ||
| @Override | ||
| public String getFormat() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * @return information about the exporter | ||
| */ | ||
| @Override | ||
| public String getComment() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * @param network the IIDM network to export | ||
| * @param parameters properties specific to this exporter | ||
| * @param dataSource access to outputStream | ||
| */ | ||
| @Override | ||
| public void export(Network network, Properties parameters, DataSource dataSource) { | ||
| // business logic to export a model to a given format | ||
| } | ||
|
|
||
| } | ||
| ``` | ||
|
|
||
| ## Deployment | ||
|
|
||
| ### Generating jar | ||
|
|
||
| Once your implementation is ready, run the following command to create your project jar: | ||
| ``` | ||
| $ cd <PROJECT_HOME> | ||
| $ mvn clean package | ||
| ``` | ||
|
|
||
| The jar file will be generated in `<PROJECT_HOME>/target`. | ||
|
|
||
| ### Adding the format in iTools | ||
|
|
||
| [iTools](../itools/index.md) allows the user to convert a network from one format to another via the | ||
| `convert-network` command line. | ||
|
|
||
| You can add your custom export format to the available output formats of the command by copying the generated jar in | ||
| your powsybl distribution: | ||
| ``` | ||
| $> cp target/my-exporter.jar <POWYSBL_HOME>/share/java | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| The code of a simple CSV Exporter is available in [powsybl-tutorials](https://github.com/powsybl/powsybl-tutorials) as a | ||
| complete example of this tutorial. | ||
|
|
||
| To try it, clone the project and deploy as below: | ||
| ``` | ||
| $ git clone https://github.com/powsybl/powsybl-tutorials.git | ||
| $ cd powsybl-tutorials/csv-exporter | ||
| $ mvn clean package | ||
| ``` | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| --- | ||
| layout: default | ||
| --- | ||
| # Write an IIDM importer | ||
|
|
||
| From Powsybl's `Importer` interface, it is possible to add a new file format from which | ||
| an IIDM data model can be loaded. | ||
|
|
||
| In order to do so, you will need to: | ||
| - Write an implementation of the `Importer` interface | ||
| - Declare the new class as a service implementation with the `@AutoService` annotation | ||
| - Build your jar | ||
|
|
||
| ## Configuring your module | ||
|
|
||
| In order to implement a new `Importer`, add the following dependencies in your `pom.xml` file: | ||
| - `auto-service (com.google.auto.service)`: Configuration/metadata generator for `ServiceLoader`-style providers | ||
| - `powsybl-iidm-converter-api`: IIDM network import/export API | ||
|
|
||
| ```xml | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.google.auto.service</groupId> | ||
| <artifactId>auto-service</artifactId> | ||
| <version>1.0-rc2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.powsybl</groupId> | ||
| <artifactId>powsybl-iidm-converter-api</artifactId> | ||
| <version>${powsybl.core.version}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| ``` | ||
|
|
||
| ## Implementation | ||
|
|
||
| As said above, you will need to write your own implementation of the `Importer` interface and declare it as a service | ||
| implementation. Here is an empty class template of an `Importer` implementation: | ||
|
|
||
| ```java | ||
| import com.powsybl.commons.datasource.DataSource; | ||
| import com.powsybl.commons.datasource.ReadOnlyDataSource; | ||
| import com.powsybl.iidm.import_.Importer; | ||
| import com.powsybl.iidm.network.Network; | ||
| import com.powsybl.iidm.parameters.Parameter; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Properties; | ||
|
|
||
| @AutoService(Importer.class) | ||
| public class MyImporter implements Importer { | ||
|
|
||
| /** | ||
| * Get a unique identifier of the format. | ||
| * | ||
| * @return the unique ID for the given format | ||
| */ | ||
| @Override | ||
| public String getFormat() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * This override is optional. By default, it returns Collections.emptyList() | ||
| * | ||
| * @return description of import parameters | ||
| */ | ||
| @Override | ||
| public List<Parameter> getParameters() { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| /** | ||
| * Get some information about this importer. | ||
| * | ||
| * @return information about the importer | ||
| */ | ||
| @Override | ||
| public String getComment() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Check if the data source is importable | ||
| * | ||
| * @param dataSource the data source | ||
| * @return true if the data source is importable, false otherwise | ||
| */ | ||
| @Override | ||
| public boolean exists(ReadOnlyDataSource dataSource) { | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Create a model. | ||
| * | ||
| * @param dataSource data source | ||
| * @param parameters some properties to configure the import | ||
| * @return the model | ||
| */ | ||
| @Override | ||
| public Network importData(ReadOnlyDataSource dataSource, Properties parameters) { | ||
| // business logic to import a network from a data source in a given format | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Copy data from one data source to another. | ||
| * | ||
| * @param fromDataSource from data source | ||
| * @param toDataSource destination data source | ||
| */ | ||
| @Override | ||
| public void copy(ReadOnlyDataSource fromDataSource, DataSource toDataSource) { | ||
| // business logic to copy a network from a data source to another file in a given format | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Deployment | ||
|
|
||
| ### Generating jar | ||
|
|
||
| Once your implementation is ready, run the following command to create your project jar: | ||
| ``` | ||
| $ cd <PROJECT_HOME> | ||
| $ mvn clean package | ||
| ``` | ||
|
|
||
| The jar file will be generated in `<PROJECT_HOME>/target`. | ||
|
|
||
| ### Adding the format in iTools | ||
|
|
||
| [iTools](../itools/index.md) allows the user to convert a network from one format to another via the | ||
| `convert-network` command line. | ||
|
|
||
| You can add your custom import format, allowing files in this format to be converted using the command, by copying the | ||
| generated jar in your powsybl distribution: | ||
| ``` | ||
| $> cp target/my-exporter.jar <POWYSBL_HOME>/share/java | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| The code of a simple CSV Importer is available in [powsybl-tutorials](https://github.com/powsybl/powsybl-tutorials) as a | ||
| complete example of this tutorial. | ||
|
|
||
| To try it, clone the project and deploy as below: | ||
| ``` | ||
| $ git clone https://github.com/powsybl/powsybl-tutorials.git | ||
| $ cd powsybl-tutorials/csv-importer | ||
| $ mvn clean package | ||
| ``` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a line at the end of the file
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| layout: default | ||
| --- | ||
| # IIDM import/export | ||
|
|
||
| ```{toctree} | ||
| --- | ||
| maxdepth: 2 | ||
| --- | ||
| importer.md | ||
| exporter.md | ||
| ``` |
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a line at the end of the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done