pub struct Program {
pub calibrations: CalibrationSet,
pub frames: FrameSet,
pub memory_regions: BTreeMap<String, MemoryRegion>,
pub waveforms: BTreeMap<String, Waveform>,
/* private fields */
}
Expand description
A Quil Program instance describes a quantum program with metadata used in execution.
This contains not only instructions which are executed in turn on the quantum processor, but also the “headers” used to describe and manipulate those instructions, such as calibrations and frame definitions.
Fields§
§calibrations: CalibrationSet
§frames: FrameSet
§memory_regions: BTreeMap<String, MemoryRegion>
§waveforms: BTreeMap<String, Waveform>
Implementations§
source§impl Program
impl Program
pub fn new() -> Self
sourcepub fn body_instructions(&self) -> impl Iterator<Item = &Instruction>
pub fn body_instructions(&self) -> impl Iterator<Item = &Instruction>
Returns an iterator over immutable references to the instructions that make up the body of the program.
pub fn into_body_instructions(self) -> impl Iterator<Item = Instruction>
sourcepub fn clone_without_body_instructions(&self) -> Self
pub fn clone_without_body_instructions(&self) -> Self
Like Clone
, but does not clone the body instructions.
sourcepub fn add_instruction(&mut self, instruction: Instruction)
pub fn add_instruction(&mut self, instruction: Instruction)
Add an instruction to the end of the program.
pub fn add_instructions<I>(&mut self, instructions: I)where I: IntoIterator<Item = Instruction>,
sourcepub fn dagger(&self) -> Result<Self, ProgramError>
pub fn dagger(&self) -> Result<Self, ProgramError>
Creates a new conjugate transpose of the Program
by reversing the order of gate
instructions and applying the DAGGER modifier to each.
Errors
Errors if any of the instructions in the program are not Instruction::Gate
sourcepub fn expand_calibrations(&self) -> Result<Self, ProgramError>
pub fn expand_calibrations(&self) -> Result<Self, ProgramError>
Expand any instructions in the program which have a matching calibration, leaving the others unchanged. Recurses though each instruction while ensuring there is no cycle in the expansion graph (i.e. no calibration expands directly or indirectly into itself)
sourcepub fn from_instructions(instructions: Vec<Instruction>) -> Self
pub fn from_instructions(instructions: Vec<Instruction>) -> Self
Build a program from a list of instructions
sourcepub fn get_frames_for_instruction<'a>(
&'a self,
instruction: &'a Instruction
) -> Option<MatchedFrames<'a>>
pub fn get_frames_for_instruction<'a>( &'a self, instruction: &'a Instruction ) -> Option<MatchedFrames<'a>>
Return the frames which are either “used” or “blocked” by the given instruction.
An instruction “uses” a frame if it plays on that frame; it “blocks” a frame if the instruction prevents other instructions from playing on that frame until complete.
Return None
if the instruction does not execute in the context of a frame - such
as classical instructions.
See the Quil-T spec for more information.
sourcepub fn get_used_qubits(&self) -> &HashSet<Qubit>
pub fn get_used_qubits(&self) -> &HashSet<Qubit>
Returns a HashSet consisting of every Qubit that is used in the program.
sourcepub fn into_instructions(self) -> Vec<Instruction>
pub fn into_instructions(self) -> Vec<Instruction>
Consume the Program
to return all of the instructions which constitute it.
sourcepub fn into_simplified(&self) -> Result<Self, ProgramError>
pub fn into_simplified(&self) -> Result<Self, ProgramError>
Simplify this program into a new Program
which contains only instructions
and definitions which are executed; effectively, perform dead code removal.
Removes:
- All calibrations, following calibration expansion
- Frame definitions which are not used by any instruction such as
PULSE
orCAPTURE
- Waveform definitions which are not used by any instruction
When a valid program is simplified, it remains valid.
sourcepub fn resolve_placeholders(&mut self)
pub fn resolve_placeholders(&mut self)
Resolve [LabelPlaceholder
]s and QubitPlaceholder
s within the program using default resolvers.
See resolve_placeholders_with_custom_resolvers
,
default_target_resolver
,
and default_qubit_resolver
for more information.
sourcepub fn resolve_placeholders_with_custom_resolvers(
&mut self,
target_resolver: Box<dyn Fn(&TargetPlaceholder) -> Option<String>>,
qubit_resolver: Box<dyn Fn(&QubitPlaceholder) -> Option<u64>>
)
pub fn resolve_placeholders_with_custom_resolvers( &mut self, target_resolver: Box<dyn Fn(&TargetPlaceholder) -> Option<String>>, qubit_resolver: Box<dyn Fn(&QubitPlaceholder) -> Option<u64>> )
Resolve TargetPlaceholder
s and QubitPlaceholder
s within the program such that the resolved values
will remain unique to that placeholder within the scope of the program.
The provided target_resolver
and qubit_resolver
, will be used to resolve those values respectively.
If your placeholder returns None
for a particular placeholder, it will not be replaced but will be left as a placeholder.
If you wish to provide a resolver for either labels or qubits, but want to rely on the
default behavior for the other, considering using either
default_qubit_resolver
or default_target_resolver
.
sourcepub fn default_target_resolver(
&self
) -> Box<dyn Fn(&TargetPlaceholder) -> Option<String>>
pub fn default_target_resolver( &self ) -> Box<dyn Fn(&TargetPlaceholder) -> Option<String>>
The default target resolver will resolve each TargetPlaceholder
in the program to a unique target
by applying an auto-incrementing suffix to the base target.
sourcepub fn default_qubit_resolver(
&self
) -> Box<dyn Fn(&QubitPlaceholder) -> Option<u64>>
pub fn default_qubit_resolver( &self ) -> Box<dyn Fn(&QubitPlaceholder) -> Option<u64>>
The default qubit resolver will resolve each QubitPlaceholder
in the program to
a unique fixed qubit index by incrementing to the next available index.
sourcepub fn to_instructions(&self) -> Vec<Instruction>
pub fn to_instructions(&self) -> Vec<Instruction>
Return a copy of all of the instructions which constitute this Program
.
sourcepub fn to_unitary(&self, n_qubits: u64) -> Result<Matrix, ProgramError>
pub fn to_unitary(&self, n_qubits: u64) -> Result<Matrix, ProgramError>
Return the unitary of a program.
Errors
Returns an error if the program contains instructions other than Gate
s.
sourcepub fn get_instruction(&self, index: usize) -> Option<&Instruction>
pub fn get_instruction(&self, index: usize) -> Option<&Instruction>
Get a reference to the Instruction
at the given index, if present.
Trait Implementations§
source§impl From<Vec<Instruction, Global>> for Program
impl From<Vec<Instruction, Global>> for Program
source§fn from(instructions: Vec<Instruction>) -> Self
fn from(instructions: Vec<Instruction>) -> Self
source§impl FromStr for Program
impl FromStr for Program
§type Err = ProgramError
type Err = ProgramError
source§impl PartialEq<Program> for Program
impl PartialEq<Program> for Program
source§impl Quil for Program
impl Quil for Program
source§fn write(
&self,
writer: &mut impl Write,
fall_back_to_debug: bool
) -> Result<(), ToQuilError>
fn write( &self, writer: &mut impl Write, fall_back_to_debug: bool ) -> Result<(), ToQuilError>
fall_back_to_debug
is true
, then it must not return an error.source§fn to_quil(&self) -> Result<String, ToQuilError>
fn to_quil(&self) -> Result<String, ToQuilError>
source§fn to_quil_or_debug(&self) -> String
fn to_quil_or_debug(&self) -> String
Debug
representation of that
component.