Pragmas
This module provides classes for building and managing quantum programs using the Bloqade library.
AddArgs
args
args(args_list: List[Union[str, Variable]]) -> Args
Add arguments to the current program.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args_list
|
List[Union[str, Variable]]
|
List of argument names or Variable objects to be added. |
required |
Returns:
Name | Type | Description |
---|---|---|
Args |
Args
|
A new instance of the Args class with the specified arguments. |
Raises:
Type | Description |
---|---|
TypeError
|
If args_list contains invalid types. |
Note
This method is useful for deferring the value assignment of certain variables to runtime.
Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/pragmas.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
Assignable
assign
assign(**assignments) -> Assign
Assign values to variables declared previously in the program.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**assignments
|
Key-value pairs where the key is the variable name and the value is the value to assign. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Assign |
Assign
|
A new instance of the Assign class with the specified assignments. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid assignment is provided. |
Note
This is reserved for variables that should take single values or for
spatial modulations created with .scale(str)
. After assigning values,
you can choose a backend for emulation or execution.
Usage Examples:
# define geometry
>>> reg = bloqade.start
... .add_position([(0,0),(1,1),(2,2),(3,3)])
# define variables in program
>>> seq = reg.rydberg.detuning.uniform
... .linear(start="ival", stop=1, duration="span_time")
# assign values to variables
>>> seq = seq.assign(span_time=0.5, ival=0.0)
- Next steps:
...assign(assignments).bloqade
: select the bloqade local emulator backend...assign(assignments).braket
: select braket local emulator or QuEra hardware...assign(assignments).device(specifier_string)
: select backend by specifying a string...assign(assignments).batch_assign(assignments)
: assign multiple values for a parameter sweep...assign(assignments).parallelize(cluster_spacing)
: parallelize the program register...assign(assignments).args([previously_defined_vars])
: defer value assignment to runtime
Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/pragmas.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
BatchAssignable
batch_assign
batch_assign(
__batch_params: List[Dict[str, ParamType]] = [],
**assignments: List[ParamType]
) -> Union[BatchAssign, ListAssign]
Assign multiple values to variables for creating a parameter sweep.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__batch_params
|
List[Dict[str, ParamType]]
|
List of dictionaries where each dictionary contains variable assignments for one set of parameters. |
[]
|
**assignments
|
List[ParamType]
|
Key-value pairs where the key is the variable name and the value is a list of values to assign. |
{}
|
Returns:
Type | Description |
---|---|
Union[BatchAssign, ListAssign]
|
Union[BatchAssign, ListAssign]: A new instance of BatchAssign or ListAssign class with the specified assignments. |
Raises:
Type | Description |
---|---|
ValueError
|
If both __batch_params and assignments are provided. |
Note
Bloqade handles the multiple programs generated by this method and treats them as a unified object for easy post-processing. Ensure all lists of values are of the same length as Bloqade will not perform a Cartesian product.
Usage Example:
>>> reg = start.add_position([(0,0), (0, "atom_distance")])
>>> prog = reg.rydberg.rabi.amplitude.uniform.constant("value", 5.0)
>>> var_assigned_prog = prog.batch_assign(value=[1.0, 2.0, 3.0],
atom_distance=[1.0, 2.0, 3.0])
- Next steps:
...batch_assign(assignments).bloqade
: select the bloqade local emulator backend...batch_assign(assignments).braket
: select braket local emulator or QuEra hardware...batch_assign(assignments).device(specifier_string)
: select backend by specifying a string...batch_assign(assignments).parallelize(cluster_spacing)
: parallelize the program register...batch_assign(assignments).args([previously_defined_vars])
: defer value assignment to runtime
Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/pragmas.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
Parallelizable
parallelize
parallelize(cluster_spacing: LiteralType) -> Parallelize
Parallelize the current problem by duplicating the geometry to utilize all available space/qubits on hardware.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cluster_spacing
|
LiteralType
|
Specifies the spacing between clusters in micrometers. |
required |
Returns:
Name | Type | Description |
---|---|---|
Parallelize |
Parallelize
|
A new instance of the Parallelize class with the specified cluster spacing. |
Raises:
Type | Description |
---|---|
ValueError
|
If the cluster_spacing is not a valid value. |
Note
After calling this method, you can choose a backend for emulation or
execution. Options include bloqade
for a local emulator, braket
for
a local emulator or QuEra hardware on the cloud, or specifying a device
with a string.
Usage Example:
>>> reg = start.add_position((0,0)).rydberg.rabi.uniform.amplitude.constant(1.0, 1.0)
# copy-paste the geometry and waveforms
>>> parallelized_prog = reg.parallelize(24)
- Next steps:
...parallelize(cluster_spacing).bloqade
: select the bloqade local emulator backend...parallelize(cluster_spacing).braket
: select braket local emulator or QuEra hardware on the cloud...parallelize(cluster_spacing).device(specifier_string)
: select backend by specifying a string
Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/pragmas.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|