qml.tape.OperationRecorder¶
- class OperationRecorder(ops=None, measurements=None, shots=None)[source]¶
Bases:
pennylane.tape.qscript.QuantumScript
,pennylane.queuing.AnnotatedQueue
A template and quantum function inspector, allowing easy introspection of operators that have been applied without requiring a QNode.
Example:
The OperationRecorder is a context manager. Executing templates or quantum functions stores applied operators in the recorder, which can then be printed.
>>> shape = qml.templates.StronglyEntanglingLayers.shape(n_layers=1, n_wires=2) >>> weights = np.random.random(shape) >>> >>> with OperationRecorder() as rec: >>> qml.templates.StronglyEntanglingLayers(weights, wires=[0, 1])
Alternatively, the
queue
attribute can be used to directly access the appliedOperation
andObservable
objects.Attributes
The batch size of the quantum script inferred from the batch sizes of the used operations for parameter broadcasting.
Returns the underlying quantum circuit as a list of operations and measurements.
Alias to
get_parameters()
andset_parameters()
for backwards compatibilities with operations.Returns the gates that diagonalize the measured wires such that they are in the eigenbasis of the circuit observables.
Returns a directed acyclic graph representation of the recorded quantum circuit:
returns an integer hash uniquely representing the quantum script
Returns the measurements on the quantum script.
Returns the number of trainable parameters on the quantum script.
Returns the index of the first operator that is not an StatePrepBase operator.
Returns the number of wires in the quantum script process
Returns the expected numeric type of the quantum script result by inspecting its measurements.
Returns the subset of the observables that share wires with another observable, i.e., that do not have their own unique set of wires.
Returns the indices subset of the observables that share wires with another observable, i.e., that do not have their own unique set of wires.
Returns the observables on the quantum script.
Returns the wires that the tape operations act on.
Returns the state preparations and operations on the quantum script.
The (inferred) output dimension of the quantum script.
Returns the parameter information of the operations and measurements in the quantum script.
Returns a list of objects in the annotated queue
Determines if any of the measurements are in the computational basis.
Returns a
Shots
object containing information about the number and batches of shotsResource information about a quantum circuit.
Store or return a list containing the indices of parameters that support differentiability.
Returns the wires used in the quantum script process
- batch_size¶
The batch size of the quantum script inferred from the batch sizes of the used operations for parameter broadcasting.
See also
batch_size
for details.- Returns
The batch size of the quantum script if present, else
None
.- Return type
int or None
- circuit¶
Returns the underlying quantum circuit as a list of operations and measurements.
The circuit is created with the assumptions that:
The
operations
attribute contains quantum operations and mid-circuit measurements andThe
measurements
attribute contains terminal measurements.
Note that the resulting list could contain MeasurementProcess objects that some devices may not support.
- Returns
the quantum circuit containing quantum operations and measurements
- Return type
list[Operator, MeasurementProcess]
- data¶
Alias to
get_parameters()
andset_parameters()
for backwards compatibilities with operations.
- diagonalizing_gates¶
Returns the gates that diagonalize the measured wires such that they are in the eigenbasis of the circuit observables.
- Returns
the operations that diagonalize the observables
- Return type
List[Operation]
Examples
For a tape with a single observable, we get the diagonalizing gate of that observable:
>>> tape = qml.tape.QuantumScript([], [qml.expval(X(0))]) >>> tape.diagonalizing_gates [Hadamard(wires=[0])]
If the tape includes multiple observables, they are each diagonalized individually:
>>> tape = qml.tape.QuantumScript([], [qml.expval(X(0)), qml.var(Y(1))]) >>> tape.diagonalizing_gates [Hadamard(wires=[0]), Z(1), S(wires=[1]), Hadamard(wires=[1])]
Warning
If the tape contains multiple observables acting on the same wire, then
tape.diagonalizing_gates
will include multiple conflicting diagonalizations.For example:
>>> tape = qml.tape.QuantumScript([], [qml.expval(X(0)), qml.var(Y(0))]) >>> tape.diagonalizing_gates [Hadamard(wires=[0]), Z(0), S(wires=[0]), Hadamard(wires=[0])]
If it is relevant for your application, applying
split_non_commuting()
to a tape will split it into multiple tapes with only qubit-wise commuting observables.Generally, composite operators are handled by diagonalizing their component parts, for example:
>>> tape = qml.tape.QuantumScript([], [qml.expval(X(0)+Y(1))]) >>> tape.diagonalizing_gates [Hadamard(wires=[0]), Z(1), S(wires=[1]), Hadamard(wires=[1])]
However, for operators that contain multiple terms on the same wire, a single diagonalizing operator will be returned that diagonalizes the full operator as a unit:
>>> tape = qml.tape.QuantumScript([], [qml.expval(X(0)+Y(0))]) >>> tape.diagonalizing_gates [QubitUnitary(array([[-0.70710678-0.j , 0.5 -0.5j], [-0.70710678-0.j , -0.5 +0.5j]]), wires=[0])]
- graph¶
Returns a directed acyclic graph representation of the recorded quantum circuit:
>>> ops = [qml.StatePrep([0, 1], 0), qml.RX(0.432, 0)] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0))]) >>> qscript.graph <pennylane.circuit_graph.CircuitGraph object at 0x7fcc0433a690>
Note that the circuit graph is only constructed once, on first call to this property, and cached for future use.
- Returns
the circuit graph object
- Return type
- hash¶
returns an integer hash uniquely representing the quantum script
- Type
int
- measurements¶
Returns the measurements on the quantum script.
- Returns
list of measurement processes
- Return type
list[MeasurementProcess]
Example
>>> ops = [qml.StatePrep([0, 1], 0), qml.RX(0.432, 0)] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0))]) >>> qscript.measurements [expval(Z(0))]
- num_params¶
Returns the number of trainable parameters on the quantum script.
- num_preps¶
Returns the index of the first operator that is not an StatePrepBase operator.
- num_wires¶
Returns the number of wires in the quantum script process
- Returns
number of wires in quantum script process
- Return type
int
- numeric_type¶
Returns the expected numeric type of the quantum script result by inspecting its measurements.
- Returns
The numeric type corresponding to the result type of the quantum script, or a tuple of such types if the script contains multiple measurements
- Return type
Union[type, Tuple[type]]
Example:
>>> dev = qml.device('default.qubit', wires=2) >>> qs = QuantumScript(measurements=[qml.state()]) >>> qs.numeric_type complex
- obs_sharing_wires¶
Returns the subset of the observables that share wires with another observable, i.e., that do not have their own unique set of wires.
- Returns
list of observables with shared wires.
- Return type
list[Observable]
- obs_sharing_wires_id¶
Returns the indices subset of the observables that share wires with another observable, i.e., that do not have their own unique set of wires.
- Returns
list of indices from observables with shared wires.
- Return type
list[int]
- observables¶
Returns the observables on the quantum script.
- Returns
list of observables
- Return type
list[MeasurementProcess, Observable]]
Example
>>> ops = [qml.StatePrep([0, 1], 0), qml.RX(0.432, 0)] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0))]) >>> qscript.observables [expval(Z(0))]
- op_wires¶
Returns the wires that the tape operations act on.
- operations¶
Returns the state preparations and operations on the quantum script.
- Returns
quantum operations
- Return type
list[Operator]
>>> ops = [qml.StatePrep([0, 1], 0), qml.RX(0.432, 0)] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0))]) >>> qscript.operations [StatePrep([0, 1], wires=[0]), RX(0.432, wires=[0])]
- output_dim¶
The (inferred) output dimension of the quantum script.
- par_info¶
Returns the parameter information of the operations and measurements in the quantum script.
- Returns
list of dictionaries with parameter information.
- Return type
list[dict[str, Operator or int]]
Example
>>> ops = [qml.StatePrep([0, 1], 0), qml.RX(0.432, 0), qml.CNOT((0,1))] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0))]) >>> qscript.par_info [{'op': StatePrep(array([0, 1]), wires=[0]), 'op_idx': 0, 'p_idx': 0}, {'op': RX(0.432, wires=[0]), 'op_idx': 1, 'p_idx': 0}]
Note that the operations and measurements included in this list are only the ones that have parameters
- queue¶
- samples_computational_basis¶
Determines if any of the measurements are in the computational basis.
- shots¶
Returns a
Shots
object containing information about the number and batches of shots- Returns
Object with shot information
- Return type
Shots
- specs¶
Resource information about a quantum circuit.
- Returns
dictionaries that contain quantum script specifications
- Return type
dict[str, Union[defaultdict,int]]
- Example
>>> ops = [qml.Hadamard(0), qml.RX(0.26, 1), qml.CNOT((1,0)), ... qml.Rot(1.8, -2.7, 0.2, 0), qml.Hadamard(1), qml.CNOT((0, 1))] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0) @ qml.Z(1))])
Asking for the specs produces a dictionary of useful information about the circuit:
>>> qscript.specs['num_observables'] 1 >>> qscript.specs['gate_sizes'] defaultdict(<class 'int'>, {1: 4, 2: 2}) >>> print(qscript.specs['resources']) wires: 2 gates: 6 depth: 4 shots: Shots(total=None) gate_types: {'Hadamard': 2, 'RX': 1, 'CNOT': 2, 'Rot': 1} gate_sizes: {1: 4, 2: 2}
- trainable_params¶
Store or return a list containing the indices of parameters that support differentiability. The indices provided match the order of appearance in the quantum circuit.
Setting this property can help reduce the number of quantum evaluations needed to compute the Jacobian; parameters not marked as trainable will be automatically excluded from the Jacobian computation.
The number of trainable parameters determines the number of parameters passed to
set_parameters()
, and changes the default output size of methodget_parameters()
.Note
For devices that support native backpropagation (such as
default.qubit
anddefault.mixed
), this property contains no relevant information when using backpropagation to compute gradients.Example
>>> ops = [qml.RX(0.432, 0), qml.RY(0.543, 0), ... qml.CNOT((0,"a")), qml.RX(0.133, "a")] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0))]) >>> qscript.trainable_params [0, 1, 2] >>> qscript.trainable_params = [0] # set only the first parameter as trainable >>> qscript.get_parameters() [0.432]
- wires¶
Returns the wires used in the quantum script process
- Returns
wires in quantum script process
- Return type
Wires
Methods
adjoint
()Create a quantum script that is the adjoint of this one.
append
(obj, **kwargs)Append
obj
into the queue withkwargs
metadata.bind_new_parameters
(params, indices)Create a new tape with updated parameters.
clear
()copy
([copy_operations])Returns a copy of the quantum script.
draw
([wire_order, show_all_wires, decimals, ...])Draw the quantum script as a circuit diagram.
expand
([depth, stop_at, expand_measurements])Expand all operations to a specific depth.
from_queue
(queue[, shots])Construct a QuantumScript from an AnnotatedQueue.
fromkeys
([value])Create a new ordered dictionary with keys from iterable and values set to value.
get
(key[, default])Return the value for key if key is in the dictionary, else default.
get_info
(obj)Retrieve the metadata for
obj
.get_operation
(idx)Returns the trainable operation, the operation index and the corresponding operation argument index, for a specified trainable parameter index.
get_parameters
([trainable_only, operations_only])Return the parameters incident on the quantum script operations.
items
()keys
()Map a circuit's wires such that they are in a standard order.
move_to_end
(key[, last])Move an existing element to the end (or beginning if last is false).
pop
(key[,default])If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem
([last])Remove and return a (key, value) pair from the dictionary.
remove
(obj)Remove
obj
from the queue.setdefault
(key[, default])Insert key with a value of default if key is not in the dictionary.
shape
(device)Produces the output shape of the quantum script by inspecting its measurements and the device used for execution.
to_openqasm
([wires, rotations, measure_all, ...])Serialize the circuit as an OpenQASM 2.0 program.
update
([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
update_info
(obj, **kwargs)Update
obj
's metadata withkwargs
if it exists in the queue.values
()- adjoint()¶
Create a quantum script that is the adjoint of this one.
Adjointed quantum scripts are the conjugated and transposed version of the original script. Adjointed ops are equivalent to the inverted operation for unitary gates.
- Returns
the adjointed script
- Return type
QuantumScript
- append(obj, **kwargs)¶
Append
obj
into the queue withkwargs
metadata.
- bind_new_parameters(params, indices)¶
Create a new tape with updated parameters.
This function takes a list of new parameters as input, and returns a new
QuantumScript
containing the new parameters at the provided indices, with the parameters at all other indices remaining the same.- Parameters
params (Sequence[TensorLike]) – New parameters to create the tape with. This must have the same length as
indices
.indices (Sequence[int]) – The parameter indices to update with the given parameters. The index of a parameter is defined as its index in
tape.get_parameters()
.
- Returns
New tape with updated parameters
- Return type
Example
>>> ops = [qml.RX(0.432, 0), qml.RY(0.543, 0), ... qml.CNOT((0,"a")), qml.RX(0.133, "a")] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0))])
A new tape can be created by passing new parameters along with the indices to be updated. To modify all parameters in the above qscript:
>>> new_qscript = qscript.bind_new_parameters([0.1, 0.2, 0.3], [0, 1, 2]) >>> new_qscript.get_parameters() [0.1, 0.2, 0.3]
The original
qscript
remains unchanged:>>> qscript.get_parameters() [0.432, 0.543, 0.133]
A subset of parameters can be modified as well, defined by the parameter indices:
>>> newer_qscript = new_qscript.bind_new_parameters([-0.1, 0.5], [0, 2]) >>> newer_qscript.get_parameters() [-0.1, 0.2, 0.5]
- clear() None. Remove all items from od. ¶
- copy(copy_operations=False, **update)¶
Returns a copy of the quantum script. If any attributes are defined via keyword argument, those are used on the new tape - otherwise, all attributes match the original tape. The copy is a shallow copy if copy_operations is False and no tape attributes are updated via keyword argument.
- Parameters
copy_operations (bool) – If True, the operations are also shallow copied. Otherwise, if False, the copied operations will simply be references to the original operations; changing the parameters of one script will likewise change the parameters of all copies. If any keyword arguments are passed to update, this argument will be treated as True.
- Keyword Arguments
operations (Iterable[Operator]) – An iterable of the operations to be performed. If provided, these operations will replace the copied operations on the new tape.
measurements (Iterable[MeasurementProcess]) – All the measurements to be performed. If provided, these measurements will replace the copied measurements on the new tape.
shots (None, int, Sequence[int], Shots) – Number and/or batches of shots for execution. If provided, these shots will replace the copied shots on the new tape.
trainable_params (None, Sequence[int]) – The indices for which parameters are trainable. If provided, these parameter indices will replace the copied parameter indices on the new tape.
- Returns
A copy of the quantum script, with modified attributes if specified by keyword argument.
- Return type
Example
tape = qml.tape.QuantumScript( ops= [qml.X(0), qml.Y(1)], measurements=[qml.expval(qml.Z(0))], shots=2000) new_tape = tape.copy(measurements=[qml.expval(qml.X(1))])
>>> tape.measurements [qml.expval(qml.Z(0)]
>>> new_tape.measurements [qml.expval(qml.X(1))]
>>> new_tape.shots Shots(total_shots=2000, shot_vector=(ShotCopies(2000 shots x 1),))
- draw(wire_order=None, show_all_wires=False, decimals=None, max_length=100, show_matrices=True)¶
Draw the quantum script as a circuit diagram. See
tape_text()
for more information.- Parameters
wire_order (Sequence[Any]) – the order (from top to bottom) to print the wires of the circuit
show_all_wires (bool) – If True, all wires, including empty wires, are printed.
decimals (int) – How many decimal points to include when formatting operation parameters. Default
None
will omit parameters from operation labels.max_length (Int) – Maximum length of a individual line. After this length, the diagram will begin anew beneath the previous lines.
show_matrices=True (bool) – show matrix valued parameters below all circuit diagrams
- Returns
the circuit representation of the quantum script
- Return type
str
- expand(depth=1, stop_at=None, expand_measurements=False)¶
Expand all operations to a specific depth.
- Parameters
depth (int) – the depth the script should be expanded
stop_at (Callable) – A function which accepts a queue object, and returns
True
if this object should not be expanded. If not provided, all objects that support expansion will be expanded.expand_measurements (bool) – If
True
, measurements will be expanded to basis rotations and computational basis measurements.
See also
decompose()
for a transform that performs the same job and fits into the current transform architecture.Warning
This method cannot be used with a tape with non-commuting measurements, even if
expand_measurements=False
.>>> mps = [qml.expval(qml.X(0)), qml.expval(qml.Y(0))] >>> tape = qml.tape.QuantumScript([], mps) >>> tape.expand() QuantumFunctionError: Only observables that are qubit-wise commuting Pauli words can be returned on the same wire, some of the following measurements do not commute: [expval(X(0)), expval(Y(0))]
Since commutation is determined by pauli word arithmetic, non-pauli words cannot share wires with other measurements, even if they commute:
>>> measurements = [qml.expval(qml.Projector([0], 0)), qml.probs(wires=0)] >>> tape = qml.tape.QuantumScript([], measurements) >>> tape.expand() QuantumFunctionError: Only observables that are qubit-wise commuting Pauli words can be returned on the same wire, some of the following measurements do not commute: [expval(Projector(array([0]), wires=[0])), probs(wires=[0])]
For this reason, we recommend the use of
decompose()
instead.Usage Details
>>> ops = [qml.Permute((2,1,0), wires=(0,1,2)), qml.X(0)] >>> measurements = [qml.expval(qml.X(0))] >>> tape = qml.tape.QuantumScript(ops, measurements) >>> expanded_tape = tape.expand() >>> print(expanded_tape.draw()) 0: ─╭SWAP──Rϕ──RX──Rϕ─┤ <X> 2: ─╰SWAP─────────────┤
Specifying a depth greater than one decomposes operations multiple times.
>>> expanded_tape2 = tape.expand(depth=2) >>> print(expanded_tape2.draw()) 0: ─╭●─╭X─╭●──RZ──GlobalPhase──RX──RZ──GlobalPhase─┤ <Z> 2: ─╰X─╰●─╰X──────GlobalPhase──────────GlobalPhase─┤
The
stop_at
callable allows the specification of terminal operations that should no longer be decomposed. In this example, theX
operator is not decomposed becausestop_at(qml.X(0)) == True
.>>> def stop_at(obj): ... return isinstance(obj, qml.X) >>> expanded_tape = tape.expand(stop_at=stop_at) >>> print(expanded_tape.draw()) 0: ─╭SWAP──X─┤ <X> 2: ─╰SWAP────┤
Warning
If an operator does not have a decomposition, it will not be decomposed, even if
stop_at(obj) == False
. If you want to decompose to reach a certain gateset, you will need an extra validation pass to ensure you have reached the gateset.>>> def stop_at(obj): ... return getattr(obj, "name", "") in {"RX", "RY"} >>> tape = qml.tape.QuantumScript([qml.RZ(0.1, 0)]) >>> tape.expand(stop_at=stop_at).circuit [RZ(0.1, wires=[0])]
If more than one observable exists on a wire, the diagonalizing gates will be applied and the observable will be substituted for an analogous combination of
qml.Z
operators. This will happen even ifexpand_measurements=False
.>>> mps = [qml.expval(qml.X(0)), qml.expval(qml.X(0) @ qml.X(1))] >>> tape = qml.tape.QuantumScript([], mps) >>> expanded_tape = tape.expand() >>> print(expanded_tape.draw()) 0: ──RY─┤ <Z> ╭<Z@Z> 1: ──RY─┤ ╰<Z@Z>
Setting
expand_measurements=True
applies any diagonalizing gates and converts the measurement into a wires+eigvals representation.Warning
Many components of PennyLane do not support the wires + eigvals representation. Setting
expand_measurements=True
should be used with extreme caution.>>> tape = qml.tape.QuantumScript([], [qml.expval(qml.X(0))]) >>> tape.expand(expand_measurements=True).circuit [Hadamard(wires=[0]), expval(eigvals=[ 1. -1.], wires=[0])]
- classmethod from_queue(queue, shots=None)¶
Construct a QuantumScript from an AnnotatedQueue.
- fromkeys(value=None)¶
Create a new ordered dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- get_info(obj)¶
Retrieve the metadata for
obj
. Raises aQueuingError
if obj is not in the queue.
- get_operation(idx)¶
Returns the trainable operation, the operation index and the corresponding operation argument index, for a specified trainable parameter index.
- Parameters
idx (int) – the trainable parameter index
- Returns
tuple containing the corresponding operation, operation index and an integer representing the argument index, for the provided trainable parameter.
- Return type
tuple[Operation, int, int]
- get_parameters(trainable_only=True, operations_only=False, **kwargs)¶
Return the parameters incident on the quantum script operations.
The returned parameters are provided in order of appearance on the quantum script.
- Parameters
trainable_only (bool) – if True, returns only trainable parameters
operations_only (bool) – if True, returns only the parameters of the operations excluding parameters to observables of measurements
Example
>>> ops = [qml.RX(0.432, 0), qml.RY(0.543, 0), ... qml.CNOT((0,"a")), qml.RX(0.133, "a")] >>> qscript = QuantumScript(ops, [qml.expval(qml.Z(0))])
By default, all parameters are trainable and will be returned:
>>> qscript.get_parameters() [0.432, 0.543, 0.133]
Setting the trainable parameter indices will result in only the specified parameters being returned:
>>> qscript.trainable_params = [1] # set the second parameter as trainable >>> qscript.get_parameters() [0.543]
The
trainable_only
argument can be set toFalse
to instead return all parameters:>>> qscript.get_parameters(trainable_only=False) [0.432, 0.543, 0.133]
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- map_to_standard_wires()¶
Map a circuit’s wires such that they are in a standard order. If no mapping is required, the unmodified circuit is returned.
- Returns
The circuit with wires in the standard order
- Return type
The standard order is defined by the operator wires being increasing integers starting at zero, to match array indices. If there are any measurement wires that are not in any operations, those will be mapped to higher values.
Example:
>>> circuit = qml.tape.QuantumScript([qml.X("a")], [qml.expval(qml.Z("b"))]) >>> circuit.map_to_standard_wires().circuit [X(0), expval(Z(1))]
If any measured wires are not in any operations, they will be mapped last:
>>> circuit = qml.tape.QuantumScript([qml.X(1)], [qml.probs(wires=[0, 1])]) >>> circuit.map_to_standard_wires().circuit [X(0), probs(wires=[1, 0])]
If no wire-mapping is needed, then the returned circuit is the inputted circuit:
>>> circuit = qml.tape.QuantumScript([qml.X(0)], [qml.expval(qml.Z(1))]) >>> circuit.map_to_standard_wires() is circuit True
- move_to_end(key, last=True)¶
Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
- pop(key[, default]) v, remove specified key and return the corresponding value. ¶
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem(last=True)¶
Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
- remove(obj)¶
Remove
obj
from the queue. Passes silently if the object is not in the queue.
- setdefault(key, default=None)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- shape(device)¶
Produces the output shape of the quantum script by inspecting its measurements and the device used for execution.
Note
The computed shape is not stored because the output shape may be dependent on the device used for execution.
- Parameters
device (pennylane.devices.Device) – the device that will be used for the script execution
- Returns
the output shape(s) of the quantum script result
- Return type
Union[tuple[int], tuple[tuple[int]]]
Examples
>>> dev = qml.device('default.qubit', wires=2) >>> qs = QuantumScript(measurements=[qml.state()]) >>> qs.shape(dev) (4,) >>> m = [qml.state(), qml.expval(qml.Z(0)), qml.probs((0,1))] >>> qs = QuantumScript(measurements=m) >>> qs.shape(dev) ((4,), (), (4,))
- to_openqasm(wires=None, rotations=True, measure_all=True, precision=None)¶
Serialize the circuit as an OpenQASM 2.0 program.
Measurements are assumed to be performed on all qubits in the computational basis. An optional
rotations
argument can be provided so that output of the OpenQASM circuit is diagonal in the eigenbasis of the quantum script’s observables. The measurement outputs can be restricted to only those specified in the script by settingmeasure_all=False
.Note
The serialized OpenQASM program assumes that gate definitions in
qelib1.inc
are available.- Parameters
wires (Wires or None) – the wires to use when serializing the circuit
rotations (bool) – in addition to serializing user-specified operations, also include the gates that diagonalize the measured wires such that they are in the eigenbasis of the circuit observables.
measure_all (bool) – whether to perform a computational basis measurement on all qubits or just those specified in the script
precision (int) – decimal digits to display for parameters
- Returns
OpenQASM serialization of the circuit
- Return type
str
- update([E, ]**F) None. Update D from dict/iterable E and F. ¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- update_info(obj, **kwargs)¶
Update
obj
’s metadata withkwargs
if it exists in the queue.
- values() an object providing a view on D's values ¶