Spaces:
Sleeping
Sleeping
aishani-s20 commited on
Commit ·
805db5e
1
Parent(s): a404079
added graders file
Browse files- __init__.py +4 -0
- graders.py +44 -0
- openenv.yaml +4 -4
- server/__init__.py +2 -6
- server/quantum_openenv_env_environment.py +16 -29
__init__.py
CHANGED
|
@@ -8,9 +8,13 @@
|
|
| 8 |
|
| 9 |
from .client import QuantumOpenenvEnv
|
| 10 |
from .models import QuantumAction, QuantumObservation
|
|
|
|
| 11 |
|
| 12 |
__all__ = [
|
| 13 |
"QuantumAction",
|
| 14 |
"QuantumObservation",
|
| 15 |
"QuantumOpenenvEnv",
|
|
|
|
|
|
|
|
|
|
| 16 |
]
|
|
|
|
| 8 |
|
| 9 |
from .client import QuantumOpenenvEnv
|
| 10 |
from .models import QuantumAction, QuantumObservation
|
| 11 |
+
from .graders import grade_easy, grade_medium, grade_hard
|
| 12 |
|
| 13 |
__all__ = [
|
| 14 |
"QuantumAction",
|
| 15 |
"QuantumObservation",
|
| 16 |
"QuantumOpenenvEnv",
|
| 17 |
+
"grade_easy",
|
| 18 |
+
"grade_medium",
|
| 19 |
+
"grade_hard",
|
| 20 |
]
|
graders.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the BSD-style license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
Standalone graders for the Quantum Circuit Optimization Environment.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from .models import QuantumObservation
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def grade_easy(observation: QuantumObservation) -> float:
|
| 15 |
+
"""Independent grader for Easy Task."""
|
| 16 |
+
final_count = observation.gate_count
|
| 17 |
+
metadata = observation.metadata or {}
|
| 18 |
+
initial_count = metadata.get("initial_count", final_count)
|
| 19 |
+
if initial_count == 0:
|
| 20 |
+
return 1.0
|
| 21 |
+
compression_ratio = (initial_count - final_count) / initial_count
|
| 22 |
+
return max(0.0, min(1.0, compression_ratio))
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def grade_medium(observation: QuantumObservation) -> float:
|
| 26 |
+
"""Independent grader for Medium Task."""
|
| 27 |
+
final_count = observation.gate_count
|
| 28 |
+
metadata = observation.metadata or {}
|
| 29 |
+
initial_count = metadata.get("initial_count", final_count)
|
| 30 |
+
if initial_count == 0:
|
| 31 |
+
return 1.0
|
| 32 |
+
compression_ratio = (initial_count - final_count) / initial_count
|
| 33 |
+
return max(0.0, min(1.0, compression_ratio))
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def grade_hard(observation: QuantumObservation) -> float:
|
| 37 |
+
"""Independent grader for Hard Task."""
|
| 38 |
+
final_count = observation.gate_count
|
| 39 |
+
metadata = observation.metadata or {}
|
| 40 |
+
initial_count = metadata.get("initial_count", final_count)
|
| 41 |
+
if initial_count == 0:
|
| 42 |
+
return 1.0
|
| 43 |
+
compression_ratio = (initial_count - final_count) / initial_count
|
| 44 |
+
return max(0.0, min(1.0, compression_ratio))
|
openenv.yaml
CHANGED
|
@@ -1,22 +1,22 @@
|
|
| 1 |
name: "quantum_circuit_optimizer"
|
| 2 |
version: "0.1.0"
|
| 3 |
description: "An OpenEnv environment for optimizing multi-qubit quantum circuits using RL/LLM agents."
|
| 4 |
-
entrypoint: "server.quantum_openenv_env_environment:QuantumCircuitOptimizationEnvironment"
|
| 5 |
tasks:
|
| 6 |
- id: "easy"
|
| 7 |
name: "Easy Circuit Optimization"
|
| 8 |
description: "2 qubits, single-qubit gates only."
|
| 9 |
difficulty: "easy"
|
| 10 |
-
grader: "server.quantum_openenv_env_environment:grade_easy"
|
| 11 |
|
| 12 |
- id: "medium"
|
| 13 |
name: "Medium Circuit Optimization"
|
| 14 |
description: "4 qubits with basic CNOT/SWAP entanglement."
|
| 15 |
difficulty: "medium"
|
| 16 |
-
grader: "server.quantum_openenv_env_environment:grade_medium"
|
| 17 |
|
| 18 |
- id: "hard"
|
| 19 |
name: "Hard Circuit Optimization"
|
| 20 |
description: "6 qubits with deep entanglement and complex blockades."
|
| 21 |
difficulty: "hard"
|
| 22 |
-
grader: "server.quantum_openenv_env_environment:grade_hard"
|
|
|
|
| 1 |
name: "quantum_circuit_optimizer"
|
| 2 |
version: "0.1.0"
|
| 3 |
description: "An OpenEnv environment for optimizing multi-qubit quantum circuits using RL/LLM agents."
|
| 4 |
+
entrypoint: "quantum_openenv_env.server.quantum_openenv_env_environment:QuantumCircuitOptimizationEnvironment"
|
| 5 |
tasks:
|
| 6 |
- id: "easy"
|
| 7 |
name: "Easy Circuit Optimization"
|
| 8 |
description: "2 qubits, single-qubit gates only."
|
| 9 |
difficulty: "easy"
|
| 10 |
+
grader: "quantum_openenv_env.server.quantum_openenv_env_environment:QuantumCircuitOptimizationEnvironment.grade_easy"
|
| 11 |
|
| 12 |
- id: "medium"
|
| 13 |
name: "Medium Circuit Optimization"
|
| 14 |
description: "4 qubits with basic CNOT/SWAP entanglement."
|
| 15 |
difficulty: "medium"
|
| 16 |
+
grader: "quantum_openenv_env.server.quantum_openenv_env_environment:QuantumCircuitOptimizationEnvironment.grade_medium"
|
| 17 |
|
| 18 |
- id: "hard"
|
| 19 |
name: "Hard Circuit Optimization"
|
| 20 |
description: "6 qubits with deep entanglement and complex blockades."
|
| 21 |
difficulty: "hard"
|
| 22 |
+
grader: "quantum_openenv_env.server.quantum_openenv_env_environment:QuantumCircuitOptimizationEnvironment.grade_hard"
|
server/__init__.py
CHANGED
|
@@ -6,12 +6,8 @@
|
|
| 6 |
|
| 7 |
"""Quantum Openenv Env environment server components."""
|
| 8 |
|
| 9 |
-
from .quantum_openenv_env_environment import
|
| 10 |
-
|
| 11 |
-
grade_easy,
|
| 12 |
-
grade_medium,
|
| 13 |
-
grade_hard,
|
| 14 |
-
)
|
| 15 |
|
| 16 |
__all__ = [
|
| 17 |
"QuantumCircuitOptimizationEnvironment",
|
|
|
|
| 6 |
|
| 7 |
"""Quantum Openenv Env environment server components."""
|
| 8 |
|
| 9 |
+
from .quantum_openenv_env_environment import QuantumCircuitOptimizationEnvironment
|
| 10 |
+
from quantum_openenv_env.graders import grade_easy, grade_medium, grade_hard
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
__all__ = [
|
| 13 |
"QuantumCircuitOptimizationEnvironment",
|
server/quantum_openenv_env_environment.py
CHANGED
|
@@ -80,37 +80,11 @@ TASK_CONFIGS = {
|
|
| 80 |
# Graders
|
| 81 |
# ============================================================================
|
| 82 |
|
| 83 |
-
|
| 84 |
-
"""Independent grader for Easy Task."""
|
| 85 |
-
final_count = observation.gate_count
|
| 86 |
-
metadata = observation.metadata or {}
|
| 87 |
-
initial_count = metadata.get("initial_count", final_count)
|
| 88 |
-
if initial_count == 0:
|
| 89 |
-
return 1.0
|
| 90 |
-
compression_ratio = (initial_count - final_count) / initial_count
|
| 91 |
-
return max(0.0, min(1.0, compression_ratio))
|
| 92 |
-
|
| 93 |
-
def grade_medium(observation: QuantumObservation) -> float:
|
| 94 |
-
"""Independent grader for Medium Task."""
|
| 95 |
-
final_count = observation.gate_count
|
| 96 |
-
metadata = observation.metadata or {}
|
| 97 |
-
initial_count = metadata.get("initial_count", final_count)
|
| 98 |
-
if initial_count == 0:
|
| 99 |
-
return 1.0
|
| 100 |
-
compression_ratio = (initial_count - final_count) / initial_count
|
| 101 |
-
return max(0.0, min(1.0, compression_ratio))
|
| 102 |
-
|
| 103 |
-
def grade_hard(observation: QuantumObservation) -> float:
|
| 104 |
-
"""Independent grader for Hard Task."""
|
| 105 |
-
final_count = observation.gate_count
|
| 106 |
-
metadata = observation.metadata or {}
|
| 107 |
-
initial_count = metadata.get("initial_count", final_count)
|
| 108 |
-
if initial_count == 0:
|
| 109 |
-
return 1.0
|
| 110 |
-
compression_ratio = (initial_count - final_count) / initial_count
|
| 111 |
-
return max(0.0, min(1.0, compression_ratio))
|
| 112 |
|
| 113 |
# Exporting for inference.py and Hackathon Platform
|
|
|
|
|
|
|
| 114 |
GRADERS = {
|
| 115 |
"easy": grade_easy,
|
| 116 |
"medium": grade_medium,
|
|
@@ -258,6 +232,19 @@ class QuantumCircuitOptimizationEnvironment(Environment):
|
|
| 258 |
|
| 259 |
return self._build_observation(reward, action_result)
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
def _build_observation(self, reward: float, action_result: str) -> QuantumObservation:
|
| 262 |
max_steps_reached = self._state.step_count >= 150
|
| 263 |
is_done = max_steps_reached or self._is_circuit_dead_end()
|
|
|
|
| 80 |
# Graders
|
| 81 |
# ============================================================================
|
| 82 |
|
| 83 |
+
# Graders are now defined in ../graders.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
# Exporting for inference.py and Hackathon Platform
|
| 86 |
+
from quantum_openenv_env.graders import grade_easy, grade_medium, grade_hard
|
| 87 |
+
|
| 88 |
GRADERS = {
|
| 89 |
"easy": grade_easy,
|
| 90 |
"medium": grade_medium,
|
|
|
|
| 232 |
|
| 233 |
return self._build_observation(reward, action_result)
|
| 234 |
|
| 235 |
+
# Grader methods for OpenEnv validation
|
| 236 |
+
def grade_easy(self, observation: QuantumObservation) -> float:
|
| 237 |
+
"""Grader for Easy Task."""
|
| 238 |
+
return grade_easy(observation)
|
| 239 |
+
|
| 240 |
+
def grade_medium(self, observation: QuantumObservation) -> float:
|
| 241 |
+
"""Grader for Medium Task."""
|
| 242 |
+
return grade_medium(observation)
|
| 243 |
+
|
| 244 |
+
def grade_hard(self, observation: QuantumObservation) -> float:
|
| 245 |
+
"""Grader for Hard Task."""
|
| 246 |
+
return grade_hard(observation)
|
| 247 |
+
|
| 248 |
def _build_observation(self, reward: float, action_result: str) -> QuantumObservation:
|
| 249 |
max_steps_reached = self._state.step_count >= 150
|
| 250 |
is_done = max_steps_reached or self._is_circuit_dead_end()
|