pub struct BasicBlock<'p> { /* private fields */ }Implementations§
Source§impl<'p> BasicBlock<'p>
impl<'p> BasicBlock<'p>
pub fn label(&self) -> Option<&'p Target>
pub fn instruction_index_offset(&self) -> usize
pub fn instructions(&self) -> &[&'p Instruction]
pub fn terminator(&self) -> &BasicBlockTerminator<'p>
Sourcepub fn as_schedule_seconds(
&self,
program: &Program,
) -> Result<Schedule<Seconds>, BasicBlockScheduleError>
pub fn as_schedule_seconds( &self, program: &Program, ) -> Result<Schedule<Seconds>, BasicBlockScheduleError>
Compute the flattened schedule for this BasicBlock in terms of seconds,
using a default built-in calculation for the duration of scheduled instructions.
See [BasicBlockOwned::as_schedule].
§Arguments
program- The program containing this basic block. This is used to retrieve frame and calibration information. Generally, this should be the program from which the block was extracted.
§How it Works
- Expanding each instruction within the block using the program’s calibration definitions
- Resolving the
ScheduleSecondsof the expanded instructions - Mapping calibrated instructions back to the original instructions within this block, such that the block’s instruction is represented as a timespan encompassing all of its expanded instructions
§Notes
If the basic block contains gates,
the program must contain corresponding DEFCALs for those gates.
Gates do not inherently have durations,
but rather inherit them from the PULSE, CAPTURE, DELAY,
and other instructions within their calibrations.
Without a calibration, a gate’s duration cannot be computed.
§Python Example
For Python users, the following example demonstrates construction of such a schedule for a simple program without explicit control flow (and thus with only one basic block):
from quil.program import Program
program = Program.parse("CZ 0 1; CZ 0 2")
print(program.to_quil())
control_flow_graph = program.control_flow_graph()
assert control_flow_graph.has_dynamic_control_flow() == False
basic_blocks = control_flow_graph.basic_blocks()
assert len(basic_blocks) == 1
schedule = blocks[0].as_schedule_seconds(program)
print(f"Duration = {schedule.duration()}")
print(schedule.items())Sourcepub fn as_schedule<F, Time>(
&self,
program: &'p Program,
get_duration: F,
) -> Result<Schedule<Time>, BasicBlockScheduleError>where
F: Fn(&Program, &Instruction) -> Option<Time>,
Time: Clone + Debug + PartialOrd + Add<Time, Output = Time> + Sub<Time, Output = Time> + Zero,
pub fn as_schedule<F, Time>(
&self,
program: &'p Program,
get_duration: F,
) -> Result<Schedule<Time>, BasicBlockScheduleError>where
F: Fn(&Program, &Instruction) -> Option<Time>,
Time: Clone + Debug + PartialOrd + Add<Time, Output = Time> + Sub<Time, Output = Time> + Zero,
Compute the schedule for this BasicBlock in terms of a generic unit of time,
using a provided function to calculate the duration of scheduled instructions in that unit.
§Arguments
program- The program containing this basic block. This is used to retrieve frame and calibration information.get_duration- A function that takes a program and an instruction and returns the duration of the instruction in the desired time unit, orNoneif the instruction’s duration is not known.
Note: when an instruction is expanded, the “time” of that original instruction includes the times of all of the resulting instructions. This may cause gate times to be longer than a user might expect.
To understand why, consider a program like this:
# One-qubit frame
DEFFRAME 0 "a":
ATTRIBUTE: 1
# Two-qubit frame
DEFFRAME 0 1 "b":
ATTRIBUTE: 1
DEFCAL A 0:
PULSE 0 "a" flat(duration: 1.0)
DEFCAL B 0 1:
FENCE 1
PULSE 0 1 "b" flat(duration: 1.0)
A 0
B 0 1B 0 will be scheduled from time 0 to time 2, because its inner FENCE is scheduled for time 0.
This may be unexpected if the user expects to see only the timing of the inner PULSE.
Trait Implementations§
Source§impl<'p> Clone for BasicBlock<'p>
impl<'p> Clone for BasicBlock<'p>
Source§fn clone(&self) -> BasicBlock<'p>
fn clone(&self) -> BasicBlock<'p>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'p> Debug for BasicBlock<'p>
impl<'p> Debug for BasicBlock<'p>
Source§impl<'p> Default for BasicBlock<'p>
impl<'p> Default for BasicBlock<'p>
Source§fn default() -> BasicBlock<'p>
fn default() -> BasicBlock<'p>
Source§impl<'b> From<&'b BasicBlockOwned> for BasicBlock<'b>
impl<'b> From<&'b BasicBlockOwned> for BasicBlock<'b>
Source§fn from(value: &'b BasicBlockOwned) -> Self
fn from(value: &'b BasicBlockOwned) -> Self
Source§impl From<BasicBlock<'_>> for BasicBlockOwned
impl From<BasicBlock<'_>> for BasicBlockOwned
Source§fn from(value: BasicBlock<'_>) -> Self
fn from(value: BasicBlock<'_>) -> Self
Source§impl<'a> TryFrom<&BasicBlock<'a>> for QubitGraph<'a>
impl<'a> TryFrom<&BasicBlock<'a>> for QubitGraph<'a>
Source§type Error = QubitGraphError
type Error = QubitGraphError
Auto Trait Implementations§
impl<'p> Freeze for BasicBlock<'p>
impl<'p> RefUnwindSafe for BasicBlock<'p>
impl<'p> Send for BasicBlock<'p>
impl<'p> Sync for BasicBlock<'p>
impl<'p> Unpin for BasicBlock<'p>
impl<'p> UnwindSafe for BasicBlock<'p>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.