Skip to content
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

Validate and report misconfigured simulation export #91

Closed
qpavsmi opened this issue May 2, 2024 · 2 comments
Closed

Validate and report misconfigured simulation export #91

qpavsmi opened this issue May 2, 2024 · 2 comments
Assignees
Labels
feature A feature request submitted by the community FEM Finite Element simulations unitaryhack-bounty

Comments

@qpavsmi
Copy link
Contributor

qpavsmi commented May 2, 2024

Description

When running a simulation script, we need to define two sets of parameters: one that guides the shape of the geometry, and the other that guides the execution of the third-party simulator, such as Elmer or Ansys. Certain parameter settings of those two parameter sets can't work together. These should be validated and reported before the simulation export work is done.

Use case

When I write a simulation export script in klayout_package/python/scripts/simulations I might not notice or I might not know that I have defined simulation and solution parameters in such a way that they can't work together. Instead of spending too much time debugging the problem after the simulation work is done, I'd like the KQC simulation exporter to tell me that the parameters don't make sense and for what reason.

Prerequisites

KQCircuits standalone installation required, GUI installation prevents an error which in practice could be circumvented.

Get started

See for example the following block of code from klayout_package/python/scripts/simulations/swissmon_fluxline_sim.py

# Sweep simulation and solution type
simulations = [
    (
        sim_class(layout, **sim_parameters, name="fluxline_mut_ind", flux_simulation=True),
        AnsysCurrentSolution(
            max_delta_e=0.01,
            frequency=0.1,
            maximum_passes=20,
            integrate_magnetic_flux=True,
            mesh_size={"squid": 2, "vacuumrefine": 4, "substraterefine": 4},
        ),
    ),
    (
        sim_class(layout, **sim_parameters, name="fluxline_decay", flux_simulation=False),
        AnsysHfssSolution(max_delta_s=0.005, frequency=4.5, maximum_passes=20, sweep_enabled=False),
    ),
]

The simulations list here consists of tuples, for which the first object is of class Simulation containing the geometry data, and the other object is a dataclass object containing parameters that need to be fed to the simulator software, Ansys in this case.

simulations list gets fed to the export_ansys function (there is also export_elmer equivalent). This would be a perfect place to perform validations. Before any of the current function code is implemented, there could be a set of manually defined validations to be performed that, if at least one of them fails, the function halts and prints a user-friendly error.

These validation checks might be Ansys and Elmer specific, but let's still define a single function for validations that both export_elmer and export_ansys will call, so that validations can be maintained in one place. The main focus of this exercise is to enable infrastructure so that additional validations could be quite easily added without being too familiar with details of simulation export code.

Definition of done

  • export_ansys and export_elmer should call a function defined elsewhere in code that does validation checks.
  • If we come up with new validation checks, these should be easy to define (including condition, error message etc) and they should be clear when expressed in code.
  • Unit tests are welcome on the infrastructure as well as concrete validation scenarios.

Concrete validation scenarios to start with

  • If Simulation object has no ports, the Solution object type cannot be any of the following: AnsysHfssSolution, AnsysVoltageSolution, AnsysCurrentSolution, ElmerVectorHelmholtzSolution, ElmerCapacitanceSolution
  • If Simulation object has at least one port of type EdgePort, the Solution object type cannot be any of the following: AnsysEigenmodeSolution, AnsysVoltageSolution, AnsysCurrentSolution
  • If Solution object has a field integrate_magnetic_flux and it is set to True, the Simulation object should have at least one entry in layers dict such that it has thickness == 0.0 and material != 'pec'. Such layer is called a "non-pec sheet".
@qpavsmi qpavsmi added the feature A feature request submitted by the community label May 2, 2024
@qpavsmi qpavsmi added the FEM Finite Element simulations label May 17, 2024
@rmoretti9
Copy link
Contributor

I addressed this issue by creating a ValidateSim class in \kqcircuits\simulations\export\simulation_validate.py that implements the checks mentioned in the issue description. The methods of this class are called every time export_ansys or export_elmer are used, for example in the "_sim.py" scripts in klayout_package\python\scripts\simulations.

Unit tests are in tests\simulations\simulation_validate\test_simulation_validate.py

@qpavsmi
Copy link
Contributor Author

qpavsmi commented Jun 11, 2024

Thank you for your contribution and for participating in unitaryhack 2024!

@qpavsmi qpavsmi closed this as completed Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request submitted by the community FEM Finite Element simulations unitaryhack-bounty
Projects
None yet
Development

No branches or pull requests

2 participants