diff --git a/src/Circuit/BatchBuilder.php b/src/Circuit/BatchBuilder.php index 97bf8e3..87ef558 100644 --- a/src/Circuit/BatchBuilder.php +++ b/src/Circuit/BatchBuilder.php @@ -52,4 +52,12 @@ public function run(): BatchResult return $this->device->executeBatch($this->circuits); } + + /** + * Get the name of the driver this batch is pinned to. + */ + public function driverName(): string + { + return $this->driverName; + } } diff --git a/src/Jobs/PollQuantumTask.php b/src/Jobs/PollQuantumTask.php index 9a4c0b2..c994044 100644 --- a/src/Jobs/PollQuantumTask.php +++ b/src/Jobs/PollQuantumTask.php @@ -71,8 +71,8 @@ public function tries(): int */ public function handle(QuantumManager $manager, Dispatcher $events): void { - $driverName = $this->driver ?? config('aether.default', 'local'); - $device = $manager->driver($this->driver); + $driverName = $manager->driverAlias($this->driver); + $device = $manager->driver($driverName); if (! $device instanceof AsynchronousDevice || ! $device instanceof QuantumDevice) { throw QuantumExecutionException::asynchronousUnsupported($driverName); diff --git a/src/Jobs/SubmitQuantumCircuit.php b/src/Jobs/SubmitQuantumCircuit.php index 539ded3..9ed8080 100644 --- a/src/Jobs/SubmitQuantumCircuit.php +++ b/src/Jobs/SubmitQuantumCircuit.php @@ -52,8 +52,8 @@ public function __construct( */ public function handle(QuantumManager $manager): void { - $driverName = $this->driver ?? config('aether.default', 'local'); - $device = $manager->driver($this->driver); + $driverName = $manager->driverAlias($this->driver); + $device = $manager->driver($driverName); if (! $device instanceof AsynchronousDevice || ! $device instanceof QuantumDevice) { throw QuantumExecutionException::asynchronousUnsupported($driverName); diff --git a/src/QuantumManager.php b/src/QuantumManager.php index b288eaa..10b7194 100644 --- a/src/QuantumManager.php +++ b/src/QuantumManager.php @@ -50,9 +50,12 @@ public function driver($driver = null) /** * The string alias for a driver argument, which Manager also accepts as an - * enum; the fake reports this on the events it dispatches. + * enum. The one place in the manager that knows how an absent name + * resolves to the default: the fake reports it on the events it + * dispatches, and circuit() and batch() pin it onto the builders they + * create. The queue jobs ask getDefaultDriver() for the same answer. */ - private function driverAlias(string|UnitEnum|null $driver): string + public function driverAlias(string|UnitEnum|null $driver): string { return match (true) { $driver === null => $this->getDefaultDriver(), @@ -71,10 +74,9 @@ private function driverAlias(string|UnitEnum|null $driver): string */ public function circuit(?string $driver = null): CircuitBuilder { - return new CircuitBuilder( - $this->driver($driver), - $driver ?? $this->getDefaultDriver(), - ); + $name = $this->driverAlias($driver); + + return new CircuitBuilder($this->driver($name), $name); } /** @@ -84,11 +86,9 @@ public function circuit(?string $driver = null): CircuitBuilder */ public function batch(array $circuits, ?string $driver = null): BatchBuilder { - return new BatchBuilder( - $this->driver($driver), - array_values($circuits), - $driver ?? $this->getDefaultDriver(), - ); + $name = $this->driverAlias($driver); + + return new BatchBuilder($this->driver($name), array_values($circuits), $name); } /** diff --git a/tests/Feature/QuantumManagerTest.php b/tests/Feature/QuantumManagerTest.php index 0f99548..4642272 100644 --- a/tests/Feature/QuantumManagerTest.php +++ b/tests/Feature/QuantumManagerTest.php @@ -113,9 +113,18 @@ }); it('pins the resolved default driver name when no driver is requested', function () { - config()->set('aether.default', 'local'); + config()->set('aether.default', 'aws'); $manager = app(QuantumManager::class); - expect($manager->circuit()->driverName())->toBe('local'); + expect($manager->circuit()->driverName())->toBe('aws'); +}); + +it('pins the resolved default driver name on batches when no driver is requested', function () { + config()->set('aether.default', 'aws'); + + $manager = app(QuantumManager::class); + $batch = $manager->batch([$manager->circuit()->qubits(1)->h(0)->measure()]); + + expect($batch->driverName())->toBe('aws'); });