Skip to content

Commit

Permalink
fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
alibrahimzada committed Jan 13, 2025
1 parent f695d0c commit 63ca9df
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
93 changes: 75 additions & 18 deletions src/static_analysis/create_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,80 @@
import keyword


def topological_sort(graph: list[tuple[str, str]]) -> list[str]:
"""
Provides a topological sort of the graph.
Args:
graph: A list of tuples where each tuple contains two strings representing the source and target nodes.
Returns:
A list of strings representing the nodes in topological order.
"""
# create a dictionary with the nodes as keys and their dependencies as values
graph_dict = {}
for edge in graph:
if edge[0] not in graph_dict:
graph_dict[edge[0]] = []
graph_dict[edge[0]].append(edge[1])

# create a dictionary with the nodes as keys and their indegree as values
indegree_dict = {}
for edge in graph:
if edge[1] not in indegree_dict:
indegree_dict[edge[1]] = 0
if edge[0] not in indegree_dict:
indegree_dict[edge[0]] = 0
indegree_dict[edge[1]] += 1

# create a list of nodes with indegree 0
zero_indegree = [node for node in indegree_dict if indegree_dict[node] == 0]

# create a list to store the sorted nodes
sorted_nodes = []

# loop over the nodes with indegree 0
while zero_indegree:
node = zero_indegree.pop()
sorted_nodes.append(node)

# loop over the nodes that depend on the current node
if node in graph_dict:
for dependent_node in graph_dict[node]:
indegree_dict[dependent_node] -= 1
if indegree_dict[dependent_node] == 0:
zero_indegree.append(dependent_node)

return sorted_nodes


def get_class_order(schema_data):
"""
Get the order of classes in the schema based on inheritance.
"""
dependency_graph = set() # set of (dependent, dependency) pairs

for class_ in schema_data['classes']:
if schema_data['classes'][class_]['extends']:
if schema_data['classes'][class_]['extends'][0] in schema_data['classes']:
dependency_graph.add((class_, schema_data['classes'][class_]['extends'][0]))

if schema_data['classes'][class_]['implements']:
for interface in schema_data['classes'][class_]['implements']:
if interface in schema_data['classes']:
dependency_graph.add((class_, interface))

if schema_data['classes'][class_]['nested_inside']:
dependency_graph.add((class_, schema_data['classes'][class_]['nested_inside']))

class_list = topological_sort(dependency_graph)[::-1]

# check for any classes that were not included in the dependency graph
class_list += [clz for clz in schema_data['classes'] if clz not in class_list]

return class_list


def split_with_nested_commas(s):
result = []
stack = []
Expand Down Expand Up @@ -154,24 +228,7 @@ def main(args):
target_schema = schema.copy()
python_imports = []
python_imports.append('from __future__ import annotations')
class_order = []
while len(class_order) != len(schema['classes']):
for class_ in schema['classes']:
if class_ in class_order:
continue

if not set(schema['classes'][class_]['extends']).issubset(set(class_order)) and all([x in schema['classes'].keys() for x in schema['classes'][class_]['extends']]):
continue

if not set(schema['classes'][class_]['implements']).issubset(set(class_order)) and all([x in schema['classes'].keys() for x in schema['classes'][class_]['implements']]):
continue

if schema['classes'][class_]['nests'] == []:
class_order.append(class_)
continue

if all([x in class_order for x in schema['classes'][class_]['nests']]):
class_order.append(class_)
class_order = get_class_order(schema)

class_dependencies = []
for class_ in class_order:
Expand Down
2 changes: 1 addition & 1 deletion src/translation/compositional_translation_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ def translate(fragment, args, processed_fragments, budget={}, feedback=None, rec

model_info = {
'deepseek-coder-33b-instruct': {'total': 16384, 'max_new_tokens': 4096, 'model_id': 'deepseek-ai/deepseek-coder-33b-instruct'},
'llama3.3': {'total': 128000, 'max_new_tokens': 8196, 'model_id': 'llama3.3'},
'gpt-4o-2024-11-20': {'total': 128000, 'max_new_tokens': 16384, 'model_id': 'gpt-4o-2024-11-20'},
'llama-3-3-70b-instruct': {'total': 128000, 'max_new_tokens': 8196, 'model_id': 'llama3.3'},
'Qwen2.5-Coder-32B-Instruct': {'total': 131072, 'max_new_tokens': 8196, 'model_id': 'krith/qwen2.5-coder-32b-instruct:IQ4_XS'}
}

Expand Down
2 changes: 1 addition & 1 deletion src/translation/prompt_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, is_feedback, args, fragment_details, feedback='', use_icl_poo
self.meta_data = {
'deepseek-coder-33b-instruct-persona': 'You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.',
'gpt-4o-2024-11-20-persona': '',
'llama-3-3-70b-instruct-persona': '',
'llama3.3-persona': '',
'Qwen2.5-Coder-32B-Instruct-persona': 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.',
'icl': {
'field': 'Java code:\n```\npublic class Calculator {\n public int x;\n}\n```\n\nPartial Python translation:\n```\nclass Calculator:\n x: int = \n```\n\nPython field translation:\n```\n x: int = 0\n```',
Expand Down

0 comments on commit 63ca9df

Please sign in to comment.