Parallel Parameter Scan
This page uses a local daemon resource to run the radius scan from Parameter Scan. The daemon schedules project solves on the declared resource. The example allows two project solves to run at the same time.
Declare A Local Resource
The script creates a daemon handler and adds one local workstation resource:
handler = jcmsuite.daemon.handler()
localhost = jcmsuite.daemon.Workstation(
hostname="localhost", multiplicity=2, n_threads=1
)
handler.resources.add(localhost)
multiplicity=2 allows two concurrent project solves. n_threads=1 assigns one solver
thread to each project solve. The with handler: block starts and connects the daemon:
with handler:
results = jcmsuite.solve("mie2D.jcmp", keys=keys, temporary=True, quiet=True)
When the block ends, JCMsuite disconnects the handler and stops the daemon.
Note
Set multiplicity and n_threads to values supported by the local computer
and the available JCMsuite licenses.
Run The Parallel Scan
import numpy as np
from matplotlib import pyplot as plt
import jcmsuite
# Set geometry parameter
radii = np.linspace(0.3, 0.5, 41)
keys = [{"radius": radius} for radius in radii]
# Create a daemon handler and add resources to it
handler = jcmsuite.daemon.handler()
localhost = jcmsuite.daemon.Workstation(
hostname="localhost", multiplicity=2, n_threads=1
)
handler.resources.add(localhost)
# Run the project
with handler:
results = jcmsuite.solve("mie2D.jcmp", keys=keys, temporary=True, quiet=True)
# Access the results of the first postprocess and export it to a dictionary
scattering_postprocess = results.postprocesses[0]
scattering_export = scattering_postprocess.to_xarray()
cross_sections = scattering_export["ElectromagneticFieldEnergyFlux"].squeeze().real
plt.plot(radii, cross_sections, "-+")
plt.xlabel(r"Radius [$\mu$ m]")
plt.ylabel("Integral scattering cross section")
plt.axis("tight")
plt.show()
The script uses the daemon handler as the context for solve. While the
daemon handler is active, the script passes batched project keys to solve.
The active handler selects the daemon backend. The call returns a
BatchSolveResult after all project solves finish.
The rest of the script is identical to the one in Parameter Scan.
Use A Remote Workstation
Use a remote workstation when the local computer does not provide sufficient
compute capacity. Create a Workstation and add it with
add(). Replace <remote_host_address> with the remote host name or
address. Set jcm_root to the JCMsuite installation directory on the remote
host.
The multiplicity value sets the number of concurrent project solves. The
n_threads value sets the number of solver threads for each project solve.
remote_workstation = jcmsuite.daemon.Workstation(
hostname="<remote_host_address>",
multiplicity=20,
n_threads=1,
jcm_root="<remote_jcm_root_dir>"
)
handler.resources.add(remote_workstation)
The Python process must connect to the remote host without an interactive password prompt. JCMsuite and a valid license must be available on the remote host. The daemon transfers the project and required project support files to the remote workstation automatically.
The returned BatchSolveResult contains the result data. For additional remote
files, plan a separate collection method. Use
Resources And Queues to configure scheduler
queues. When you submit solve work without waiting, use
Submit And Wait to collect the submission.
Project Files
run.py
import numpy as np
from matplotlib import pyplot as plt
import jcmsuite
# Set geometry parameter
radii = np.linspace(0.3, 0.5, 41)
keys = [{"radius": radius} for radius in radii]
# Create a daemon handler and add resources to it
handler = jcmsuite.daemon.handler()
localhost = jcmsuite.daemon.Workstation(
hostname="localhost", multiplicity=2, n_threads=1
)
handler.resources.add(localhost)
# Run the project
with handler:
results = jcmsuite.solve("mie2D.jcmp", keys=keys, temporary=True, quiet=True)
# Access the results of the first postprocess and export it to a dictionary
scattering_postprocess = results.postprocesses[0]
scattering_export = scattering_postprocess.to_xarray()
cross_sections = scattering_export["ElectromagneticFieldEnergyFlux"].squeeze().real
plt.plot(radii, cross_sections, "-+")
plt.xlabel(r"Radius [$\mu$ m]")
plt.ylabel("Integral scattering cross section")
plt.axis("tight")
plt.show()
layout.jcmt
Layout2D {
UnitOfLength = 1e-6
MeshOptions {
MaximumSideLength = 0.1
CurvilinearDegree = 2
}
Objects {
# Computational domain
Parallelogram {
Name = "ComputationalDomain"
DomainId = 1
Priority = ComputationalDomain
Width = 4
Height = 4
Boundary {
Class = Transparent
}
}
# Scatterer (rod)
Circle {
Name = "Rod"
DomainId = 2
Priority = 1
Radius = %(radius)e
}
}
}
materials.jcm
# material properties for the surroundings (air)
Material {
DomainId = 1
RelPermittivity = 1.0
RelPermeability = 1.0
}
# material properties the glass rod
Material {
DomainId = 2
RelPermittivity = 2.3104 # 1.52^2
RelPermeability = 1.0
}
mie2D.jcmp
Project {
InfoLevel = 3
Electromagnetics {
TimeHarmonic {
Scattering {
FieldComponents = Electric
Accuracy {
FiniteElementDegree = 3
Refinement {
MaxNumberSteps = 0
PreRefinements = 0
}
}
}
}
}
}
# computes the energy flux of the scattered field into the exterior domain
PostProcess {
FluxIntegration {
FieldBagPath = "./mie2D_results/fieldbag.jcm"
OutputFileName = "./mie2D_results/energyflux_scattered.jcm"
OutputQuantity = ElectromagneticFieldEnergyFlux
InterfaceType = ExteriorDomain
}
}
# exports computed field on cartesian grid
PostProcess {
ExportFields {
FieldBagPath = "./mie2D_results/fieldbag.jcm"
OutputFileName = "./mie2D_results/fieldbag_cartesian.jcm"
Cartesian {
NGridPointsX = 200
NGridPointsY = 200
}
}
}
sources.jcm
SourceBag {
Source {
ElectricFieldStrength {
PlaneWave {
K = [1.14239732857811e7 0.0 0.0]
Amplitude = [0 0 1]
}
}
}
}
Next Step
Continue to Persistent Parameter Scan to store and reuse solve results.