override complete config for submodule with hydra - fb-hydra

So, I have a hydra model config (autoencoder.yaml) defined as:
_target_: student.models.AutoEncoder
defaults:
- dataloader: msa
- encoder: default_encoder
- decoder: vae_decoder
- scheduler: null
- optimizer: adam
- preprocessing: null
batch_size: 256
Now in the encoder folder, I have the following YAML configs:
- default_encoder.yaml
- vae_encoder.yaml
and my base config file is as:
# #package _global_
defaults:
- _self_
- model: autoencoder.yaml
# enable color logging
- override hydra/hydra_logging: colorlog
- override hydra/job_logging: colorlog
work_dir: ${hydra:runtime.cwd}
seed: null
name: "default"
Now, I can call this as is with:
python myapp.py seed=42 #works
but when I do something like:
python myapp.py ++model.encoder=vae_encoder
It comes with the error:
Top level config has to be OmegaConf DictConfig, plain dict, or a Structured Config class or instance
How can I just replace the underlying object through composition with hydra? Basically, when I do this or ++model.encoder=vae_encoder, it replaces this as a string rather than referring to the yaml file

When modifying the defaults list, use a slash ('/') instead of a period ('.') as the separator for path components:
python myapp.py model/encoder=vae_encoder
instead of
python myapp.py model.encoder=vae_encoder

Related

Salt state to enable re-run systemd service

I am trying to craft a salt state file to simply ensure-enabled and re-run my one-shot service. I thought it would be nice to re-run if any of the dependent files changed, but honestly this is simple enough and the short-lived service is almost never going to be running when I want to update.
Current attempt:
myown-systemd-service-unit-file:
...
myown-systemd-service-executable-file:
...
myown-service:
systemd.force_reload:
- name: myown
- enable: True
- watch:
- myown-systemd-service-unit-file
- myown-systemd-service-executable-file
is failing at with errror:
----------
ID: myown-service
Function: systemd.force_reload
Name: myown
Result: False
Comment: State 'systemd.force_reload' was not found in SLS 'something.myown'
Reason: 'systemd.force_reload' is not available.
Changes:
By enable, I mean to have the equivalent of this CLI call be applied:
sudo systemctl enable myown.service
Relevant docs: https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.systemd_service.html#module-salt.modules.systemd_service
The systemd_service module is an execution module, and the syntax to use such modules is slightly different. The state declaration you are using is for state modules. Also, the example from the documentation points to use of service.force_reload rather than systemd.force_reload.
salt '*' service.force_reload <service name>
Considering all this, the below example restarts and enables myown service when the service unit file changes.
myown-service:
module.run:
- service.restart:
- name: myown
onchanges:
- file: myown-systemd-service-unit-file
- service.enable:
- name: myown
Note that I've used restart instead of force_reload to bounce the service. Also I'm using onchanges for file module as you haven't shown how you manage the two files. You can use the appropriate module and state IDs.

Environment variables in Dagster config YAML

I'm attempting to provide an environment variable in a config YAML file as such:
resources:
be_warehouse:
config:
conn_str:
env: DB_CONN_STR
analytics_warehouse:
config:
conn_str:
env: WH_DB_CONN_STR
but I am receiving the following error:
Invalid scalar at path root:resources:analytics_warehouse:config:conn_str. Value "{'env': 'WH_DB_CONN_STR'}" of type "<class 'dict'>" is not valid for expected type "String".
I have seen this syntax used in this official example. Am I missing something obvious?
The env: ENV_VAR support is available for config schema which is typed as StringSource. If these are #resources you are creating you just need to declare config_schema={'conn_str': StringSource} instead of just using str.
https://docs.dagster.io/_apidocs/config#dagster.StringSource

JMSSerializerBundle Yaml config for custom entity class

I've got in my symfony2 project, a custom entity outside Bundles and framework.
I need set json data into this entity, but i can't apply right configuration to user yaml file.
app/config/config.yml
jms_serializer:
metadata:
auto_detection: true
directories:
CORE:
namespace_prefix: "Core\Domain\Model"
path: "%kernel.root_dir%/Resources/serializer/CORE"
app/Resources/serializer/CORE/Model.Product.yml
Core\Domain\Model\Product\Product:
properties:
id:
type: integer
objectId:
type: string
name:
type: string ...
It's possible that this bundle dont works fine with entities outside bundles?.
Always I see error message: You must define a type for Core\Domain\Model\Product\Product::$id.
I think that JMSSerializerBundle don't read yaml file, because with annotations works fine.
Any idea?.
Thanks.
In your app/config/config.yml be sure to use \\ as namespace separator instead of \:
jms_serializer:
metadata:
auto_detection: true
directories:
CORE:
namespace_prefix: "Core\\Domain\\Model"
path: "%kernel.root_dir%/Resources/serializer/CORE"
Otherwise the backslashes are treated as escape characters for the following letters.
Edit:
Also make sure to name the JMS serializer config properly. For the class Core\Domain\Model\Product\Product you need a Product.Product.yml file inside the specified path of the config. In your example, your file is named Model.Product.yml.
So to get the serializer config file name for an entitiy in general:
Strip the namespace defined in the config from the class name
replace the namespace separators \ with .
append .yml and put the file in the path folder defined in the config

Confused on Symfony2 YAML imports

I'm new to Symfony and a little confused by the imports key found at the top of config.yml. I am trying to import /our_stuff/admin/version.yml into Symfony's config.yml file.
This is what my config.yml file looks like:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: '/our_stuff/admin/version.yml' }
This is what I have inside my version.yml file
version:
last_recorded_software_version: '10.12.1'
But this produces the error:
FileLoaderLoadException: Cannot import resource "/our_stuff/admin/version.yml" from "/our_stuff/admin/symfony/app/config/config.yml". (There is no extension able to load the configuration for "last_recorded_software_version" (in /our_stuff/admin/version.yml).
Looked for namespace "last_recorded_software_version", found "framework", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "web_profiler", "sensio_distribution")
To test, I've also moved the version.yml file into Symfony's config folder. The path is symfony_root/app/config/, but this still produces the same error.
Why does importing work for the default YAML files that are included in Symfony, but not the one's I include?
EDIT Edited for clarity
Edit 2 Here is the entirety of the /our_stuff/admin/version.yml file:
# Update this variable ONLY RIGHT BEFORE creating a new numbered release
version:
last_recorded_software_version: '10.12.1'
Edit 3 The solution:
The version.yml file needs to have a namespace of parameters in order to read them in the config.yml file
# app/config/config.yml
imports:
- { resource: 'parameters.yml' }
- { resource: '/etc/sites/mysite.com/parameters.yml' }
#/etc/sites/mysite.com/version.yml
parameters:
some_key:
some_other_key: value
some_other_key1: value
...
You can store your configuration files outside the project direcoty or in project directory and can include check this link global-configuration-files
You can include you configuration file like this:
# app/config/config.yml
imports:
- { resource: 'parameters.yml' }
- { resource: '/etc/sites/mysite.com/parameters.yml' }
Your version.yml file format should be:
parameters:
some_key:
some_other_key: value
some_other_key1: value
...
All config files in Symfony are parsed by Configuration component. Symfony application by default import only one file: config_%environment%.yml. This file has 3 predefined sections that have significant value for Symfony:
imports
Contain array of resources that will be imported by configuration component in processing. These resources may be xml, yml or even php files that will return array.
services
Contain service definitions that have very significant value for ServiceContainer that will create services from this config section.
parameters
Parameters that will have significant value for ServiceContainer that will manage all included values in parameters section of container. If you want to get parameters from service container you should define it here.
Also you can import any config file in your bundle's configuration class.
If you import your config files inside imports block or in your bundle's Configuration class you should place them in appropriate sections: parameters, services.
As was requested examples:
parameters.yml:
parameters:
param: value1
array: {key1: value2}
services.yml:
services:
class: FQCN/To/Your/Class
If you put your version.config under some bundle you have to import it like this :
- { resource: "#AAA/YourBundle/Resources/config/version.yml" }
Otherwise your first import will work perfectly :
- { resource: version.yml }

Symfony2 bundle configuration parameters

My team develops a very large e-commerce project. Up to now, we had something like 40 configuration parameters in that bundle and I didn't know their final relations nor had a way to structure them properly, so we ended up using the standard parameters structure in the app/config.yml file. But, somewhere along the way I decided to move the config to the semantic configuration structure - so I can validate it, have a clean structure, easily extend it by means of bundle inheritance and so on.
The problem is I can't import our bundle parameters to another bundle config, now.
Here's what I could do before:
(...)
parameters:
company.bundle.email.user: user#domain.com
company.bundle.email.pass: #MyBeAUtiFULpA55w0Rd!
(...)
swiftmailer:
(...)
username: %company.bundle.email.user%
password: %company.bundle.email.pass%
Here's what I'm trying to do now and it doesn't work at all:
(...)
company_bundle:
(...)
settings:
(...)
mailer:
(...)
user: user#domain.com
pass: #MyBeAUtiFULpA55w0Rd!
(...)
swiftmailer:
(...)
username: %company_bundle.settings.mailer.user%
password: %company_bundle.settings.mailer.pass%
(...)
Of course the company_bundle node contains the semantic configuration, processed by the DIC and defined in Company\Bundle\DependencyInjection\Configuration.php.
All I end up with for now is the following error:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "company_bundle.settings.mailer.user".
So the question is: how to make my bundle parameters accessible in another bundle configuration parameters (I've already taken care of including my bundle configuration always before the Swiftmailer bundle)?
NOTICE: Swiftmailer bundle configuration is shown here only for demonstration purposes, I want to be able to reuse my bundle parameters across some other bundles as well.
What's the motivation behind that?
Well I want our product to be configured by a person who doesn't know Symfony well - so she must be able to open our bundle config file and just tweak the parameters, which will then be used in some Symfony bundles we use. So I want all application configuration to be accessible in our bundle's semantic conf, since I'd want not to expose the whole configuration to that person (I've already divided everything into separate config files, one of them containing the configuration for our bundle, the rest - for all the other ones).
So, is what I'm asking even possible?
As the parameters are to be modified in each installation (they probably differ at least between development and production environments), so (as Sgoettschkes said in comment) external file is the best solution.
In Symfony2 by default place for such parameters is parameters.yml file located in app/config/ dir.
In standard installation you can find for example such entries:
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
(...)
These params are used in config.yml this way:
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
(...)
So you can define your params (in parameters.yml):
parameters:
(...)
company_bundle_email_user: user#domain.com
company_bundle_email_pass: #MyBeAUtiFULpA55w0Rd!
and use them (in config.yml):
swiftmailer:
(...)
username: %company_bundle_email_user%
password: %company_bundle_email_pass%

Resources