Spaces:
Sleeping
Sleeping
File size: 1,420 Bytes
8b66d81 760fb86 8b66d81 760fb86 8b66d81 760fb86 8b66d81 760fb86 8b66d81 0ecba14 8b66d81 760fb86 8b66d81 760fb86 8b66d81 760fb86 8b66d81 760fb86 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
"""
FastAPI application for the Quantum Circuit Optimization Environment.
"""
import os
import functools
try:
from openenv.core.env_server.http_server import create_app
except Exception as e:
raise ImportError(
"openenv is required. Install dependencies with 'uv sync'"
) from e
from quantum_openenv_env.models import QuantumAction, QuantumObservation
from quantum_openenv_env.server.quantum_openenv_env_environment import QuantumCircuitOptimizationEnvironment
# Read QUANTUM_TASK from environment variable (default: "random")
# When inference.py starts a container with env_vars={"QUANTUM_TASK": "easy"},
# this ensures the environment is instantiated with the correct task.
_task = os.getenv("QUANTUM_TASK", "random")
# Create a factory function (not a bare class) so we can pass task= argument
def _env_factory() -> QuantumCircuitOptimizationEnvironment:
return QuantumCircuitOptimizationEnvironment(task=_task)
app = create_app(
_env_factory,
QuantumAction,
QuantumObservation,
env_name="quantum_openenv_env",
max_concurrent_envs=100,
)
def main():
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
if __name__ == "__main__":
main() |