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
8 changes: 8 additions & 0 deletions src/Circuit/BatchBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/Jobs/PollQuantumTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Jobs/SubmitQuantumCircuit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions src/QuantumManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions tests/Feature/QuantumManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});