Skip to content

Commit 793233e

Browse files
committed
code optimization and bug fixes
2 parents 3407491 + 3da3ca0 commit 793233e

12 files changed

Lines changed: 393 additions & 553 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ __pycache__
1111

1212
# setuptools
1313
*egg-info*
14+
dist/
1415

1516
# miscellaneous
1617
ddpg_DcSeries-Cont-v0_weights_actor\.h5f

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ learning algorithms to train agents controlling electric motors.
1515

1616
[Read the detailed docs!](https://upb-lea.github.io/gym-electric-motor/)
1717

18-
So far, several DC-motor models and the three-phase motors permanent magnet synchronous motor (PMSM)
19-
and synchronous reluctance motor (SynRM) are available.
18+
So far, several DC-motor models and the three-phase motors permanent magnet synchronous motor (PMSM),
19+
synchronous reluctance motor (SynRM), squirrel cage induction motor (SCIM) and doubly-fed induction
20+
motor (DFIM) are available.
2021
Beside electrical motors, also converters and load models are implemented. The converters can be driven by means of a duty cycle (continuous mode) or
2122
switching commands (discrete mode).
2223
The figure shows the basic scheme of the converter, motor and load.
-128 KB
Binary file not shown.
-98.3 KB
Binary file not shown.

gym_electric_motor/envs/gym_im/doubly_fed_induc_motor_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, motor='DFIM', reward_function=None, reference_generator=None,
2525
class DiscDoublyFedInductionMotorEnvironment(DoublyFedInductionMotorEnvironment):
2626
"""
2727
Description:
28-
Environment to simulate a discretely controlled Squirrel-Cage Induction Motor (SCIM).
28+
Environment to simulate a discretely controlled Doubly-Fed Induction Motor (SCIM).
2929
3030
Key:
3131
`DFIMDisc-v1`
@@ -93,7 +93,7 @@ def __init__(self, tau=1e-5, converter='Disc-Multi', subconverters=('Disc-B6C',
9393
class ContDoublyFedInductionMotorEnvironment(DoublyFedInductionMotorEnvironment):
9494
"""
9595
Description:
96-
Environment to simulate a continuously controlled Squirrel-Cage Induction Motor (SCIM).
96+
Environment to simulate a continuously controlled Doubly-Fed Induction Motor (SCIM).
9797
9898
Key:
9999
`DFIMCont-v1`

gym_electric_motor/envs/gym_im/squirrel_cage_induc_motor_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, motor='SCIM', reward_function=None, reference_generator=None,
2525
class DiscSquirrelCageInductionMotorEnvironment(SquirrelCageInductionMotorEnvironment):
2626
"""
2727
Description:
28-
Environment to simulate a discretely controlled Squirrel-Cage Induction Motor (SCIM).
28+
Environment to simulate a discretely controlled Squirrel Cage Induction Motor (SCIM).
2929
3030
Key:
3131
`SCIMDisc-v1`
@@ -92,7 +92,7 @@ def __init__(self, tau=1e-5, converter='Disc-B6C', **kwargs):
9292
class ContSquirrelCageInductionMotorEnvironment(SquirrelCageInductionMotorEnvironment):
9393
"""
9494
Description:
95-
Environment to simulate a continuously controlled Squirrel-Cage Induction Motor (SCIM).
95+
Environment to simulate a continuously controlled Squirrel Cage Induction Motor (SCIM).
9696
9797
Key:
9898
`SCIMCont-v1`

gym_electric_motor/physical_systems/converters.py

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -481,17 +481,40 @@ def __init__(self, subconverters, **kwargs):
481481
super().__init__(**kwargs)
482482
self._subconverters = [instantiate(PowerElectronicConverter, subconverter, **kwargs) for subconverter in subconverters]
483483

484-
self.subsignal_current_space_dims = np.array([(np.squeeze(subconverter.currents.shape) or 1) for subconverter in self._subconverters])
485-
self.subsignal_voltage_space_dims = np.array([(np.squeeze(subconverter.voltages.shape) or 1) for subconverter in self._subconverters])
484+
self.subsignal_current_space_dims = []
485+
self.subsignal_voltage_space_dims = []
486+
self.action_space = []
487+
currents_low = []
488+
currents_high = []
489+
voltages_low = []
490+
voltages_high = []
491+
492+
# get the limits and space dims from each subconverter
493+
for subconverter in self._subconverters:
494+
self.subsignal_current_space_dims.append(np.squeeze(subconverter.currents.shape) or 1)
495+
self.subsignal_voltage_space_dims.append(np.squeeze(subconverter.voltages.shape) or 1)
486496

487-
self.action_space = MultiDiscrete([subconverter.action_space.n for subconverter in self._subconverters])
497+
self.action_space.append(subconverter.action_space.n)
488498

489-
currents_low = np.concatenate([subconverter.currents.low for subconverter in self._subconverters])
490-
currents_high = np.concatenate([subconverter.currents.high for subconverter in self._subconverters])
491-
self.currents = Box(currents_low, currents_high)
499+
currents_low.append(subconverter.currents.low)
500+
currents_high.append(subconverter.currents.high)
501+
502+
voltages_low.append(subconverter.voltages.low)
503+
voltages_high.append(subconverter.voltages.high)
504+
505+
# convert to 1D list
506+
self.subsignal_current_space_dims = np.array(self.subsignal_current_space_dims)
507+
self.subsignal_voltage_space_dims = np.array(self.subsignal_voltage_space_dims)
508+
509+
currents_low = np.concatenate(currents_low)
510+
currents_high = np.concatenate(currents_high)
492511

493-
voltages_low = np.concatenate([subconverter.voltages.low for subconverter in self._subconverters])
494-
voltages_high = np.concatenate([subconverter.voltages.high for subconverter in self._subconverters])
512+
voltages_low = np.concatenate(voltages_low)
513+
voltages_high = np.concatenate(voltages_high)
514+
515+
# put limits into gym_space format
516+
self.action_space = MultiDiscrete(self.action_space)
517+
self.currents = Box(currents_low, currents_high)
495518
self.voltages = Box(voltages_low, voltages_high)
496519

497520
def convert(self, i_out, t):
@@ -558,19 +581,45 @@ def __init__(self, subconverters, **kwargs):
558581
super().__init__(**kwargs)
559582
self._subconverters = [instantiate(PowerElectronicConverter, subconverter, **kwargs) for subconverter in subconverters]
560583

561-
self.subsignal_current_space_dims = np.array([(np.squeeze(subconverter.currents.shape) or 1) for subconverter in self._subconverters])
562-
self.subsignal_voltage_space_dims = np.array([(np.squeeze(subconverter.voltages.shape) or 1) for subconverter in self._subconverters])
584+
self.subsignal_current_space_dims = []
585+
self.subsignal_voltage_space_dims = []
586+
action_space_low = []
587+
action_space_high = []
588+
currents_low = []
589+
currents_high = []
590+
voltages_low = []
591+
voltages_high = []
563592

564-
action_space_low = np.concatenate([subconverter.action_space.low for subconverter in self._subconverters])
565-
action_space_high = np.concatenate([subconverter.action_space.high for subconverter in self._subconverters])
566-
self.action_space = Box(action_space_low, action_space_high)
593+
# get the limits and space dims from each subconverter
594+
for subconverter in self._subconverters:
595+
self.subsignal_current_space_dims.append(np.squeeze(subconverter.currents.shape) or 1)
596+
self.subsignal_voltage_space_dims.append(np.squeeze(subconverter.voltages.shape) or 1)
567597

568-
currents_low = np.concatenate([subconverter.currents.low for subconverter in self._subconverters])
569-
currents_high = np.concatenate([subconverter.currents.high for subconverter in self._subconverters])
570-
self.currents = Box(currents_low, currents_high)
598+
action_space_low.append(subconverter.action_space.low)
599+
action_space_high.append(subconverter.action_space.high)
600+
601+
currents_low.append(subconverter.currents.low)
602+
currents_high.append(subconverter.currents.high)
603+
604+
voltages_low.append(subconverter.voltages.low)
605+
voltages_high.append(subconverter.voltages.high)
606+
607+
# convert to 1D list
608+
self.subsignal_current_space_dims = np.array(self.subsignal_current_space_dims)
609+
self.subsignal_voltage_space_dims = np.array(self.subsignal_voltage_space_dims)
610+
611+
action_space_low = np.concatenate(action_space_low)
612+
action_space_high = np.concatenate(action_space_high)
571613

572-
voltages_low = np.concatenate([subconverter.voltages.low for subconverter in self._subconverters])
573-
voltages_high = np.concatenate([subconverter.voltages.high for subconverter in self._subconverters])
614+
currents_low = np.concatenate(currents_low)
615+
currents_high = np.concatenate(currents_high)
616+
617+
voltages_low = np.concatenate(voltages_low)
618+
voltages_high = np.concatenate(voltages_high)
619+
620+
# put limits into gym_space format
621+
self.action_space = Box(action_space_low, action_space_high)
622+
self.currents = Box(currents_low, currents_high)
574623
self.voltages = Box(voltages_low, voltages_high)
575624

576625
def set_action(self, action, t):

0 commit comments

Comments
 (0)