The environment module defines an Environment type that plays a similar role as a context (or typing environment) for type checking systems. Here, it is a record of information for the qubit register and compilation directives.
Environment
An environment to hold register information and compiler directives.
add_grid_options(options)
Add grid options to the Environment.
Source code in qadence2_expressions/core/environment.py
defadd_grid_options(options:dict[str,Any])->None:"""Add grid options to the Environment."""current=Environment.grid_optionsor{}Environment.grid_options={**current,**options}
add_qpu_directives(directives)
Add QPU directives to the Environment.
Source code in qadence2_expressions/core/environment.py
defadd_qpu_directives(directives:dict[str,Any])->None:"""Add QPU directives to the Environment."""current=Environment.directivesor{}Environment.directives={**current,**directives}
add_settings(settings)
Add compilation settings to the Environment.
Source code in qadence2_expressions/core/environment.py
defadd_settings(settings:dict[str,Any])->None:"""Add compilation settings to the Environment."""current=Environment.settingsor{}Environment.settings={**current,**settings}
get_grid_options()
Get grid options from the Environment.
Source code in qadence2_expressions/core/environment.py
defset_number_qubits(n:int)->None:"""Set the number of qubits in the Environment if not defined in the register."""ifEnvironment.qubit_positionsandn!=len(Environment.qubit_positions):raiseValueError("Number of qubits already defined by the register.")Environment.num_qubits=n
set_qubits_positions(pos)
Set qubits positions in the Environment.
Source code in qadence2_expressions/core/environment.py
defset_qubits_positions(pos:list[tuple[int,int]]|list[int])->None:"""Set qubits positions in the Environment."""Environment.qubit_positions=posset_number_qubits(len(pos))