Skip to content

Commit

Permalink
Set type of measurement expression correctly
Browse files Browse the repository at this point in the history
That is measuring a qubit or hardware qubit results in a bit.
Measuring a qubit register results in a bit register of the same length.

Closes #51
  • Loading branch information
jlapeyre committed Jan 19, 2024
1 parent 32e84de commit bb06ae0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/oq3_semantics/src/asg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,16 @@ impl MeasureExpression {
&self.operand
}

// FIXME: type may not be correct here.
// This assumes a single qubit is measured.
pub fn to_texpr(self) -> TExpr {
TExpr::new(Expr::MeasureExpression(self), Type::Bit(IsConst::False))
let out_type = match self.operand.get_type() {
Type::Qubit | Type::HardwareQubit => Type::Bit(IsConst::False),
Type::QubitArray(dims) => Type::BitArray(dims.clone(), IsConst::False),
_ => panic!(
"Measure expression operand has type {:?}",
self.operand.get_type()
),
};
TExpr::new(Expr::MeasureExpression(self), out_type)
}
}

Expand Down

0 comments on commit bb06ae0

Please sign in to comment.