def test_export_import(self): waveguide = Waveguide([0, 0], 0, 1) for i_bend in range(9): waveguide.add_bend(angle=np.pi, radius=60 + i_bend * 40) offset = (10, 10) angle = np.pi cell = Cell('test') cell.add_to_layer(1, waveguide) sub_cell = Cell('sub_cell') sub_cell.add_to_layer(2, waveguide) cell.add_cell(sub_cell, origin=(0, 0), angle=0) sub_cell2 = Cell('sub_cell2') sub_cell2.add_to_layer(3, waveguide) cell.add_cell(sub_cell2, origin=offset, angle=angle) cell.save(grid_steps_per_micron=10000) def assert_almost_equal_shapely(a, b, tolerance=2e-4): self.assertTrue(a.buffer(tolerance).contains(b)) self.assertTrue(b.buffer(tolerance).contains(a)) assert_almost_equal_shapely( waveguide.get_shapely_object(), GDSIIImport('test.gds', 'test', 1).get_shapely_object()) assert_almost_equal_shapely( waveguide.get_shapely_object(), GDSIIImport('test.gds', 'test', 2).get_shapely_object()) assert_almost_equal_shapely( translate(rotate(waveguide.get_shapely_object(), angle, use_radians=True, origin=(0, 0)), *offset), GDSIIImport('test.gds', 'test', 3).get_shapely_object()) self.assertTrue(GDSIIImport('test.gds', 'test', 1, 2).get_shapely_object().is_empty)
def _example(): from gdshelpers.geometry.chip import Cell devicename = 'MZI' mzi = MachZehnderInterferometer(origin=(0, 0), angle=0, width=1.2, splitter_length=10, splitter_separation=5, bend_radius=50, upper_vertical_length=50, lower_vertical_length=0, horizontal_length=0) mzi_mmi = MachZehnderInterferometerMMI(origin=(300, 0), angle=0, width=1.2, splitter_length=33, splitter_width=7.7, bend_radius=50, upper_vertical_length=50, lower_vertical_length=0, horizontal_length=0) print(mzi_mmi.device_width) wg = Waveguide.make_at_port(mzi_mmi.port) wg.add_straight_segment(length=50) cell = Cell(devicename) cell.add_to_layer(1, mzi) cell.add_to_layer(1, mzi_mmi) cell.add_to_layer(1, wg) cell.save('%s.gds' % devicename)
def example(): start_port = Port((0, 0), 0.5 * np.pi, 1.) wg1 = Waveguide.make_at_port(start_port) wg1.add_straight_segment(100.) # wg1.add_bend(0, 60.) detector = SNSPD.make_at_port(wg1.current_port, **snspd_parameters) wg = detector.get_waveguide() electrodes = detector.get_electrodes() pl = detector.get_passivation_layer(passivation_buffer=0.2) wg2 = Waveguide.make_at_port(detector.current_port) wg2.add_straight_segment(50.) # cell = gdsCAD.core.Cell('test') cell = Cell('test') cell.add_to_layer(3, Point(detector.get_aux_top()[0]).buffer(0.05)) cell.add_to_layer(4, Point(detector.get_aux_top()[1]).buffer(0.05)) cell.add_to_layer(3, Point(detector.get_aux_bottom()[0]).buffer(0.05)) cell.add_to_layer(4, Point(detector.get_aux_bottom()[1]).buffer(0.05)) cell.add_to_layer(3, wg1) cell.add_to_layer(1, detector) cell.add_to_layer(2, detector.get_waveguide()) cell.add_to_layer(6, detector.get_electrodes()) cell.add_to_layer(5, pl) # cell.add_to_layer(6, detector.right_electrode_port.debug_shape) # cell.add_to_layer(6, detector.left_electrode_port.debug_shape) cell.add_to_layer(3, wg2) cell.save('SNSPD_test.gds') cell.show()
def _example(): from gdshelpers.geometry.chip import Cell from gdshelpers.parts.splitter import Splitter from gdshelpers.parts.coupler import GratingCoupler port = Port([0, 0], 0, 1) path = Waveguide.make_at_port(port) path.add_straight_segment(10) path.add_bend(np.pi / 2, 10, final_width=0.5) path.add_bend(-np.pi / 2, 10, final_width=1) path.add_arc(np.pi * 3 / 4, 10, ) splitter = Splitter.make_at_root_port(path.current_port, 30, 10) path2 = Waveguide.make_at_port(splitter.right_branch_port) path2.add_bend(-np.pi / 4, 10) n = 10 path2.add_parameterized_path(lambda t: (n * 10 * t, np.cos(n * 2 * np.pi * t) - 1), path_derivative=lambda t: (n * 10, -n * 2 * np.pi * np.sin(n * 2 * np.pi * t)), width=lambda t: np.cos(n * 2 * np.pi * t) * 0.2 + np.exp(-t) * 0.3 + 0.5, width_function_supports_numpy=True) path2.add_straight_segment(10, width=[.5, .5, .5]) print(path2.length) print(path2.length_last_segment) path2.add_cubic_bezier_path((0, 0), (5, 0), (10, 10), (5, 10)) path2.add_bend(-np.pi, 40) coupler1 = GratingCoupler([100, 50], 0, 1, np.deg2rad(30), [10, 0.1, 2, 0.1, 2], start_radius_absolute=True) path3 = Waveguide((0, -50), np.deg2rad(0), 1) path3.add_bezier_to(coupler1.port.origin, coupler1.port.inverted_direction.angle, bend_strength=50) splitter2 = Splitter.make_at_left_branch_port(splitter.left_branch_port, 30, 10, wavelength_root=2) path4 = Waveguide.make_at_port(splitter2.root_port) path4.add_straight_segment(20) path4.width = 1 path4.add_straight_segment(20) empty_path = Waveguide.make_at_port(path4.current_port) whole_layout = (path, splitter, path2, splitter2, coupler1, path3, path4, empty_path) layout = Cell('LIBRARY') cell = Cell('TOP') cell.add_to_layer(1, *whole_layout) cell.add_to_layer(2, empty_path) cell.add_to_layer(4, splitter.root_port.debug_shape) layout.add_cell(cell) cell_df = Cell('TOP_DF') cell_df.add_to_layer(1, convert_to_positive_resist(whole_layout, buffer_radius=1.5)) layout.add_cell(cell_df) layout.save('output.gds') cell.show()
def _example(): qr_code = QRCode([0, 0], 'A0.0', 1.0, version=1, error_correction=QRCode.ERROR_CORRECT_M) from gdshelpers.geometry.chip import Cell device = Cell('test') device.add_to_layer(1, qr_code) device.show() chip = Cell('optical_codes') chip.add_cell(device) chip.start_viewer() chip.save()
def _example(): from gdshelpers.geometry.chip import Cell from gdshelpers.geometry import geometric_union # Generate a coupler, which ought to be identical to # coupler_sn330_1550_bf_ff_ap( 0:0 1550 0.7 22 0.96 10 22 1 "active") # also known as # coupler_bf_ap_mff( 0:0 1 40.0 1.13 0.7 22 0.96 10 22 200 "active") coupler = GratingCoupler.make_traditional_coupler([150, 0], 1, np.deg2rad(40), 1.13, 0.7, 22, 0.96, 10, 22, angle=-np.pi) coupler2 = GratingCoupler.make_traditional_coupler_from_database([0, 0], 1, 'sn330', 1550) print(coupler.get_description_str()) whole_layout = (coupler, coupler2) layout = Cell('LIBRARY') cell = Cell('TOP') cell.add_to_layer(1, *whole_layout) cell.add_to_layer(StandardLayers.parnamelayer1, coupler.get_description_text()) cell.add_to_layer(StandardLayers.parnamelayer1, coupler2.get_description_text()) cell.add_to_layer(1, coupler.get_description_text()) cell.add_to_layer(1, coupler2.get_description_text()) cell.add_to_layer(1, coupler2.get_description_text(side='left')) layout.add_cell(cell) # We could also easily generate a dark field layout out of this def make_dark_field(obj, buffer_size=1.5): return obj.buffer(buffer_size).difference(obj) cell_df = Cell('TOP_DF') cell_df.add_to_layer(2, make_dark_field(geometric_union(whole_layout))) layout.add_cell(cell_df) layout.save('coupler.gds') cell.show()
def test_export_import(self): waveguide = Waveguide([0, 0], 0, 1) for i_bend in range(9): waveguide.add_bend(angle=np.pi, radius=60 + i_bend * 40) offset = (10, 10) angle = np.pi cell = Cell('test') cell.add_to_layer(1, waveguide) sub_cell = Cell('sub_cell') sub_cell.add_to_layer(2, waveguide) cell.add_cell(sub_cell, origin=(0, 0), angle=0) sub_cell2 = Cell('sub_cell2') sub_cell2.add_to_layer(3, waveguide) cell.add_cell(sub_cell2, origin=offset, angle=angle) cell.save(library='gdshelpers', grid_steps_per_micron=10000) self.assertTrue(waveguide.get_shapely_object().almost_equals( GDSIIImport('test.gds', 'test', 1).get_shapely_object(), decimal=3)) self.assertTrue(waveguide.get_shapely_object().almost_equals( GDSIIImport('test.gds', 'test', 2).get_shapely_object(), decimal=3)) self.assertTrue( translate( rotate(waveguide.get_shapely_object(), angle, use_radians=True, origin=(0, 0)), *offset).almost_equals(GDSIIImport('test.gds', 'test', 3).get_shapely_object(), decimal=3)) self.assertTrue( GDSIIImport('test.gds', 'test', 1, 2).get_shapely_object().is_empty)
def _example(): from gdshelpers.geometry.chip import Cell cell = Cell('test') wg1 = Waveguide((0, 0), 0.5 * np.pi, 1.) wg1.add_straight_segment(10.) cell.add_to_layer(3, wg1) detector = SNSPD.make_at_port(wg1.current_port, nw_width=0.1, nw_gap=0.1, nw_length=70, passivation_buffer=0.2, waveguide_tapering=True) cell.add_to_layer(1, detector) cell.add_to_layer(2, detector.get_waveguide()) cell.add_to_layer(5, detector.get_passivation_layer()) # cell.add_to_layer(6, detector.right_electrode_port.debug_shape) # cell.add_to_layer(6, detector.left_electrode_port.debug_shape) wg2 = Waveguide.make_at_port(detector.current_port) wg2.add_straight_segment(20.) cell.add_to_layer(3, wg2) cell.save('SNSPD_test.gds') cell.show()
diff = np.array(center_coordinates.interpolate(pos + padding / 2)) - np.array( center_coordinates.interpolate(pos - padding / 2)) d1 = np.array((-diff[1], diff[0])) / np.linalg.norm(diff) for direction in [-1, 1]: point = Point(xy + direction * (offset + spacing / 2 * (i % 2)) * d1) if outline.contains(point): new_circles = True if area_for_holes.contains(point): circles.append(point.buffer(hole_radius)) offset += spacing return unary_union(circles) if __name__ == '__main__': from gdshelpers.geometry.chip import Cell from gdshelpers.parts.waveguide import Waveguide wg = Waveguide((0, 0), 0, [3, 3, 3, 3, 3]) wg.add_straight_segment(5) wg.add_bend(np.pi / 2, 20) wg.width = 15 wg.add_straight_segment(4) wg.add_bend(-np.pi / 2, 20) cell = Cell('vortex_traps') cell.add_to_layer(1, wg) cell.add_to_layer(2, fill_waveguide_with_holes_in_honeycomb_lattice(wg, 1, .1, .15)) cell.add_to_layer(2, surround_with_holes(wg.get_shapely_outline(), 3, 1, 1, 15)) cell.show() cell.save()
text=info_text, alignment='center-bottom', angle=np.pi) cell.add_to_layer(comment_layer, device_info) return cell ####################################################################################### if __name__ == "__main__": devices = [] #### ADD Modulators global_cell = Cell('Demux_Tests') # global_cell.add_to_layer(marker_protection_layer, device.get_markers_protection()) coupler_sep = 0.5 coupler_length = 30 electrodes_sep = 1.1 for j, MZ_length in enumerate(np.linspace(1250, 1500, 2)): temp_cell = Demux_active(coupler_sep, coupler_length, MZ_length, electrodes_sep, 'D%i' % j) temp_cell.name = 'Demux_test_' + str(j) # global_cell.add_cell(temp_cell, origin=(-2000 + j * 1000, -1500), angle=np.pi) global_cell.add_cell(temp_cell, origin=(-2000 + j * 3000, -1500)) print('starting device saving') global_cell.save('tests_Demux.gds') print('done saving')
text=info_text, alignment='center-bottom', angle=np.pi) cell.add_to_layer(comment_layer, device_info) return cell ####################################################################################### if __name__ == "__main__": devices = [] #### ADD Modulators global_cell = Cell('Modulators_Tests') # global_cell.add_to_layer(marker_protection_layer, device.get_markers_protection()) coupler_sep = 0.4 coupler_length = 22 electrodes_sep = 1.1 for j, MZ_length in enumerate(np.linspace(500, 1250, 4)): temp_cell = MZI_active(coupler_sep, coupler_length, MZ_length, electrodes_sep, 'D%i' % j) temp_cell.name = 'MZI_test_' + str(j) # global_cell.add_cell(temp_cell, origin=(-2000 + j * 1000, -1500), angle=np.pi) global_cell.add_cell(temp_cell, origin=(-2000 + j * 1000, -1500)) print('starting device saving') global_cell.save('tests_Modulators.gds') print('done saving')
] polygon1 = Polygon(outer_corners) origin = wg_end._current_port.origin print("End Point: ", origin) origin[0] = origin[0] + 2 * gap outer_corners = [ origin, (origin[0], origin[1] + 2 * gap), (origin[0] - 2 * gap, origin[1] + 2 * gap), (origin[0] - 2 * gap, origin[1] - 2 * gap), (origin[0], origin[1] - 2 * gap) ] polygon2 = Polygon(outer_corners) polygon = polygon1.union(polygon2) layout_fixed = layout.difference(polygon) return layout_fixed layout = IL_mmi((0, 0), num_roundtrip=1, len_deltaL=500) layout2 = IL_mmi((0, -150), num_roundtrip=2, len_deltaL=500) cell = Cell('MZI_') cell.add_to_layer(1, layout) cell.add_to_layer(1, layout2) cell.save('./layout/IL_MZI.gds') # cell.show()
cell.add_to_layer(comment_layer, device_info) return cell ####################################################################################### if __name__ == "__main__": devices = [] #### ADD Modulators global_cell = Cell('Modulators_Tests') # global_cell.add_to_layer(marker_protection_layer, device.get_markers_protection()) coupler_sep = 0.4 coupler_length = 22 electrodes_sep = 1.1 for j, MZ_length in enumerate(np.linspace(500, 1250, 4)): temp_cell = MZI_active_with_phase(coupler_sep, coupler_length, MZ_length, electrodes_sep, 'D%i' % j) temp_cell.name = 'MZI_test_' + str(j) # global_cell.add_cell(temp_cell, origin=(-2000 + j * 1000, -1500), angle=np.pi) global_cell.add_cell(temp_cell, origin=(-2000 + j * 1000, -1500)) print('starting device saving') global_cell.save('tests_ModulatorsWithPhase.gds') print('done saving')
angle=0, width=0.45, num=16, gap=3, inner_gap=30) # get the shapely device = geometric_union([spiral]) # Boolean operation: difference buffer_device = device.buffer(3) buffer_not_device = buffer_device.difference(device) cell = Cell('cell_difference') cell.add_to_layer(1, buffer_not_device) # Here don't use cell.show() to verify the issue, and use cell.save() please. cell.save('gdshelpers_difference.gds') # And I found it's OK if I use "not" from gdspy.boolean() from gdshelpers.geometry import convert_to_layout_objs import gdspy # STEP 1: lib = gdspy.GdsLibrary(precision=1e-10) # create a new cell to save cell_gdspy = lib.new_cell("cell_not_gdspy") geo1 = convert_to_layout_objs(buffer_device, library='gdspy') geo2 = convert_to_layout_objs(device, library='gdspy') inv = gdspy.boolean(geo1, geo2, "not") cell_gdspy.add(inv)
# temp_pos = init_spirals_pos # for x, num in enumerate(scan_list): # this_dev = RectangularSpiral(temp_pos + np.array((dev_dist_list[x], 0)), id_to_alphanumeric(x, 0), 2*int(num/2.), # add_xlength=0, add_ylength=4000, sep=5, r_curve=45) # devices += [this_dev] # this_box = this_dev.get_box() # temp_pos = np.array((max((this_box.exterior.coords.xy)[0]), init_spirals_pos[1])) ## ADD EVERYTHING cell = Cell('Spiralone_LiNb') # cell.add(convert_to_gdscad(devices)) for i, device in enumerate(devices): print('adding test', i) cell.add_to_layer(wg_layer, device.get_shapely_object()) device_boxes = device.get_box() if isinstance(device_boxes, list): for this_box in device.get_box(): cell.add_to_layer(box_layer, this_box) else: cell.add_to_layer(box_layer, device_boxes) cell.add_to_layer(comment_layer, device.get_comments().get_shapely_object()) cell.add_to_layer(marker_layer_1, device.get_markers()) cell.add_to_layer(marker_layer_2, device.get_markers_copy()) cell.add_to_layer(marker_protection_layer, device.get_markers_protection()) # print('width: {:.0f}\nheight: {:.0f}'.format(*(cell.bounding_box[1] - cell.bounding_box[0]))) print('starting device saving') cell.save('tests_DC_Grating_Delays.gds') print('done saving')
self.add_dlw_data('taper', str(label), {'origin': taper_port.origin.tolist(), 'angle': port.angle, 'starting_width': port.width, 'taper_length': taper_length}) if with_markers: for i, (v, l) in enumerate(itertools.product((-20, 20), (taper_length, 0))): self.add_dlw_marker(str(label) + '-' + str(i), layer, port.parallel_offset(v).longitudinal_offset(l).origin) if __name__ == '__main__': from gdshelpers.parts.port import Port from gdshelpers.parts.waveguide import Waveguide from gdshelpers.geometry.chip import Cell # Create a cell-like object that offers a save output command '.save' which creates the .gds or .oas file by using # gdsCAD,gdspy or fatamorgana device_cell = Cell('my_cell') # Create a port to connect waveguide structures to port = Port(origin=(0, 0), width=1, angle=0) waveguide = Waveguide.make_at_port(port) for i in range(9): waveguide.add_bend(angle=np.pi, radius=60 + i * 40) # Add direct laser writing taper and alignment marker for postprocessing with a dlw printer to the cell-like object. # The cell dlw files will be saved with the cell. device_cell.add_dlw_taper_at_port('A0', 2, port.inverted_direction, 30) device_cell.add_dlw_taper_at_port('A1', 2, waveguide.current_port, 30) device_cell.add_to_layer(1, waveguide) device_cell.show() # Creates the output file by using gdspy,gdsCAD or fatamorgana. To use the implemented parallell processing, set # parallel=True. device_cell.save(name='my_design', parallel=True, library='gdspy')
y_dist = 1760 y_steps = 275 for col, MZ_length in enumerate(MZIlen_list): temp_cell = MZI_active( coupler_sep, coupler_length, MZ_length, electrodes_sep, id_to_alphanumeric(row, col), exp_wg_width=wg_Expwidth, grating_coupler_period=std_coupler_params['grating_period']) tests_cell.add_cell(temp_cell, origin=(OriginTests[0] + (col % 2) * x_dist, OriginTests[1] + int(col / 2.) * y_dist + (col % 2) * int(col / 2.) * y_steps), angle=np.pi) ############################################################## ### ADD ALL CELLS AND EXPORT FULL GDS global_cell = Cell('LiNb01_MunsterNBI') global_cell.add_cell(left4x4_cell, origin=(0, 0)) global_cell.add_cell(right4x4_cell, origin=(0, 0)) global_cell.add_cell(timebin_cell, origin=(0, 0)) global_cell.add_cell(demux_cell, origin=(0, 0)) global_cell.add_cell(tests_cell, origin=(0, 0)) global_cell.add_cell(global_markers_cell, origin=(0, 0)) global_cell.save('LiNb01_MunsterNBI_v5_500nm.gds')
left_wg.add_straight_segment(l_wg) right_wg = Waveguide.make_at_port(left_wg.port) right_wg.add_straight_segment(l_wg) layout = positive_resist.convert_to_positive_resist([left_wg, right_wg], gap, outer_resolution=1e-3) outer_corners = [origin, (origin[0], origin[1]+2*gap), (origin[0]-2*gap, origin[1]+2*gap), (origin[0]-2*gap, origin[1]-2*gap), (origin[0], origin[1]-2*gap)] polygon1 = Polygon(outer_corners) origin = (origin[0] + 2*l_wg + 2*gap, origin[1]) outer_corners = [origin, (origin[0], origin[1]+2*gap), (origin[0]-2*gap, origin[1]+2*gap), (origin[0]-2*gap, origin[1]-2*gap), (origin[0], origin[1]-2*gap)] polygon2 = Polygon(outer_corners) polygon = polygon1.union(polygon2) layout_fixed = layout.difference(polygon) cell.add_to_layer(1, layout_fixed) cell = Cell('CELL') spiral_with_coupler(cell, origin=(0,0), gap=3, num=10) spiral_with_coupler(cell, origin=(0,200), gap=3, num=15) # spiral_with_coupler(cell, origin=(0,850), gap=3, num=64) coupler_coupler((0, -150)) # coupler_coupler((0, -300)) # _example() cell.save("./layout/Spiral_with_coupler.gds") # cell.start_viewer()
starting_point = second_x_middle / 2 - gc_pitch * 3.5 gc_y = 100 grating_coupler_positions = [(starting_point + idx * gc_pitch, gc_y) for idx in range(8)] _ = interferometer_and_fiber_array(cell=cell, inports=device_inports, gc_positions=grating_coupler_positions, electrode_length=1250, coupler_sep=0.4, coupler_length=30, sm_wg_width=wg_width, wg_layer=9, wf_layer=100, electrode_layer=10, electrode_wf_layer=102, electrode_contact_pad_coordinates=[], second_x_middle=second_x_middle, total_bounds=(np.inf, np.inf, -np.inf, -np.inf), mm_wg_width=1, mm_taper_length=30, contact_pad_dims=[250, 250], contact_pad_sep=160, connector_start_y=7120, connector_probe_pitch=150, wg_sep=wg_sep, electrode_wg_sep=electrode_wg_sep) cell.save('4x4_3rdgen_150_1.gds')
cell.add_to_layer(1, layout_fixed) cell = Cell('CELL') # spiral_with_coupler(cell, origin=(0,0), gap=3, num=10) # spiral_with_coupler(cell, origin=(0,200), gap=3, num=15) # spiral_with_coupler(cell, origin=(0,850), gap=3, num=64) # coupler_coupler((0, -150)) # coupler_coupler((0, -300)) w_wg = 0.5 w_GC = 10 l_taper = 500 l_wg = 100 l_GC = 100 origin = 0 taperVector = [(origin, -w_wg / 2), (origin, w_wg / 2), (origin + l_taper, w_GC / 2), (origin + l_taper + l_GC, w_GC / 2), (origin + 2 * l_taper + l_GC, w_wg / 2), (origin + 2 * l_taper + l_GC, -w_wg / 2), (origin + l_taper + l_GC, -w_GC / 2), (origin + l_taper, -w_GC / 2), (origin, -w_wg / 2)] taperGCTaper = Polygon(taperVector) taperGCTaper2 = positive_resist.convert_to_positive_resist( [taperGCTaper], 3, outer_resolution=1e-3) cell.add_to_layer(1, taperGCTaper2) # _example() cell.save("./taper.gds") # cell.start_viewer()