API reference

Autogenerated reference for the pypalace package.

Submodules

pypalace.analysis module

Quantum analysis utilities for extracting superconducting circuit Hamiltonian parameters from electromagnetic simulation results.

class pypalace.analysis.EPR

Bases: object

Utilities for computing qubit parameters using the energy participation ratio (EPR) method.

static calculate_anharmonicity(p_q, f_q, LJ)

Compute the qubit anharmonicity from the EPR method.

Parameters:
  • p_q (float) – Qubit energy participation ratio (unitless).

  • f_q (float) – Qubit frequency in Hz.

  • LJ (float) – Josephson inductance in Henries.

Returns:

Qubit anharmonicity in Hz (negative for transmons).

Return type:

float

Notes

Based on Eq. (9) of https://arxiv.org/pdf/2010.00620.

static calculate_coupling_strength(f_q, f_r, alpha_q, chi)

Compute the qubit–resonator coupling strength from the EPR method.

Parameters:
  • f_q (float) – Qubit frequency in Hz.

  • f_r (float) – Resonator frequency in Hz.

  • alpha_q (float) – Qubit anharmonicity in Hz.

  • chi (float) – Dispersive shift in Hz.

Returns:

Coupling strength g in Hz.

Return type:

float

Notes

Based on Eq. (9) of https://arxiv.org/pdf/2312.13483.

static calculate_dispersive_shift(p_q, p_r, f_q, f_r, LJ)

Compute the dispersive shift (chi) between a qubit and resonator from the EPR method.

Parameters:
  • p_q (float) – Qubit participation ratio (unitless).

  • p_r (float) – Resonator participation ratio (unitless).

  • f_q (float) – Qubit frequency in Hz.

  • f_r (float) – Resonator frequency in Hz.

  • LJ (float) – Josephson inductance in Henries.

Returns:

Dispersive shift (chi) in Hz.

Return type:

float

Notes

Based on Eq. (11) of https://arxiv.org/pdf/2010.00620.

static calculate_lamb_shift(alpha_q, chi)
class pypalace.analysis.LOM

Bases: object

Utilities for extracting qubit Hamiltonian parameters using a lumped oscillator model (LOM).

These methods map capacitance and inductance values to effective transmon parameters using scqubits and analytic expressions.

static calculate_C_Sigma(capacitance_matrix, topology)

Compute transmon total effective capacitance (C_Sigma).

Parameters:
Returns:

Transmon total effective capacitance (C_Sigma) in Farads.

Return type:

float

Notes

For now this method only works for a transmon qubit with a single coupler.

Assumed matrix orderings (naming convention of elements does not matter, only order): - "grounded": [island, coupler, ground] - "floating": [pad1, pad2, coupler, ground]

static calculate_C_r(f_r, m, Zc=50)

Compute resonator capacitance as an effective lumped capacitance.

Parameters:
  • f_r (float) – Resonator frequency [Hz]

  • m (int) – m = 2 for quarter-wavelength resonators and m = 4 for half-wavelength resonators.

  • Zc (float) – Waveguide’s characteristic impedance in Ohms, default is 50 Ohms.

Returns:

Resonator capacitance

Return type:

float

Notes

Taken from Equation 8 of SQuADDS paper (https://quantum-journal.org/papers/q-2024-09-09-1465/)

static calculate_coupling_strength(qubit_capacitance_matrix, LJ, f_r, C_r, topology)

Compute qubit-resonator coupling strength g.

Parameters:
Returns:

Coupling strength g in Hz.

Return type:

float

static calculate_dispersive_shift(f_q, f_r, alpha_q, g)

Compute the dispersive shift (chi) between a qubit and resonator from the LOM method.

Parameters:
  • f_q (float) – Qubit frequency in Hz.

  • f_r (float) – Resonator frequency in Hz.

  • alpha_q (float) – Qubit anharmonicity in Hz.

  • g (float) – g in Hz.

Returns:

Coupling strength chi in Hz.

Return type:

float

Notes

Based on Eq. (9) of https://arxiv.org/pdf/2312.13483

static get_qubit_Hamiltonian_parameters(C_Sigma, LJ)

Compute transmon Hamiltonian parameters from circuit values.

Parameters:
  • C_Sigma (float) – Total capacitance in Farads.

  • LJ (float) – Josephson inductance in Henries.

Returns:

Dictionary containing: - frequency_GHz : qubit transition frequency - anharmonicity_MHz : qubit anharmonicity

Return type:

dict

Notes

Uses scqubits to compute transmon energy levels.

class pypalace.analysis.resonator_analysis

Bases: object

get_resonator_parameters_driven(show=False, save=None)

Extracts f_r and kappa from a frequency-domain driven simulation of a superconducting resonator.

Fit complex S21 data via the Diameter Correction Method (DCM)

Parameters:
  • S_ij (pandas.DataFrame) – DataFrame containing frequency, magnitude (dB), and phase (degrees). Otained from pypalace.Simulation.get_Sij.

  • show (bool, optional) – If True (default), display the S21 plot.

  • save (str or None, optional) – If provided, save the plot to the specified file path If None (default), the plot is not saved.

Returns:

DataFrame containing frequency, magnitude (dB), and phase (degrees).

Return type:

dictionary

Raises:

ValueError – If the simulation type is not driven or if the specified port indices are invalid.

pypalace.builder module

Helper utilities for constructing AWS Palace configuration dictionaries.

This module provides builder-style functions that mirror the structure of the AWS Palace input file (e.g., Model, Domains, Boundaries, Solver). These functions return dictionaries formatted for use with pypalace.config.Config.

class pypalace.builder.Boundaries

Bases: object

Helper functions for generating config["Boundaries"] arguments for use with pypalace.config.Config.add_Boundaries().

These functions mirror AWS Palace boundary-condition and boundary-level postprocessing definitions and return dictionaries formatted for the Palace configuration file.

See the AWS Palace Boundaries documentation for the boundary types and postprocessing options that match the current stable Palace release. If you build Palace from a newer development tree, additional config["Boundaries"]["Postprocessing"] keys may exist there before they appear on the stable site; for example Impedance and Voltage mode postprocessing are described in Palace main branch boundaries.md.

static Absorbing(Attributes, Order=None)
static Conductivity(Attributes, Conductivity, Permeability=None, Thickness=None)
static Elements(Attributes, Direction, CoordinateSystem)
static Ground(Attributes)
static Impedance(Attributes, Rs=None, Ls=None, Cs=None)
static LumpedPort(Index, Attributes, Direction, CoordinateSystem=None, Excitation=None, Active=None, R=None, L=None, C=None, Rs=None, Ls=None, Cs=None, Elements=None)
static PEC(Attributes)
static PMC(Attributes)
static Periodic(DonorAttributes, ReceiverAttributes, Translation=None, AffineTransformation=None, FloquetWaveVector=None)
static Postprocessing_Dielectric(Index, Attributes, Type, Thickness, Permittivity, LossTan=None)
static Postprocessing_FarField(Attributes, NSample=None, ThetaPhis=None)
static Postprocessing_Impedance(Index, VoltageAttributes=None, CurrentAttributes=None, VoltagePath=None, CurrentPath=None, NSamples=None)
static Postprocessing_SurfaceFlux(Index, Attributes, Type, TwoSided=False, Center=None)
static Postprocessing_Voltage(Index, VoltageAttributes=None, VoltagePath=None, NSamples=None)
static SurfaceCurrent(Index, Attributes, Direction, CoordinateSystem=None, Elements=None)
static Terminal(Index, Attributes)
static WavePort(Index, Attributes, Excitation=None, Active=None, Mode=None, Offset=None, SolverType=None, MaxIts=None, KSPTol=None, EigenTol=None, Verbose=None)
static WavePortPEC(Attributes)
static ZeroCharge(Attributes)
class pypalace.builder.Domains

Bases: object

Helper functions for generating config["Domains"] arguments for use with pypalace.config.Config.add_Domains().

These functions mirror AWS Palace domain, material, and domain-level postprocessing definitions and return dictionaries formatted for the Palace configuration file.

See the AWS Palace Domains documentation for full details on materials and domain postprocessing.

static Material(Attributes, Permeability, Permittivity, LossTan=None, Conductivity=None, LondonDepth=None, MaterialAxes=None)
static Postprocessing_Energy(Index, Attributes)
static Postprocessing_Probe(Index, Center)
class pypalace.builder.Model

Bases: object

Helper functions for generating config["Model"] arguments for use with pypalace.config.Config.add_Model().

These functions mirror AWS Palace model and mesh-refinement settings and return dictionaries formatted for the Palace configuration file.

See the AWS Palace Model documentation for full details on model and refinement options.

static Refinement(Tol=None, MaxIts=None, MaxSize=None, Nonconformal=None, UpdateFraction=None, UniformLevels=None, Boxes=None, Spheres=None, SaveAdaptMesh=None, SaveAdaptIterations=None)
static Refinement_Boxes(Levels, BoundingBoxMin, BoundingBoxMax)
static Refinement_Spheres(Levels, Center, Radius)
class pypalace.builder.Solver

Bases: object

Helper functions for generating config["Solver"] arguments for use with pypalace.config.Config.add_Solver().

These functions mirror AWS Palace solver configurations for electrostatic, magnetostatic, eigenmode, driven, transient, boundary mode, and linear simulations.

See the AWS Palace Solver documentation for full details on solver options.

static BoundaryMode(Freq=None, N=1, Save=0, Target=0.0, Tol=None, MaxSize=None, Type='Default', Attributes=None)
static Driven(MinFreq, MaxFreq, FreqStep, SaveStep=None, Samples=None, Save=None, Restart=None, AdaptiveTol=None, AdaptiveMaxSamples=None, AdaptiveConvergenceMemory=None)
static Driven_Samples(Type, MinFreq=None, MaxFreq=None, FreqStep=None, NSample=None, Freq=None, SaveStep=None, AddToPROM=None)
static Eigenmode(Target, Tol=None, MaxIts=None, MaxSize=None, N=1, Save=1, Type='Default')
static Electrostatic(Save)
static Linear(Type='Default', KSPType='Default', Tol=None, MaxIts=None, MaxSize=None)
static Magnetostatic(Save)
static Transient(Type=None, Excitation=None, ExcitationFreq=None, ExcitationWidth=None, MaxTime=None, TimeStep=None, SaveStep=None, Order=None, RelTol=None, AbsTol=None)

pypalace.config module

Configuration interface for generating AWS Palace configuration files.

This module provides the Config class for building, validating, and saving Palace JSON configuration files.

class pypalace.config.Config(config_name: str)

Bases: object

Object used to generate AWS Palace configuration files.

This class constructs and manages the JSON configuration structure used for Palace simulations.

Parameters:

config_name (str) – Name of the configuration and path where the JSON file will be saved.

add_Boundaries(BCs, Postprocessing=[])

Add Boundaries block to the Palace configuration.

This corresponds to the config["Boundaries"] section in the AWS Palace configuration file.

Parameters:
  • BCs (list) – List of boundary conditions definitions generated using pypalace.builder.Boundaries boundary condition functions.

  • Postprocessing (list, optional) – List of Boundaries postprocessing definitions generated using pypalace.builder.Boundaries postprocessing functions (SurfaceFlux, Dielectric, FarField, and on recent Palace builds also Impedance and Voltage under Postprocessing).

add_Domains(Materials, Postprocessing=[])

Add Domains block to the Palace configuration.

This corresponds to the config["Domains"] section in the AWS Palace configuration file.

Parameters:
add_Model(Mesh: str, L0=1e-06, Lc=None, Refinement=None)

Add Model block to the Palace configuration.

This corresponds to the config["Model"] section in the AWS Palace configuration file.

Parameters:
  • Mesh (str) – Path to mesh file to be simulated.

  • L0 (float) – Length scale of mesh units relative to meters (default is 1.0e-6 corresponding to 1 mesh unit = 1 µm)

  • Lc (float, optional) – Characteristic length scale used for nondimensionalization.

  • Refinement (dict, optional) – Mesh refinement settings. This should be a dictionary generated using pypalace.builder.Model.Refinement().

add_Problem(Type: str, Output: str, Verbose=2)

Add Problem block to the Palace configuration.

This corresponds to the config["Problem"] section in the AWS Palace configuration file.

Parameters:
  • Type (str) – Problem type. Must be one of: “Electrostatic”, “Magnetostatic”, “Eigenmode”, “Driven”, “Transient”, or “BoundaryMode”.

  • Output (str) – Directory path where simulation results will be saved.

  • Verbose (int, optional) – Verbosity level of the Palace log file (default is 2).

add_Solver(Simulation, Order=1, Device='CPU', Linear=None)

Add Solver block to the Palace configuration.

This corresponds to the config["Solver"] section in the AWS Palace configuration file.

Parameters:
  • Simulation (dict) – Dictionary of simulation hyperparameters generated using pypalace.builder.Solver parameter functions.

  • Order (int) – Finite element order.

  • Device (str) – Runtime device configuration. Must be one of: “CPU”, “GPU”, “Debug”.

classmethod load_config(config_name)

Creates a new config object from a pre-existing Palace configuration file.

Parameters:

config_name (str) – Path to pre-existing configuration file

print_config()

Print the current configuration as formatted JSON.

save_config(check_validity=True)

Saves Config object as AWS Palace .JSON configuration file.

Parameters:

check_validity (bool, optional) – If True, check that all required configuration blocks have been defined before saving (default True).

pypalace.simulation module

Simulation interface for running AWS Palace workflows.

This module provides the Simulation class, which executes Palace simulations (locally or on HPC systems) and extracts outputs such as capacitance matrices, eigenfrequencies, linewidths, and S-parameters.

class pypalace.simulation.Simulation(config: Config, path_to_palace: str)

Bases: object

Interface for running AWS Palace simulations and extracting results.

This class manages the full simulation workflow, including: - executing Palace simulations locally or on HPC systems - handling job submission (e.g., Slurm) - extracting simulation outputs (capacitance matrices, eigenfrequencies, S-parameters, etc.)

Parameters:
  • config (pypalace.config.Config) – Config object defining the Palace simulation.

  • path_to_palace (str) – Path to the Palace executable.

HPC_options(time, nodes, ntasks_per_node, mem, job_name, custom=None)

Define Slurm job directives for running simulations on an HPC system.

The returned list can be passed to Simulation.run() to submit the simulation via sbatch.

Parameters:
  • partition (str) – Slurm partition name.

  • time (str) – Job time limit (e.g., "02:00:00").

  • nodes (int) – Number of nodes.

  • ntasks_per_node (int) – Number of MPI tasks per node.

  • mem (int) – Memory per node in GB.

  • job_name (str) – Name of the Slurm job.

  • custom (list, optional) – Additional Slurm directives.

Returns:

List of Slurm directive strings.

Return type:

list

get_Sij(index1: int, index2: int)

Extract S-parameters between two ports from a driven simulation.

Parameters:
  • index1 (int) – input port index.

  • index2 (int) – output port index.

Returns:

DataFrame containing frequency, magnitude (dB), and phase (degrees).

Return type:

pandas.DataFrame

Raises:

ValueError – If the simulation type is not driven or if the specified indices are invalid.

get_capacitance_matrix()

Extract the capacitance matrix from an electrostatic simulation.

Returns:

Capacitance matrix labeled by terminal names.

Return type:

pandas.DataFrame

Raises:

ValueError – If the simulation type is not electrostatic.

get_frequency_eigenmode(mode: int)

Extract the eigenfrequency of a specified mode.

Parameters:

mode (int) – Eigenmode index.

Returns:

Eigenfrequency in Hz.

Return type:

float

Raises:

ValueError – If the simulation type is not eigenmode.

get_kappa_eigenmode(mode: int)

Compute the linewidth (kappa) of a specified eigenmode from its complex frequency.

Parameters:

mode (int) – Eigenmode index.

Returns:

Linewidth (kappa) in Hz.

Return type:

float

Raises:

ValueError – If the simulation type is not eigenmode.

get_portEPR(port_index: int, mode: int)

Extract the energy participation ratio (EPR) for a given port and mode.

Parameters:
  • port_index (int) – Port index.

  • mode (int) – Eigenmode index.

Returns:

Energy participation ratio.

Return type:

float

Raises:

ValueError – If the simulation type is not eigenmode or if the port is not defined.

plot_field(field, index, normal='z', origin=(0, 0, 0), quantity='magnitude', part='real', scale=None, cmap=None, show=True, save=None)

Plot a field from Palace simulation output (ParaView/PVD).

Parameters:
  • field (str) – Field to visualize. Supported options: “E” (electric field), “B” (magnetic field), “U_e” (electric energy density), “U_m” (magnetic energy density), “S” (Poynting vector).

  • index (int) – Mode index (time step) to visualize.

  • normal (str or tuple, optional) – Normal vector defining the slice plane. Default is “z” (i.e., an xy-plane slice). Can also be a 3-tuple.

  • origin (tuple, optional) – Origin of the slice plane. Default is (0, 0, 0).

  • quantity (str, optional) –

    Quantity to plot for vector fields (“E”, “B”, “S”). Options: - “magnitude” : ||field|| - “x”, “y”, “z” : corresponding Cartesian component

    Ignored for scalar fields (“U_e”, “U_m”).

  • part (str, optional) –

    For vector fields (“E”, “B”, “S”) and when quantity is not set to “magnitude” selects which part of the complex field to visualize:

    • ”real” : real part (default)

    • ”imag” : imaginary part

  • scale (tuple, optional) – Color scale limits for the plot, given as (vmin, vmax). If None (default), limits are set automatically: - For “magnitude”: based on the 1st–99th percentile range - For components: symmetric about zero using the 99th percentile

  • cmap (str, optional) – Matplotlib colormap to use for visualization. If None (default), uses: - “inferno” for magnitude plots - “RdBu_r” for component plots (diverging, centered at zero)

  • show (bool, optional) – If True (default), display the plot.

  • save (str or None, optional) – If provided, save the plot to the specified file path If None (default), the plot is not saved.

Notes

  • Vector fields are reconstructed from real and imaginary components.

  • Eigenmode fields are complex; “magnitude” is phase-independent, while individual components depend on the chosen phase convention.

run(n, HPC_options=None, custom_script_name=None)

Run the simulation.

If HPC_options is provided, a Slurm job script is generated and submitted using sbatch. Otherwise, the simulation is executed locally using mpirun.

Parameters:
  • n (int) – Number of MPI processes.

  • HPC_options (list, optional) – Slurm directive list generated by Simulation.HPC_options().

  • custom_script_name (str, optional) – Name of the generated job script file.

pypalace.meshing module

pyPalace utilities for mesh generation and mesh inspection

class pypalace.meshing.Mesh

Bases: object

Mesh I/O and Gmsh export helpers for Palace workflows.

static get_mesh_attributes(filename: str | Path)

Extract physical attribute names, IDs, and entity types from a mesh file.

Supported mesh formats include .bdf and .msh files.

Parameters:

filename (str) – Path to the mesh file.

Returns:

DataFrame with columns Name, ID, and Type.

Return type:

pandas.DataFrame

mesh_Quantum_Metal_design(output_mesh: str | Path = 'mesh_for_pyPalace.msh', *, Attributes: dict[str | tuple[str, str], int] | None = None, substrate_thickness: float = 0.5, airbox_height: float = 0.5, margin: float = 0.5, volume_mesh_size: float = 0.1, surface_mesh_size: float = 0.005, refinement_radius: float = 0.05, mesh_scale: float = 1000.0, ground_plane_attr: int | str = 'auto', farfield_attr: int | str = 'auto', substrate_attr: int | str = 'auto', air_attr: int | str = 'auto', geom_tol_factor: float = 0.01)
Generate a Palace-ready Gmsh mesh from a Quantum Metal design.

Only for coplanar designs.

Parameters:
  • design – Active Qiskit Metal design. The function reads design.qgeometry.tables["poly"].

  • output_mesh – Path to the .msh file to write.

  • Attributes – Mapping from polygon row name to Palace attribute. Keys may be either "name" or ("component", "name") for an exact row. Rows not in this mapping are still imprinted, but receive no explicit surface physical group.

  • substrate_thickness – Geometry lengths in the design’s units. Qiskit Metal defaults to mm.

  • airbox_height – Geometry lengths in the design’s units. Qiskit Metal defaults to mm.

  • margin – Geometry lengths in the design’s units. Qiskit Metal defaults to mm.

  • volume_mesh_size – Bulk mesh target in design units.

  • surface_mesh_size – Mesh target on every circuit polygon face (metals and etch annuli).

  • refinement_radius – Distance over which the background field grows from surface_mesh_size to volume_mesh_size.

  • mesh_scale – Multiplies all design coordinates before writing the mesh. If the design is in mm and Palace uses L0 = 1e-6 (one mesh unit is one micron), use mesh_scale = 1000.

  • ground_plane_attr – Integer attributes or "auto". Auto assigns these after the largest user-provided polygon attribute.

  • farfield_attr – Integer attributes or "auto". Auto assigns these after the largest user-provided polygon attribute.

  • substrate_attr – Volume physical-group attributes.

  • air_attr – Volume physical-group attributes.

  • geom_tol_factor – Tolerance used for face-to-polygon classification, as a fraction of surface_mesh_size after scaling.

Package contents

class pypalace.Config(config_name: str)

Bases: object

Object used to generate AWS Palace configuration files.

This class constructs and manages the JSON configuration structure used for Palace simulations.

Parameters:

config_name (str) – Name of the configuration and path where the JSON file will be saved.

add_Boundaries(BCs, Postprocessing=[])

Add Boundaries block to the Palace configuration.

This corresponds to the config["Boundaries"] section in the AWS Palace configuration file.

Parameters:
  • BCs (list) – List of boundary conditions definitions generated using pypalace.builder.Boundaries boundary condition functions.

  • Postprocessing (list, optional) – List of Boundaries postprocessing definitions generated using pypalace.builder.Boundaries postprocessing functions (SurfaceFlux, Dielectric, FarField, and on recent Palace builds also Impedance and Voltage under Postprocessing).

add_Domains(Materials, Postprocessing=[])

Add Domains block to the Palace configuration.

This corresponds to the config["Domains"] section in the AWS Palace configuration file.

Parameters:
add_Model(Mesh: str, L0=1e-06, Lc=None, Refinement=None)

Add Model block to the Palace configuration.

This corresponds to the config["Model"] section in the AWS Palace configuration file.

Parameters:
  • Mesh (str) – Path to mesh file to be simulated.

  • L0 (float) – Length scale of mesh units relative to meters (default is 1.0e-6 corresponding to 1 mesh unit = 1 µm)

  • Lc (float, optional) – Characteristic length scale used for nondimensionalization.

  • Refinement (dict, optional) – Mesh refinement settings. This should be a dictionary generated using pypalace.builder.Model.Refinement().

add_Problem(Type: str, Output: str, Verbose=2)

Add Problem block to the Palace configuration.

This corresponds to the config["Problem"] section in the AWS Palace configuration file.

Parameters:
  • Type (str) – Problem type. Must be one of: “Electrostatic”, “Magnetostatic”, “Eigenmode”, “Driven”, “Transient”, or “BoundaryMode”.

  • Output (str) – Directory path where simulation results will be saved.

  • Verbose (int, optional) – Verbosity level of the Palace log file (default is 2).

add_Solver(Simulation, Order=1, Device='CPU', Linear=None)

Add Solver block to the Palace configuration.

This corresponds to the config["Solver"] section in the AWS Palace configuration file.

Parameters:
  • Simulation (dict) – Dictionary of simulation hyperparameters generated using pypalace.builder.Solver parameter functions.

  • Order (int) – Finite element order.

  • Device (str) – Runtime device configuration. Must be one of: “CPU”, “GPU”, “Debug”.

classmethod load_config(config_name)

Creates a new config object from a pre-existing Palace configuration file.

Parameters:

config_name (str) – Path to pre-existing configuration file

print_config()

Print the current configuration as formatted JSON.

save_config(check_validity=True)

Saves Config object as AWS Palace .JSON configuration file.

Parameters:

check_validity (bool, optional) – If True, check that all required configuration blocks have been defined before saving (default True).