‘qtensor’ Dialect¶
The QTensor dialect for one-dimensional tensors of qubits with linear typing.
The QTensor dialect is an adjusted variant of the standard tensor dialect of MLIR that supports linear typing for one-dimensional tensors of qubits. In order to support linear typing, the extract operations of this dialect are modified so that they also return the updated tensor. In addition, alloc/dealloc operations are added to the dialect to support the bulk allocation and deallocation of qubit tensors with linear types.
Operations¶
qtensor.alloc (qtensor::AllocOp)¶
Tensor alloc operation
Syntax:
operation ::= `qtensor.alloc` `(`$size`)` attr-dict `:` type($result)
Allocates a one-dimensional qubit tensor with the given size and returns the allocated tensor. The qubits are initialized to the |0> state. If the size is a constant the resulting tensor has a static size, otherwise the tensor has a dynamic size.
Example:
%qtensor = qtensor.alloc(%c3) : tensor<3x!qco.qubit>
Interfaces: MemoryEffectOpInterface (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{MemoryEffects::Allocate on ::mlir::SideEffects::DefaultResource}
Operands:¶
Operand |
Description |
|---|---|
|
index |
Results:¶
Result |
Description |
|---|---|
|
1D tensor of QCO qubit value type values |
qtensor.dealloc (qtensor::DeallocOp)¶
Deallocate a tensor
Syntax:
operation ::= `qtensor.dealloc` $tensor attr-dict `:` type($tensor)
This operation deallocates the tensor and the values it holds, releasing its resources. Qubits that were extracted but not inserted again need to be deallocated separately.
Example:
qtensor.dealloc %tensor : tensor<3x!qco.qubit>
Interfaces: MemoryEffectOpInterface (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{MemoryEffects::Free on ::mlir::SideEffects::DefaultResource}
Operands:¶
Operand |
Description |
|---|---|
|
1D tensor of QCO qubit value type values |
qtensor.extract (qtensor::ExtractOp)¶
Extract element from tensor
Syntax:
operation ::= `qtensor.extract` $tensor `[` $index `]` attr-dict `:` type($tensor)
The qtensor.extract operation is the modified version of the standard tensor.extract
operation of the tensor dialect. It reads a ranked tensor and returns one qubit from the input tensor
at the given index. In addition, it also returns the updated input tensor as a result.
Example:
%outTensor, %q0 = qtensor.extract %tensor[%c0] : tensor<4x!qco.qubit>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:¶
Operand |
Description |
|---|---|
|
1D tensor of QCO qubit value type values |
|
index |
Results:¶
Result |
Description |
|---|---|
|
1D tensor of QCO qubit value type values |
|
QCO qubit value type |
qtensor.from_elements (qtensor::FromElementsOp)¶
Create a tensor from a range of values
Syntax:
operation ::= `qtensor.from_elements` $elements attr-dict `:` type($result)
The qtensor.from_elements operation is a wrapper operation of the tensor.from_elements operation.
This operation creates a one-dimensional qubit tensor using the operands as its input.
This also causes the input qubits to be consumed.
Example:
%tensor = qtensor.from_elements %q0, %q1, %q2 : tensor<3x!qco.qubit>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:¶
Operand |
Description |
|---|---|
|
variadic of QCO qubit value type |
Results:¶
Result |
Description |
|---|---|
|
Tensor must be statically shaped and elements must be of qubit type |
qtensor.insert (qtensor::InsertOp)¶
Insert element into tensor
Syntax:
operation ::= `qtensor.insert` $scalar `into` $dest `[` $index `]` attr-dict `:` type($dest)
The qtensor.insert operation is a wrapper operation for the tensor.insert operation of the tensor dialect.
This operation inserts a qubit scalar into a ranked tensor as specified by the operation’s index. The insertion
consumes the input qubit.
Example:
%newTensor = qtensor.insert %q0 into %tensor[%c0] : tensor<3x!qco.qubit>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:¶
Operand |
Description |
|---|---|
|
QCO qubit value type |
|
1D tensor of QCO qubit value type values |
|
index |
Results:¶
Result |
Description |
|---|---|
|
1D tensor of QCO qubit value type values |