Skip to content

Commit

Permalink
ran ruff check and ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruviyer committed Dec 26, 2024
1 parent 3f6c8c3 commit 7c085b0
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 91 deletions.
277 changes: 226 additions & 51 deletions examples/op_examples/agg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pandas as pd
import time

import pandas as pd

import lotus
from lotus.models import LM


def main():
lm = LM(model="gpt-4o-mini")

Expand All @@ -15,56 +17,228 @@ def main():

data = {
"Course Name": [
"Probability and Random Processes", "Optimization Methods in Engineering",
"Digital Design and Integrated Circuits", "Computer Security", "Cooking",
"Food Sciences", "Machine Learning", "Data Structures and Algorithms",
"Quantum Mechanics", "Organic Chemistry", "Artificial Intelligence", "Robotics",
"Thermodynamics", "Fluid Mechanics", "Molecular Biology", "Genetics",
"Astrophysics", "Neuroscience", "Microeconomics", "Macroeconomics",
"Linear Algebra", "Calculus", "Statistics", "Differential Equations",
"Discrete Mathematics", "Number Theory", "Graph Theory", "Topology",
"Complex Analysis", "Real Analysis", "Abstract Algebra", "Numerical Methods",
"Cryptography", "Network Security", "Operating Systems", "Databases",
"Computer Networks", "Software Engineering", "Compilers", "Computer Architecture",
"Parallel Computing", "Distributed Systems", "Cloud Computing", "Big Data Analytics",
"Natural Language Processing", "Computer Vision", "Reinforcement Learning",
"Deep Learning", "Bioinformatics", "Computational Biology", "Systems Biology",
"Biochemistry", "Physical Chemistry", "Inorganic Chemistry", "Analytical Chemistry",
"Environmental Chemistry", "Materials Science", "Nanotechnology", "Optics",
"Electromagnetism", "Nuclear Physics", "Particle Physics", "Cosmology",
"Planetary Science", "Geophysics", "Atmospheric Science", "Oceanography",
"Ecology", "Evolutionary Biology", "Botany", "Zoology", "Microbiology",
"Immunology", "Virology", "Pharmacology", "Physiology", "Anatomy",
"Neurobiology", "Cognitive Science", "Psychology", "Sociology", "Anthropology",
"Archaeology", "Linguistics", "Philosophy", "Ethics", "Logic",
"Political Science", "International Relations", "Public Policy", "Economics",
"Finance", "Accounting", "Marketing", "Management", "Entrepreneurship",
"Law", "Criminal Justice", "Human Rights", "Environmental Studies",
"Sustainability", "Urban Planning", "Architecture", "Civil Engineering",
"Mechanical Engineering", "Electrical Engineering", "Chemical Engineering",
"Aerospace Engineering", "Biomedical Engineering", "Environmental Engineering"
"Probability and Random Processes",
"Optimization Methods in Engineering",
"Digital Design and Integrated Circuits",
"Computer Security",
"Cooking",
"Food Sciences",
"Machine Learning",
"Data Structures and Algorithms",
"Quantum Mechanics",
"Organic Chemistry",
"Artificial Intelligence",
"Robotics",
"Thermodynamics",
"Fluid Mechanics",
"Molecular Biology",
"Genetics",
"Astrophysics",
"Neuroscience",
"Microeconomics",
"Macroeconomics",
"Linear Algebra",
"Calculus",
"Statistics",
"Differential Equations",
"Discrete Mathematics",
"Number Theory",
"Graph Theory",
"Topology",
"Complex Analysis",
"Real Analysis",
"Abstract Algebra",
"Numerical Methods",
"Cryptography",
"Network Security",
"Operating Systems",
"Databases",
"Computer Networks",
"Software Engineering",
"Compilers",
"Computer Architecture",
"Parallel Computing",
"Distributed Systems",
"Cloud Computing",
"Big Data Analytics",
"Natural Language Processing",
"Computer Vision",
"Reinforcement Learning",
"Deep Learning",
"Bioinformatics",
"Computational Biology",
"Systems Biology",
"Biochemistry",
"Physical Chemistry",
"Inorganic Chemistry",
"Analytical Chemistry",
"Environmental Chemistry",
"Materials Science",
"Nanotechnology",
"Optics",
"Electromagnetism",
"Nuclear Physics",
"Particle Physics",
"Cosmology",
"Planetary Science",
"Geophysics",
"Atmospheric Science",
"Oceanography",
"Ecology",
"Evolutionary Biology",
"Botany",
"Zoology",
"Microbiology",
"Immunology",
"Virology",
"Pharmacology",
"Physiology",
"Anatomy",
"Neurobiology",
"Cognitive Science",
"Psychology",
"Sociology",
"Anthropology",
"Archaeology",
"Linguistics",
"Philosophy",
"Ethics",
"Logic",
"Political Science",
"International Relations",
"Public Policy",
"Economics",
"Finance",
"Accounting",
"Marketing",
"Management",
"Entrepreneurship",
"Law",
"Criminal Justice",
"Human Rights",
"Environmental Studies",
"Sustainability",
"Urban Planning",
"Architecture",
"Civil Engineering",
"Mechanical Engineering",
"Electrical Engineering",
"Chemical Engineering",
"Aerospace Engineering",
"Biomedical Engineering",
"Environmental Engineering",
],
"Grade Level": [
"High School", "Graduate", "Graduate", "High School", "Undergraduate",
"Undergraduate", "High School", "Undergraduate", "High School", "Undergraduate",
"High School", "Graduate", "Undergraduate", "Undergraduate", "Graduate",
"Undergraduate", "Graduate", "Graduate", "Undergraduate", "Undergraduate",
"Undergraduate", "Undergraduate", "High School", "High School", "Undergraduate",
"Graduate", "Graduate", "Graduate", "High School", "Graduate", "Graduate", "Graduate",
"Graduate", "High School", "Undergraduate", "High School", "Undergraduate",
"Undergraduate", "Graduate", "Undergraduate", "Undergraduate", "Graduate", "Graduate",
"Graduate", "Graduate", "Graduate", "Graduate", "Graduate", "Graduate", "Graduate",
"Undergraduate", "Graduate", "Undergraduate", "High School", "Graduate", "Graduate",
"Graduate", "High School", "Graduate", "High School", "Graduate", "Graduate",
"Graduate", "Graduate", "Graduate", "Graduate", "Graduate", "Graduate",
"High School", "High School", "High School", "Undergraduate", "Graduate",
"Graduate", "Graduate", "High School", "Undergraduate", "Undergraduate",
"Graduate", "Graduate", "Undergraduate", "Undergraduate", "Undergraduate",
"High School", "High School", "Graduate", "Graduate", "High School", "Graduate",
"Graduate", "Graduate", "Undergraduate", "Undergraduate", "Undergraduate", "Undergraduate",
"High School", "High School", "Graduate", "Undergraduate", "Undergraduate", "Undergraduate",
"Undergraduate", "Undergraduate", "Undergraduate", "Graduate", "Graduate",
"Graduate", "Graduate", "Graduate", "Graduate"
"High School",
"Graduate",
"Graduate",
"High School",
"Undergraduate",
"Undergraduate",
"High School",
"Undergraduate",
"High School",
"Undergraduate",
"High School",
"Graduate",
"Undergraduate",
"Undergraduate",
"Graduate",
"Undergraduate",
"Graduate",
"Graduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"High School",
"High School",
"Undergraduate",
"Graduate",
"Graduate",
"Graduate",
"High School",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"High School",
"Undergraduate",
"High School",
"Undergraduate",
"Undergraduate",
"Graduate",
"Undergraduate",
"Undergraduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Undergraduate",
"Graduate",
"Undergraduate",
"High School",
"Graduate",
"Graduate",
"Graduate",
"High School",
"Graduate",
"High School",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"High School",
"High School",
"High School",
"Undergraduate",
"Graduate",
"Graduate",
"Graduate",
"High School",
"Undergraduate",
"Undergraduate",
"Graduate",
"Graduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"High School",
"High School",
"Graduate",
"Graduate",
"High School",
"Graduate",
"Graduate",
"Graduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"High School",
"High School",
"Graduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"Undergraduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
"Graduate",
],
}

Expand All @@ -75,5 +249,6 @@ def main():
print(df._output[0])
print(f"Total execution time: {end_time - start_time:.2f} seconds")

if __name__ == '__main__':
main()

if __name__ == "__main__":
main()
49 changes: 36 additions & 13 deletions examples/op_examples/top_k.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,67 @@
import pandas as pd
import time

import pandas as pd

import lotus
from lotus.models import LM


def main():
lm = LM(model="gpt-4o-mini")

lotus.settings.configure(lm=lm)
lotus.settings.configure(enable_multithreading=True)

data = {
"Department": ["Math", "Physics", "Computer Science", "Biology"] * 7,
"Course Name": [
"Calculus", "Quantum Mechanics", "Data Structures", "Genetics",
"Linear Algebra", "Thermodynamics", "Algorithms", "Ecology",
"Statistics", "Optics", "Machine Learning", "Molecular Biology",
"Number Theory", "Relativity", "Computer Networks", "Evolutionary Biology",
"Differential Equations", "Particle Physics", "Operating Systems", "Biochemistry",
"Complex Analysis", "Fluid Dynamics", "Artificial Intelligence", "Microbiology",
"Topology", "Astrophysics", "Cybersecurity", "Immunology"
]
"Calculus",
"Quantum Mechanics",
"Data Structures",
"Genetics",
"Linear Algebra",
"Thermodynamics",
"Algorithms",
"Ecology",
"Statistics",
"Optics",
"Machine Learning",
"Molecular Biology",
"Number Theory",
"Relativity",
"Computer Networks",
"Evolutionary Biology",
"Differential Equations",
"Particle Physics",
"Operating Systems",
"Biochemistry",
"Complex Analysis",
"Fluid Dynamics",
"Artificial Intelligence",
"Microbiology",
"Topology",
"Astrophysics",
"Cybersecurity",
"Immunology",
],
}

df = pd.DataFrame(data)

for method in ["quick", "heap", "naive"]:

start_time = time.time()
sorted_df, stats = df.sem_topk(
"Which {Course Name} is the most challenging?",
K=2,
method=method,
return_stats=True,
group_by=["Department"]
group_by=["Department"],
)
end_time = time.time()
print(sorted_df)
print(stats)
print(f"Total execution time: {end_time - start_time:.2f} seconds")

if __name__ == '__main__':

if __name__ == "__main__":
main()
Loading

0 comments on commit 7c085b0

Please sign in to comment.