Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ppvm-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ Gates (q = qubit index; angles / probabilities are floats)
u3 <q> <theta> <phi> <lam>
rxx ryy rzz <a> <b> <angle>
depolarize loss <q> <p> depolarize2 <a> <b> <p>
leakage <q> <p0> <p1>
pauli_error <q> <px> <py> <pz> correlated_loss <a> <b> <p0> <p1> <p2>

Line editing: ←/→ move · Home/End · Backspace/Del · ↑/↓ history";
Expand Down
17 changes: 17 additions & 0 deletions crates/ppvm-tui/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub fn gate_spec(name: &str) -> Option<GateSpec> {
"loss" => (Loss, 1, 1),
"pauli_error" => (PauliError, 1, 3),
"correlated_loss" => (CorrelatedLoss, 2, 3),
// Same shape as `r`: one qubit, two floats. Push order is q, p0, p1
// (probabilities of leaking into pinned |0⟩ / |1⟩).
"leakage" => (Leakage, 1, 2),
_ => return None,
};
Some(GateSpec {
Expand Down Expand Up @@ -208,6 +211,20 @@ mod tests {
);
}

#[test]
fn leakage_parses_qubit_and_two_probs() {
assert_eq!(
parse_command("leakage 0 0.0 1.0").unwrap(),
Command::Gate {
inst: CircuitInstruction::Leakage,
qubits: vec![0],
params: vec![0.0, 1.0],
}
);
assert!(parse_command("leakage 0 1.0").is_err());
assert!(parse_command("leakage 0").is_err());
}

#[test]
fn meta_commands() {
assert_eq!(parse_command(":q").unwrap(), Command::Quit);
Expand Down
3 changes: 3 additions & 0 deletions crates/ppvm-vihaco/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ enum BytecodeCircuit {
PauliError,
Depolarize2,
Depolarize,
Leakage,
}

#[derive(Debug, Clone, vihaco::Instruction)]
Expand Down Expand Up @@ -257,6 +258,7 @@ fn encode_instruction(inst: &PPVMInstruction) -> eyre::Result<BytecodeInstructio
vihaco_circuit_isa::CircuitInstruction::PauliError => BytecodeCircuit::PauliError,
vihaco_circuit_isa::CircuitInstruction::Depolarize2 => BytecodeCircuit::Depolarize2,
vihaco_circuit_isa::CircuitInstruction::Depolarize => BytecodeCircuit::Depolarize,
vihaco_circuit_isa::CircuitInstruction::Leakage => BytecodeCircuit::Leakage,
}),
};
Ok(encoded)
Expand Down Expand Up @@ -344,6 +346,7 @@ fn decode_instruction(inst: BytecodeInstruction) -> PPVMInstruction {
BytecodeCircuit::PauliError => vihaco_circuit_isa::CircuitInstruction::PauliError,
BytecodeCircuit::Depolarize2 => vihaco_circuit_isa::CircuitInstruction::Depolarize2,
BytecodeCircuit::Depolarize => vihaco_circuit_isa::CircuitInstruction::Depolarize,
BytecodeCircuit::Leakage => vihaco_circuit_isa::CircuitInstruction::Leakage,
}),
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/ppvm-vihaco/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ where
(CorrelatedLoss, TwoQubitAndFloatArr3(addr0, addr1, ps)) => {
self.tab.correlated_loss_channel(*addr0, *addr1, *ps)
}
(Leakage, &QubitAndTwoFloats(addr, p0, p1)) => self.tab.leakage_channel(addr, p0, p1),

/* BATCH OPERATIONS START HERE */
// Batch: dedicated batch methods
Expand Down Expand Up @@ -389,7 +390,9 @@ macro_rules! dispatch_common_paulisum {
// Not supported on either backend (Decision 11 + Gate Support
// Matrix). Loss / CorrelatedLoss handling differs by backend
// and lives in the caller's impl block, not this macro.
(Measure | Reset, _) => {
// Leakage is GeneralizedTableau-only (pinned |0⟩/|1⟩), not a
// LossyPauliSum qutrit |L⟩ channel.
(Measure | Reset | Leakage, _) => {
return Err(eyre!("{} is not supported on the {} backend", $inst, $backend));
}

Expand Down
16 changes: 16 additions & 0 deletions crates/ppvm-vihaco/src/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ impl PPVM {
let q = self.pop_u64()?;
Ok(CircuitMessage::QubitAndFloat(q, theta))
}
Leakage => {
// Push order: qubit, p0, p1. Pop reverse.
let p1 = self.pop_f64()?;
let p0 = self.pop_f64()?;
let q = self.pop_u64()?;
Ok(CircuitMessage::QubitAndTwoFloats(q, p0, p1))
}
RXX | RYY | RZZ | Depolarize2 => {
let theta = self.pop_f64()?;
let q1 = self.pop_u64()?;
Expand Down Expand Up @@ -939,6 +946,15 @@ mod tests {
machine.resolve_circuit(&CircuitInstruction::CorrelatedLoss)?,
CircuitMessage::TwoQubitAndFloatArr3(2, 5, [0.1, 0.2, 0.3])
);

// Leakage: push q=2, p0, p1 — two floats, unlike Loss.
machine.cpu.stack_push(Value::U64(2));
machine.cpu.stack_push(Value::F64(0.1));
machine.cpu.stack_push(Value::F64(0.2));
assert_eq!(
machine.resolve_circuit(&CircuitInstruction::Leakage)?,
CircuitMessage::QubitAndTwoFloats(2, 0.1, 0.2)
);
Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions crates/ppvm-vihaco/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ impl PPVMResolver {
S::PauliError => R::PauliError,
S::Depolarize2 => R::Depolarize2,
S::Depolarize => R::Depolarize,
S::Leakage => R::Leakage,
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions crates/ppvm-vihaco/tests/paulisum_leakage_error.sst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
device circuit.n_qubits 1;
device circuit.backend paulisum;
device circuit.observable Z;

// Leakage is GeneralizedTableau-only. PauliSum has no leakage_channel,
// so this program must fail at execute with a backend-rejection error.
fn @main() {
cpu::cpu.const u64, 0
cpu::cpu.const f64, 0.0
cpu::cpu.const f64, 1.0
circuit::circuit.leakage
cpu::cpu.ret 0
}
39 changes: 39 additions & 0 deletions crates/ppvm-vihaco/tests/sst_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ fn dumped_rotxy_runs_and_flips_qubit() {
assert_eq!(record[0].as_slice(), &[MeasurementOutcome::One]);
}

#[test]
fn tableau_leakage_pins_to_one_and_skips_x() {
// `tableau_leakage.sst` leaks q0 with (p0, p1) = (0, 1), pinning |1⟩,
// then applies X. A leaked qubit is frozen, so measure still returns 1.
let machine = ppvm_vihaco::run_file("tests/tableau_leakage.sst")
.unwrap_or_else(|e| panic!("run tableau_leakage.sst: {e:?}"));
let record = machine.measurement_record();
assert_eq!(record.len(), 1, "expected exactly one measurement");
assert_eq!(
record[0].as_slice(),
&[MeasurementOutcome::One],
"leaked q0 must measure the pinned 1, not LOST, and X must be a no-op"
);
}

#[test]
fn dumped_tableau_leakage_pins_to_one() {
let machine = dump_load_run("tests/tableau_leakage.sst", "ppvm_dump_tableau_leakage.ssb");
let record = machine.measurement_record();
assert_eq!(record.len(), 1);
assert_eq!(record[0].as_slice(), &[MeasurementOutcome::One]);
}

#[test]
fn run_file_via_library_helper() {
let machine =
Expand Down Expand Up @@ -347,6 +370,22 @@ fn paulisum_measure_returns_unsupported_error() {
);
}

#[test]
fn paulisum_leakage_returns_unsupported_error() {
// Leakage is tableau-only. PauliSum must reject it the same way it
// rejects Measure — not with a mismatched-argument fallback.
let mut machine = PPVM::default();
machine
.load_file("tests/paulisum_leakage_error.sst")
.unwrap_or_else(|e| panic!("load paulisum_leakage_error.sst: {e:?}"));
let err = machine.run().unwrap_err();
let msg = err.to_string();
assert!(
msg.contains("not supported on the PauliSum backend"),
"expected PauliSum-rejection error, got: {msg}"
);
}

// ─── Task 16: Tableau-side Trace, cross-backend agreement ────────────────

#[test]
Expand Down
20 changes: 20 additions & 0 deletions crates/ppvm-vihaco/tests/tableau_leakage.sst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
device circuit.n_qubits 1;

// Deterministic leakage: p0=0, p1=1 pins q0 to |1⟩ and marks it leaked.
// Stack order for `circuit.leakage`: qubit, then p0, then p1.
// A subsequent X is a no-op on a leaked qubit, so measurement still
// returns 1 (the pinned bit, not LOST).
fn @main() {
cpu::cpu.const u64, 0
cpu::cpu.const f64, 0.0
cpu::cpu.const f64, 1.0
circuit::circuit.leakage

cpu::cpu.const u64, 0
circuit::circuit.x

cpu::cpu.const u64, 0
circuit::circuit.measure

cpu::cpu.ret 0
}
5 changes: 5 additions & 0 deletions crates/vihaco-circuit-isa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ vihaco::component! {
PauliError,
Depolarize2,
Depolarize,
Leakage,
}
}

Expand Down Expand Up @@ -110,6 +111,8 @@ impl std::fmt::Display for runtime::Instruction {
PauliError => write!(f, "PauliError"),
Depolarize2 => write!(f, "Depolarize2"),
Depolarize => write!(f, "Depolarize"),

Leakage => write!(f, "Leakage"),
}
}
}
Expand Down Expand Up @@ -181,6 +184,8 @@ mod tests {
assert_eq!(parse("rxx"), RXX);
assert_eq!(parse("depolarize2"), Depolarize2);
assert_eq!(parse("depolarize"), Depolarize);
assert_eq!(parse("loss"), Loss);
assert_eq!(parse("leakage"), Leakage);
}

// ─── Parse: prefix-sensitive disambiguation ───────────────────────────
Expand Down
Loading