from abc import ABC, abstractmethod
import gymnasium as gym
import pennylane as qml
[docs]
class QuantumEnv(gym.Env, ABC):
"""Abstract base class for all QRL quantum environments"""
def __init__(self, n_qubits=1):
super().__init__()
self.n_qubits = n_qubits
self.dev = qml.device("default.qubit", wires=n_qubits)
[docs]
@abstractmethod
def get_reward(self):
"""Get reward for current state."""
pass
[docs]
@abstractmethod
def reset(self, seed=None, options=None):
"""Reset environment to initial state."""
pass
[docs]
@abstractmethod
def step(self, action):
"""Apply an action (quantum gate or sequence) and return the new observation and reward"""
pass
[docs]
@abstractmethod
def render(self):
"""Animate the episode"""
pass