qdesignoptimizer.utils.utils module

Utility functions for geometry calculations and runtime operations in quantum circuit designs.

This module provides helper functions for common geometric calculations needed in quantum circuit design and simulation, such as finding junction positions, calculating midpoints, normalizing vectors, and performing rotations. It also includes utilities for string parsing of values with units and process management.

qdesignoptimizer.utils.utils.close_ansys() None[source]

Terminate all running Ansys HFSS processes using Windows task management.

Note

This function only works on Windows operating systems.

qdesignoptimizer.utils.utils.get_junction_position(design, qcomponent) Tuple[str, str][source]

Calculate the position of a Josephson junction in a quantum component.

Extracts the geometric coordinates of a Josephson junction from a quantum component’s geometry tables. This is particularly useful for determining where flux lines should be placed in relation to the junction.

Parameters:
  • design – The Qiskit Metal design containing the component.

  • qcomponent – The quantum component containing the junction.

Returns:

A tuple of (x, y) coordinates as strings with “mm” units, suitable for use in QComponent options.

Note

Supports only components containing a single junction.

Example

>>> x_pos, y_pos = get_junction_position(design, transmon)
>>> print(x_pos, y_pos)
'2.5mm' '3.7mm'
qdesignoptimizer.utils.utils.get_middle_point(point1: Tuple[float, float], point2: Tuple[float, float]) Tuple[float, float][source]

Calculate the midpoint between two points in a 2D plane.

Parameters:
  • point1 – The (x, y) coordinates of the first point.

  • point2 – The (x, y) coordinates of the second point.

Returns:

The (x, y) coordinates of the midpoint.

Example

>>> get_middle_point((0, 0), (10, 20))
(5.0, 10.0)
qdesignoptimizer.utils.utils.get_normalized_vector(point1: Tuple[float, float], point2: Tuple[float, float]) Tuple[float, float][source]

Calculate the normalized unit vector pointing from point1 to point2.

Computes a vector of length 1 that points in the direction from the first point to the second point in a 2D plane.

Parameters:
  • point1 – The (x, y) coordinates of the origin point.

  • point2 – The (x, y) coordinates of the target point.

Returns:

A tuple (dx, dy) representing the normalized vector components.

Example

>>> get_normalized_vector((0, 0), (3, 4))
(0.6, 0.8)
qdesignoptimizer.utils.utils.rotate_point(point: ndarray, rotation_center: ndarray, angle_rad: float) ndarray[source]

Rotate a point counterclockwise around a center point by a specified angle.

Applies a 2D rotation transformation to a point around a specified center using standard rotation matrix operations.

Parameters:
  • point – A numpy array [x, y] representing the point to rotate.

  • rotation_center – A numpy array [x, y] representing the center of rotation.

  • angle_rad – The angle of rotation in radians (positive for counterclockwise).

Returns:

A numpy array with the coordinates of the rotated point.

Example

>>> import numpy as np
>>> rotate_point(np.array([1, 0]), np.array([0, 0]), np.pi/2)
array([0., 1.])
qdesignoptimizer.utils.utils.get_value_and_unit(val_unit: str) Tuple[float, str][source]

Extract numerical value and unit from a string representation.

Parses a string containing a number followed by an optional unit (e.g., “10.5mm”) and separates it into the numerical value and unit string.

Parameters:

val_unit – A string representing a value with optional unit (e.g., “10.5mm”).

Returns:

A tuple (value, unit) where value is a float and unit is a string. If no unit is present, the unit string will be empty..

Example

>>> get_value_and_unit("10.5mm")
(10.5, 'mm')
>>> get_value_and_unit("42")
(42.0, '')
qdesignoptimizer.utils.utils.sum_expression(vals: List[str]) str[source]

Calculate the sum of values with consistent units.

Takes a list of strings representing values with units (e.g., [“10mm”, “5mm”]), extracts the numerical values while preserving the unit, computes their sum, and returns the result with the same unit.

Parameters:

vals – A list of strings representing values with the same unit.

Returns:

A string representing the sum with the preserved unit.

Raises:

AssertionError – If the units of the provided values are not the same.

Example

>>> sum_expression(["10mm", "5mm", "2.5mm"])
'17.5mm'
>>> sum_expression(["1.2GHz", "0.8GHz"])
'2.0GHz'
qdesignoptimizer.utils.utils.get_save_path(out_folder: str, chip_name: str, time_format: str = '%Y%m%d-%H%M%S')[source]

Create a path to save simulation results by appending the start time of the simulation to the identifier name.