Public API Tour#

Source: examples/catalog/public_api_tour.py

Introduction#

Tour the curated public API through concrete packaged objects.

Technical Implementation#

This page is generated from the top-of-file module docstring and the example source code. The full script is included below for direct inspection.

  1from __future__ import annotations
  2
  3import numpy
  4
  5import design_research_problems as derp
  6
  7
  8def main() -> None:
  9    """Load one example from each family and print typed public-API touchpoints."""
 10    registry = derp.ProblemRegistry()
 11    catalog: derp.IdeationCatalog = derp.get_ideation_catalog()
 12    summaries: tuple[derp.ProblemCatalogSummary, ...] = derp.search_problem_summaries(text="battery")[:2]
 13    integration_module = derp.integration
 14
 15    text_problem = derp.get_problem("ideation_peanut_shelling_fu_cagan_kotovsky_2010")
 16    typed_text_problem = derp.get_problem_as(
 17        "ideation_peanut_shelling_fu_cagan_kotovsky_2010",
 18        derp.TextProblem,
 19    )
 20    decision_problem = derp.get_problem_as(
 21        "decision_laptop_design_profit_maximization",
 22        derp.DecisionProblem,
 23    )
 24    optimization_problem = derp.get_problem_as("gmpb_default_dynamic_min", derp.OptimizationProblem)
 25    grammar_problem = derp.get_problem_as("iot_home_cooling_system_design", derp.GrammarProblem)
 26    mcp_problem = derp.get_problem_as("mcp_build123d_parametric_mounting_bracket", derp.MCPProblem)
 27
 28    loaded_problems: tuple[derp.Problem, ...] = (
 29        text_problem,
 30        typed_text_problem,
 31        decision_problem,
 32        optimization_problem,
 33        grammar_problem,
 34        mcp_problem,
 35    )
 36    computable_count = sum(isinstance(problem, derp.ComputableProblem) for problem in loaded_problems)
 37
 38    metadata: derp.ProblemMetadata = typed_text_problem.metadata
 39    taxonomy: derp.ProblemTaxonomy = metadata.taxonomy
 40    citations: tuple[derp.Citation, ...] = metadata.citations
 41    assets: tuple[derp.ProblemAsset, ...] = metadata.assets
 42
 43    kinds = {listed_metadata.kind for listed_metadata in registry.list()}
 44    assert derp.ProblemKind.TEXT in kinds
 45    assert derp.ProblemKind.DECISION in kinds
 46    assert derp.ProblemKind.OPTIMIZATION in kinds
 47    assert derp.ProblemKind.GRAMMAR in kinds
 48    assert derp.ProblemKind.MCP in kinds
 49
 50    best_decision: derp.DecisionEvaluation = decision_problem.best_evaluation()
 51
 52    candidate = numpy.zeros(optimization_problem.bounds.lb.shape, dtype=float)
 53    optimization_evaluation: derp.OptimizationEvaluation = optimization_problem.evaluate(candidate)
 54
 55    transition: derp.GrammarTransition = grammar_problem.enumerate_transitions(grammar_problem.initial_state())[0]
 56
 57    prompt: derp.IdeationPromptRecord = catalog.list_prompts()[0]
 58    variant: derp.IdeationPromptVariant = catalog.get_variant(prompt.variant_ids[0])
 59    family: derp.IdeationPromptFamily = catalog.get_family(prompt.family_id)
 60    study: derp.IdeationStudy = catalog.list_studies()[0]
 61    evidence_tier: derp.EvidenceTier = prompt.evidence_tier
 62
 63    try:
 64        derp.get_problem_as(
 65            "ideation_peanut_shelling_fu_cagan_kotovsky_2010",
 66            derp.OptimizationProblem,
 67        )
 68    except (TypeError, derp.ProblemEvaluationError) as exc:
 69        mismatch_error = type(exc).__name__
 70    else:
 71        mismatch_error = "no-error"
 72
 73    handled_optional_error = derp.MissingOptionalDependencyError.__name__
 74
 75    print("problem-count", len(derp.list_problems()))
 76    print("package-version", derp.__version__)
 77    print("search-results", [summary.problem_id for summary in summaries])
 78    print("integration-module", integration_module.__name__)
 79    print("kind-count", len(kinds), sorted(kind.value for kind in kinds))
 80    print("loaded-types", [type(problem).__name__ for problem in loaded_problems])
 81    print("computable-count", computable_count)
 82    print("text-kind", metadata.problem_id, metadata.kind.value)
 83    print("taxonomy-tags", len(taxonomy.tags))
 84    print("citation-year", citations[0].year)
 85    print("asset-count", len(assets))
 86    print("decision-best", round(best_decision.objective_value, 6), best_decision.candidate_label)
 87    print(
 88        "optimization-eval",
 89        optimization_evaluation.is_feasible,
 90        round(optimization_evaluation.objective_value, 6),
 91    )
 92    print("grammar-rule", transition.rule_name)
 93    print(
 94        "evaluation-types",
 95        type(best_decision).__name__,
 96        type(optimization_evaluation).__name__,
 97        type(transition).__name__,
 98    )
 99    print("mcp-problem", mcp_problem.metadata.problem_id)
100    print(
101        "ideation-types",
102        type(prompt).__name__,
103        type(variant).__name__,
104        type(family).__name__,
105        type(study).__name__,
106        evidence_tier.value,
107    )
108    print(
109        "primary-verbatim-prompts",
110        len(
111            catalog.search_prompts(
112                evidence_tiers=(derp.EvidenceTier.PRIMARY_VERBATIM,),
113                status="complete",
114            )
115        ),
116    )
117    print("handled-errors", handled_optional_error, mismatch_error)
118
119
120if __name__ == "__main__":
121    main()

Expected Results#

Run Command

PYTHONPATH=src python3 examples/catalog/public_api_tour.py

Run the command shown below from repository root. Output should summarize the problem setup, a baseline solution, or diagnostic values relevant to this example.